Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the conda package manager #296461

Merged
merged 7 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions pkgs/by-name/li/libmamba/package.nix
EricTheMagician marked this conversation as resolved.
Show resolved Hide resolved
SomeoneSerge marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
fetchFromGitHub,
lib,
stdenv,
cmake,
fmt,
spdlog,
tl-expected,
nlohmann_json,
yaml-cpp,
simdjson,
reproc,
libsolv,
curl,
libarchive,
zstd,
bzip2,
python3Packages,
}:
stdenv.mkDerivation rec {
pname = "libmamba";
version = "1.5.7";
src = fetchFromGitHub {
owner = "mamba-org";
repo = "mamba";
rev = "${pname}-${version}";
hash = "sha256-HfmvLi9IBWlaGAn2Ej4Bnm4b3l19jEXwNl5IUkdVxi0=";
};
nativeBuildInputs = [
cmake
python3Packages.python
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
python3Packages.python
python3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically asked the author to use python3Packages.python.

The motivation is that we'd be forced to use python3Packages instead of python3 if we later had to add some python packages as dependencies in order to keep splicing working and avoid bringing diverging versions of the interpreter into the closure. So, might as well always ask for python3Packages for consistency

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we merge this as is. If you want this changed to python3 I suggest we open a separate PR and discuss it there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we you are worried about using different python package sets, then use python3.pkgs instead of python3Packages.

Copy link
Contributor

@SomeoneSerge SomeoneSerge Apr 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, python3.pkgs breaks splicing. I think what we need instead is #296461 (comment)

];
buildInputs = [
fmt
spdlog
tl-expected
nlohmann_json
yaml-cpp
simdjson
reproc
libsolv
curl
libarchive
zstd
bzip2
];

cmakeFlags = [
(lib.cmakeBool "BUILD_LIBMAMBA" true)
(lib.cmakeBool "BUILD_SHARED" true)
];

meta = {
description = "The library for the fast Cross-Platform Package Manager";
homepage = "https://github.com/mamba-org/mamba";
license = lib.licenses.bsd3;
platforms = lib.platforms.all;
maintainers = [ lib.maintainers.ericthemagician ];
SomeoneSerge marked this conversation as resolved.
Show resolved Hide resolved
};
}
4 changes: 3 additions & 1 deletion pkgs/development/libraries/libsolv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
, withRpm ? !stdenv.isDarwin
, rpm
, db
, withConda ? true
}:

