nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 149 lines 3.9 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchurl, 5 runCommand, 6 makeWrapper, 7 buildFHSEnv, 8 libselinux, 9 libarchive, 10 libGL, 11 libxrender, 12 libxi, 13 libxau, 14 libx11, 15 libsm, 16 libice, 17 zlib, 18 # Conda installs its packages and environments under this directory 19 installationPath ? "~/.conda", 20 # Conda manages most pkgs itself, but expects a few to be on the system. 21 condaDeps ? [ 22 stdenv.cc 23 libsm 24 libice 25 libx11 26 libxau 27 libxi 28 libxrender 29 libselinux 30 libGL 31 zlib 32 ], 33 # Any extra nixpkgs you'd like available in the FHS env for Conda to use 34 extraPkgs ? [ ], 35 runScript ? "bash -l", 36}: 37 38# How to use this package? 39# 40# First-time setup: this nixpkg downloads the conda installer and provides a FHS 41# env in which it can run. On first use, the user will need to install conda to 42# the installPath using the installer: 43# $ nix-env -iA conda 44# $ conda-shell 45# $ install-conda 46# 47# Under normal usage, simply call `conda-shell` to activate the FHS env, 48# and then use conda commands as normal: 49# $ conda-shell 50# $ conda install spyder 51let 52 version = "25.11.1-1"; 53 54 src = 55 let 56 selectSystem = 57 attrs: 58 attrs.${stdenv.hostPlatform.system} 59 or (throw "conda: ${stdenv.hostPlatform.system} is not supported"); 60 arch = selectSystem { 61 x86_64-linux = "x86_64"; 62 aarch64-linux = "aarch64"; 63 }; 64 in 65 fetchurl { 66 url = "https://repo.anaconda.com/miniconda/Miniconda3-py313_${version}-Linux-${arch}.sh"; 67 hash = selectSystem { 68 x86_64-linux = "sha256-4LEOBQ6JKOLrmq0sUi7jtdMdMASLipmXZjqKRg1TjO8="; 69 aarch64-linux = "sha256-nznMjEbKN6/tXlY8wjSzrdNP6i8RGeB23K56N3ymuO4="; 70 }; 71 }; 72 73 conda = 74 runCommand "install-conda" 75 { 76 nativeBuildInputs = [ makeWrapper ]; 77 } 78 # on line 10, we have 'unset LD_LIBRARY_PATH' 79 # we have to comment it out however in a way that the number of bytes in the 80 # file does not change. So we replace the 'u' in the line with a '#' 81 # The reason is that the binary payload is encoded as number 82 # of bytes from the top of the installer script 83 # and unsetting the library path prevents the zlib library from being discovered 84 '' 85 mkdir --parents $out/bin 86 87 sed 's/unset LD_LIBRARY_PATH/#nset LD_LIBRARY_PATH/' ${src} > $out/bin/miniconda-installer.sh 88 chmod +x $out/bin/miniconda-installer.sh 89 90 makeWrapper $out/bin/miniconda-installer.sh $out/bin/install-conda \ 91 --add-flags "-p ${installationPath}" \ 92 --add-flags "-b" \ 93 --prefix "LD_LIBRARY_PATH" : "${ 94 lib.makeLibraryPath [ 95 zlib # libz.so.1 96 ] 97 }" 98 ''; 99in 100 101buildFHSEnv { 102 pname = "conda-shell"; 103 inherit version runScript; 104 105 targetPkgs = 106 pkgs: 107 (builtins.concatLists [ 108 [ conda ] 109 condaDeps 110 extraPkgs 111 ]); 112 113 profile = 114 let 115 condaSh = "${installationPath}/etc/profile.d/conda.sh"; 116 in 117 '' 118 # Add conda to PATH 119 export PATH=${installationPath}/bin:$PATH 120 # Paths for gcc if compiling some C sources with pip 121 export NIX_CFLAGS_COMPILE="-I${installationPath}/include" 122 export NIX_CFLAGS_LINK="-L${installationPath}/lib" 123 # Some other required environment variables 124 export FONTCONFIG_FILE=/etc/fonts/fonts.conf 125 export QTCOMPOSE=${libx11}/share/X11/locale 126 export LIBARCHIVE=${lib.getLib libarchive}/lib/libarchive.so 127 # Allows `conda activate` to work properly 128 if [ ! -f ${condaSh} ]; then 129 install-conda 130 fi 131 source ${condaSh} 132 ''; 133 134 passthru = { 135 inherit src; 136 }; 137 138 meta = { 139 description = "Package manager for Python"; 140 mainProgram = "conda-shell"; 141 homepage = "https://conda.io"; 142 platforms = [ 143 "aarch64-linux" 144 "x86_64-linux" 145 ]; 146 license = with lib.licenses; [ bsd3 ]; 147 maintainers = with lib.maintainers; [ jluttine ]; 148 }; 149}