stdenv.mkDerivation rec {
Expand All @@ -23,11 +24,12 @@ stdenv.mkDerivation rec {
owner = "openSUSE";
repo = "libsolv";
rev = version;
sha256 = "sha256-cL7SDwCzXM2qJQfiu/3nfAiFbcFNn1YXD23Sl3n9nzY=";
hash = "sha256-cL7SDwCzXM2qJQfiu/3nfAiFbcFNn1YXD23Sl3n9nzY=";
};

cmakeFlags = [
"-DENABLE_COMPLEX_DEPS=true"
(lib.cmakeBool "ENABLE_CONDA" withConda)
"-DENABLE_LZMA_COMPRESSION=true"
"-DENABLE_BZIP2_COMPRESSION=true"
"-DENABLE_ZSTD_COMPRESSION=true"
Expand Down
47 changes: 47 additions & 0 deletions pkgs/development/python-modules/conda-libmamba-solver/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
lib,
buildPythonPackage,
pythonRelaxDepsHook,
fetchFromGitHub,
libmambapy,
hatchling,
hatch-vcs,
boltons,
}:
buildPythonPackage rec {
pname = "conda-libmamba-solver";
version = "24.1.0";
pyproject = true;

src = fetchFromGitHub {
inherit pname version;
owner = "conda";
repo = "conda-libmamba-solver";
rev = version;
hash = "sha256-vsUYrDVNMKHd3mlaAFYCP4uPQ9HxeKsose5O8InaMcE=";
};

nativeBuildInputs = [ pythonRelaxDepsHook ];

build-system = [
hatchling
SomeoneSerge marked this conversation as resolved.
Show resolved Hide resolved
hatch-vcs
];

dependencies = [
boltons
libmambapy
];

# this package depends on conda for the import to run succesfully, but conda depends on this package to execute.
# pythonImportsCheck = [ "conda_libmamba_solver" ];

pythonRemoveDeps = [ "conda" ];

meta = {
description = "The libmamba based solver for conda.";
homepage = "https://github.com/conda/conda-libmamba-solver";
license = lib.licenses.bsd3;
maintainers = [ lib.maintainers.ericthemagician ];
};
}
30 changes: 30 additions & 0 deletions pkgs/development/python-modules/conda-package-handling/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
lib,
buildPythonPackage,
fetchFromGitHub,
setuptools,
conda-package-streaming,
}:
buildPythonPackage rec {
pname = "conda-package-handling";
version = "2.2.0";
src = fetchFromGitHub {
owner = "conda";
repo = "conda-package-handling";
rev = version;
hash = "sha256-WeGfmT6lLwcwhheLBPMFcVMudY+zPsvTuXuOsiEAorQ=";
};

pyproject = true;
build-system = [ setuptools ];
dependencies = [ conda-package-streaming ];

pythonImportsCheck = [ "conda_package_handling" ];

meta = {
description = "Create and extract conda packages of various formats";
homepage = "https://github.com/conda/conda-package-handling";
license = lib.licenses.bsd3;
maintainers = [ lib.maintainers.ericthemagician ];
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
lib,
buildPythonPackage,
fetchFromGitHub,
flit-core,
requests,
zstandard,
}:
buildPythonPackage rec {
pname = "conda-package-streaming";
version = "0.9.0";
pyproject = true;

src = fetchFromGitHub {
owner = "conda";
repo = "conda-package-streaming";
rev = "v${version}";
hash = "sha256-UTql2M+9eFDuHOwLYYKJ751wEcOfLJYzfU6+WF8Je2g=";
};

build-system = [ flit-core ];
dependencies = [
requests
zstandard
];

pythonImportsCheck = [ "conda_package_streaming" ];

meta = {
description = "An efficient library to read from new and old format .conda and .tar.bz2 conda packages.";
homepage = "https://github.com/conda/conda-package-streaming";
license = lib.licenses.bsd3;
maintainers = [ lib.maintainers.ericthemagician ];
};
}
51 changes: 51 additions & 0 deletions pkgs/development/python-modules/conda/0001-conda_exe.patch
SomeoneSerge marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--- a/conda/base/context.py
+++ b/conda/base/context.py
@@ -754,7 +754,7 @@

@property
def conda_prefix(self):
- return abspath(sys.prefix)
+ return expand("~/.conda")

@property
@deprecated(
@@ -787,28 +787,17 @@
The vars can refer to each other if necessary since the dict is ordered.
None means unset it.
"""
- if context.dev:
- return {
- "CONDA_EXE": sys.executable,
- # do not confuse with os.path.join, we are joining paths with ; or : delimiters
- "PYTHONPATH": os.pathsep.join(
- (CONDA_SOURCE_ROOT, os.environ.get("PYTHONPATH", ""))
- ),
- "_CE_M": "-m",
- "_CE_CONDA": "conda",
- "CONDA_PYTHON_EXE": sys.executable,
- }
- else:
- bin_dir = "Scripts" if on_win else "bin"
- exe = "conda.exe" if on_win else "conda"
- # I was going to use None to indicate a variable to unset, but that gets tricky with
- # error-on-undefined.
- return {
- "CONDA_EXE": os.path.join(sys.prefix, bin_dir, exe),
- "_CE_M": "",
- "_CE_CONDA": "",
- "CONDA_PYTHON_EXE": sys.executable,
- }
+ import sys
+ return {
+ "CONDA_EXE": sys.executable,
+ # do not confuse with os.path.join, we are joining paths with ; or : delimiters
+ "PYTHONPATH": os.pathsep.join(
+ [CONDA_SOURCE_ROOT, os.environ.get("PYTHONPATH", "")] + [path for path in sys.path if "site-packages" in path]
+ ),
+ "_CE_M": "-m",
+ "_CE_CONDA": "conda",
+ "CONDA_PYTHON_EXE": sys.executable,
Comment on lines +16 to +47
Copy link
Contributor

@SomeoneSerge SomeoneSerge Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while the basic functionality does work, I think the patch for conda I added makes it really fragile. Setting the environment variable PYTHONPATH breaks the conda executable, which brings it full circle to this comment:

Could you walk us through the patch? When is context.dev true? Is the difference that upstream sets a clean PYTHONPATH that only refers to the conda environment and your patch propagates the dependencies of the conda script itself (sys.path)? Why was that required?

+ }

@memoizedproperty
def channel_alias(self):
91 changes: 68 additions & 23 deletions pkgs/development/python-modules/conda/default.nix
Original file line number Diff line number Diff line change
@@ -1,38 +1,83 @@
{ lib
, buildPythonPackage
, pythonAtLeast
, fetchPypi
, pycosat
, requests
, ruamel-yaml
, isPy3k
, enum34
{
lib,
buildPythonPackage,
pythonRelaxDepsHook,
hostPlatform,
fetchFromGitHub,
# build dependencies
hatchling,
hatch-vcs,
# runtime dependencies
archspec,
conda-libmamba-solver,
conda-package-handling,
distro,
jsonpatch,
packaging,
platformdirs,
pluggy,
pycosat,
requests,
ruamel-yaml,
tqdm,
truststore,
# runtime options
defaultEnvPath ? "~/.conda/envs", # default path to store conda environments
defaultPkgPath ? "~/.conda/pkgs", # default path to store download conda packages
}:

# Note: this installs conda as a library. The application cannot be used.
# This is likely therefore NOT what you're looking for.

buildPythonPackage rec {
pname = "conda";
version = "4.3.16";
format = "setuptools";
version = "24.1.2";
pyproject = true;

# this is a very outdated version of conda that isn't compatible with python 3.10+
disabled = pythonAtLeast "3.10";

src = fetchPypi {
src = fetchFromGitHub {
inherit pname version;
sha256 = "a91ef821343dea3ba9670f3d10b36c1ace4f4c36d70c175d8fc8886e94285953";
owner = "conda";
repo = "conda";
rev = version;
hash = "sha256-L/Y7Bb3R5YqXbjTN4CRPFnkgymVLrxuFmjVzpvt28dE=";
};

propagatedBuildInputs = [ pycosat requests ruamel-yaml ] ++ lib.optional (!isPy3k) enum34;
nativeBuildInputs = [ pythonRelaxDepsHook ];

build-system = [
hatchling
hatch-vcs
];

dependencies = [
archspec
conda-libmamba-solver
conda-package-handling
distro
jsonpatch
packaging
platformdirs
pluggy
pycosat
requests
ruamel-yaml
tqdm
truststore
];

patches = [ ./0001-conda_exe.patch ];

makeWrapperArgs = [
"--set CONDA_EXE ${placeholder "out"}/bin/conda"
''--set-default CONDA_ENVS_PATH "${defaultEnvPath}"''
''--set-default CONDA_PKGS_DIRS "${defaultPkgPath}"''
];

pythonImportsCheck = [ "conda" ];

# No tests
doCheck = false;
# menuinst is currently not packaged
pythonRemoveDeps = lib.optionals (!hostPlatform.isWindows) [ "menuinst" ];

meta = {
description = "OS-agnostic, system-level binary package manager";
homepage = "https://github.com/conda/conda";
license = lib.licenses.bsd3;
maintainers = [ lib.maintainers.ericthemagician ];
};
}
Loading