···1010high amount of packages. The attribute `python3` refers to the default1111interpreter, which is currently CPython 3.10. The attribute `python` refers to1212CPython 2.7 for backwards-compatibility. It is also possible to refer to1313-specific versions, e.g. `python39` refers to CPython 3.9, and `pypy` refers to1313+specific versions, e.g. `python311` refers to CPython 3.11, and `pypy` refers to1414the default PyPy interpreter.15151616Python is used a lot, and in different ways. This affects also how it is···2626The interpreters have several common attributes. One of these attributes is2727`pkgs`, which is a package set of Python libraries for this specific2828interpreter. E.g., the `toolz` package corresponding to the default interpreter2929-is `python.pkgs.toolz`, and the CPython 3.9 version is `python39.pkgs.toolz`.2929+is `python.pkgs.toolz`, and the CPython 3.11 version is `python311.pkgs.toolz`.3030The main package set contains aliases to these package sets, e.g.3131-`pythonPackages` refers to `python.pkgs` and `python39Packages` to3232-`python39.pkgs`.3131+`pythonPackages` refers to `python.pkgs` and `python311Packages` to3232+`python311.pkgs`.33333434#### Installing Python and packages {#installing-python-and-packages}3535···5454executables are wrapped to be able to find each other and all of the modules.55555656In the following examples we will start by creating a simple, ad-hoc environment5757-with a nix-shell that has `numpy` and `toolz` in Python 3.9; then we will create5757+with a nix-shell that has `numpy` and `toolz` in Python 3.11; then we will create5858a re-usable environment in a single-file Python script; then we will create a5959full Python environment for development with this same environment.6060···7070their runtime dependencies), with no other Python packages in the Python7171interpreter's scope.72727373-To create a Python 3.9 session with `numpy` and `toolz` available, run:7373+To create a Python 3.11 session with `numpy` and `toolz` available, run:74747575```sh7676-$ nix-shell -p 'python39.withPackages(ps: with ps; [ numpy toolz ])'7676+$ nix-shell -p 'python311.withPackages(ps: with ps; [ numpy toolz ])'7777```78787979By default `nix-shell` will start a `bash` session with this interpreter in our···81818282```Python console8383[nix-shell:~/src/nixpkgs]$ python38484-Python 3.9.12 (main, Mar 23 2022, 21:36:19)8585-[GCC 11.3.0] on linux8484+Python 3.11.3 (main, Apr 4 2023, 22:36:41) [GCC 12.2.0] on linux8685Type "help", "copyright", "credits" or "license" for more information.8786>>> import numpy; import toolz8887```···101102directly like so:102103103104```sh104104-$ nix-shell -p "python39.withPackages (ps: with ps; [ numpy toolz requests ])" --run python3105105+$ nix-shell -p "python311.withPackages (ps: with ps; [ numpy toolz requests ])" --run python3105106this derivation will be built:106106- /nix/store/mpn7k6bkjl41fm51342rafaqfsl10qs4-python3-3.9.12-env.drv107107-this path will be fetched (0.09 MiB download, 0.41 MiB unpacked):108108- /nix/store/5gaiacnzi096b6prc6aa1pwrhncmhc8b-python3.9-toolz-0.11.2109109-copying path '/nix/store/5gaiacnzi096b6prc6aa1pwrhncmhc8b-python3.9-toolz-0.11.2' from 'https://cache.nixos.org'...110110-building '/nix/store/mpn7k6bkjl41fm51342rafaqfsl10qs4-python3-3.9.12-env.drv'...111111-created 279 symlinks in user environment112112-Python 3.9.12 (main, Mar 23 2022, 21:36:19)113113-[GCC 11.3.0] on linux107107+ /nix/store/r19yf5qgfiakqlhkgjahbg3zg79549n4-python3-3.11.2-env.drv108108+building '/nix/store/r19yf5qgfiakqlhkgjahbg3zg79549n4-python3-3.11.2-env.drv'...109109+created 273 symlinks in user environment110110+Python 3.11.2 (main, Feb 7 2023, 13:52:42) [GCC 12.2.0] on linux114111Type "help", "copyright", "credits" or "license" for more information.115112>>> import requests116113>>>···145150in the previous section, we could startup a shell and just run it like so:146151147152```ShellSession148148-$ nix-shell -p 'python39.withPackages(ps: with ps; [ numpy ])' --run 'python3 foo.py'153153+$ nix-shell -p 'python311.withPackages (ps: with ps; [ numpy ])' --run 'python3 foo.py'149154The dot product of [1 2] and [3 4] is: 11150155```151156···185190186191```python187192#!/usr/bin/env nix-shell188188-#!nix-shell -i python3 -p "python3.withPackages(ps: [ ps.numpy ])"189189-#!nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/d373d80b1207d52621961b16aa4a3438e4f98167.tar.gz193193+#!nix-shell -i python3 -p "python3.withPackages (ps: [ ps.numpy ])"194194+#!nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/e51209796c4262bfb8908e3d6d72302fe4e96f5f.tar.gz190195import numpy as np191196a = np.array([1,2])192197b = np.array([3,4])193198print(f"The dot product of {a} and {b} is: {np.dot(a, b)}")194199```195200196196-This will execute with the exact same versions of Python 3.8, numpy, and system201201+This will execute with the exact same versions of Python 3.10, numpy, and system197202dependencies a year from now as it does today, because it will always use198198-exactly git commit `d373d80b1207d52621961b16aa4a3438e4f98167` of Nixpkgs for all203203+exactly git commit `e51209796c4262bfb8908e3d6d72302fe4e96f5f` of Nixpkgs for all199204of the package versions.200205201206This is also a great way to ensure the script executes identically on different···208213development we're usually working in an entire package repository.209214210215As explained in the Nix manual, `nix-shell` can also load an expression from a211211-`.nix` file. Say we want to have Python 3.9, `numpy` and `toolz`, like before,216216+`.nix` file. Say we want to have Python 3.11, `numpy` and `toolz`, like before,212217in an environment. We can add a `shell.nix` file describing our dependencies:213218214219```nix215220with import <nixpkgs> {};216216-(python39.withPackages (ps: [ps.numpy ps.toolz])).env221221+(python311.withPackages (ps: with ps; [222222+ numpy223223+ toolz224224+])).env217225```218226219227And then at the command line, just typing `nix-shell` produces the same···230232 imports the `<nixpkgs>` function, `{}` calls it and the `with` statement231233 brings all attributes of `nixpkgs` in the local scope. These attributes form232234 the main package set.233233-2. Then we create a Python 3.9 environment with the `withPackages` function, as before.235235+2. Then we create a Python 3.11 environment with the `withPackages` function, as before.2342363. The `withPackages` function expects us to provide a function as an argument235237 that takes the set of all Python packages and returns a list of packages to236238 include in the environment. Here, we select the packages `numpy` and `toolz`···241243```nix242244with import <nixpkgs> {};243245let244244- pythonEnv = python39.withPackages (ps: [246246+ pythonEnv = python311.withPackages (ps: [245247 ps.numpy246248 ps.toolz247249 ]);···325327{ # ...326328327329 environment.systemPackages = with pkgs; [328328- (python38.withPackages(ps: with ps; [ numpy toolz ]))330330+ (python310.withPackages(ps: with ps; [ numpy toolz ]))329331 ];330332}331333```···346348`toolz` package.347349348350```nix349349-{ lib, buildPythonPackage, fetchPypi }:351351+{ lib352352+, buildPythonPackage353353+, fetchPypi354354+}:350355351356buildPythonPackage rec {352357 pname = "toolz";353358 version = "0.10.0";359359+ format = "setuptools";354360355361 src = fetchPypi {356362 inherit pname version;357363 hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA=";358364 };359365366366+ # has no tests360367 doCheck = false;361368369369+ pythonImportsCheck = [370370+ "toolz.itertoolz"371371+ "toolz.functoolz"372372+ "toolz.dicttoolz"373373+ ];374374+362375 meta = with lib; {376376+ changelog = "https://github.com/pytoolz/toolz/releases/tag/${version}";363377 homepage = "https://github.com/pytoolz/toolz";364378 description = "List processing tools and functional utilities";365379 license = licenses.bsd3;···386376following the name on PyPi) and a version. Another argument, `src` specifies the387377source, which in this case is fetched from PyPI using the helper function388378`fetchPypi`. The argument `doCheck` is used to set whether tests should be run389389-when building the package. Furthermore, we specify some (optional) meta379379+when building the package. Since there are no tests, we rely on `pythonImportsCheck`380380+to test whether the package can be imported. Furthermore, we specify some meta390381information. The output of the function is a derivation.391382392383An expression for `toolz` can be found in the Nixpkgs repository. As explained393384in the introduction of this Python section, a derivation of `toolz` is available394394-for each interpreter version, e.g. `python39.pkgs.toolz` refers to the `toolz`395395-derivation corresponding to the CPython 3.9 interpreter.385385+for each interpreter version, e.g. `python311.pkgs.toolz` refers to the `toolz`386386+derivation corresponding to the CPython 3.11 interpreter.396387397388The above example works when you're directly working on398389`pkgs/top-level/python-packages.nix` in the Nixpkgs repository. Often though,···406395with import <nixpkgs> {};407396408397( let409409- my_toolz = python39.pkgs.buildPythonPackage rec {398398+ my_toolz = python311.pkgs.buildPythonPackage rec {410399 pname = "toolz";411400 version = "0.10.0";401401+ format = "setuptools";412402413413- src = python39.pkgs.fetchPypi {403403+ src = python311.pkgs.fetchPypi {414404 inherit pname version;415405 hash = "sha256-CP3V73yWSArRHBLUct4hrNMjWZlvaaUlkpm1QP66RWA=";416406 };417407408408+ # has no tests418409 doCheck = false;419410420411 meta = {421412 homepage = "https://github.com/pytoolz/toolz/";422413 description = "List processing tools and functional utilities";414414+ # [...]423415 };424416 };425417426426- in python38.withPackages (ps: [ps.numpy my_toolz])418418+ in python311.withPackages (ps: with ps; [419419+ numpy420420+ my_toolz421421+ ])427422).env428423```429424430425Executing `nix-shell` will result in an environment in which you can use431431-Python 3.9 and the `toolz` package. As you can see we had to explicitly mention426426+Python 3.11 and the `toolz` package. As you can see we had to explicitly mention432427for which Python version we want to build a package.433428434429So, what did we do here? Well, we took the Nix expression that we used earlier···459442order to build [`datashape`](https://github.com/blaze/datashape).460443461444```nix462462-{ lib, buildPythonPackage, fetchPypi, numpy, multipledispatch, python-dateutil, pytest }:445445+{ lib446446+, buildPythonPackage447447+, fetchPypi448448+449449+# dependencies450450+, numpy, multipledispatch, python-dateutil451451+452452+# tests453453+, pytest454454+}:463455464456buildPythonPackage rec {465457 pname = "datashape";466458 version = "0.4.7";459459+ format = "setuptools";467460468461 src = fetchPypi {469462 inherit pname version;470463 hash = "sha256-FLLvdm1MllKrgTGC6Gb0k0deZeVYvtCCLji/B7uhong=";471464 };472465473473- nativeCheckInputs = [ pytest ];474474- propagatedBuildInputs = [ numpy multipledispatch python-dateutil ];466466+ propagatedBuildInputs = [467467+ multipledispatch468468+ numpy469469+ python-dateutil470470+ ];471471+472472+ nativeCheckInputs = [473473+ pytest474474+ ];475475476476 meta = with lib; {477477+ changelog = "https://github.com/blaze/datashape/releases/tag/${version}";477478 homepage = "https://github.com/ContinuumIO/datashape";478479 description = "A data description language";479480 license = licenses.bsd2;···501466```502467503468We can see several runtime dependencies, `numpy`, `multipledispatch`, and504504-`python-dateutil`. Furthermore, we have one `nativeCheckInputs`, i.e. `pytest`. `pytest` is a505505-test runner and is only used during the `checkPhase` and is therefore not added506506-to `propagatedBuildInputs`.469469+`python-dateutil`. Furthermore, we have `nativeCheckInputs` with `pytest`.470470+`pytest` is a test runner and is only used during the `checkPhase` and is471471+therefore not added to `propagatedBuildInputs`.507472508473In the previous case we had only dependencies on other Python packages to consider.509474Occasionally you have also system libraries to consider. E.g., `lxml` provides···511476when building the bindings and are therefore added as `buildInputs`.512477513478```nix514514-{ lib, pkgs, buildPythonPackage, fetchPypi }:479479+{ lib480480+, pkgs481481+, buildPythonPackage482482+, fetchPypi483483+}:515484516485buildPythonPackage rec {517486 pname = "lxml";518487 version = "3.4.4";488488+ format = "setuptools";519489520490 src = fetchPypi {521491 inherit pname version;522492 hash = "sha256-s9NiusRxFydHzaNRMjjxFcvWxfi45jGb9ql6eJJyQJk=";523493 };524494525525- buildInputs = [ pkgs.libxml2 pkgs.libxslt ];495495+ buildInputs = [496496+ pkgs.libxml2497497+ pkgs.libxslt498498+ ];526499527500 meta = with lib; {501501+ changelog = "https://github.com/lxml/lxml/releases/tag/lxml-${version}";528502 description = "Pythonic binding for the libxml2 and libxslt libraries";529503 homepage = "https://lxml.de";530504 license = licenses.bsd3;···553509therefore we have to set `LDFLAGS` and `CFLAGS`.554510555511```nix556556-{ lib, pkgs, buildPythonPackage, fetchPypi, numpy, scipy }:512512+{ lib513513+, pkgs514514+, buildPythonPackage515515+, fetchPypi516516+517517+# dependencies518518+, numpy519519+, scipy520520+}:557521558522buildPythonPackage rec {559523 pname = "pyFFTW";560524 version = "0.9.2";525525+ format = "setuptools";561526562527 src = fetchPypi {563528 inherit pname version;564529 hash = "sha256-9ru2r6kwhUCaskiFoaPNuJCfCVoUL01J40byvRt4kHQ=";565530 };566531567567- buildInputs = [ pkgs.fftw pkgs.fftwFloat pkgs.fftwLongDouble];532532+ buildInputs = [533533+ pkgs.fftw534534+ pkgs.fftwFloat535535+ pkgs.fftwLongDouble536536+ ];568537569569- propagatedBuildInputs = [ numpy scipy ];570570-571571- # Tests cannot import pyfftw. pyfftw works fine though.572572- doCheck = false;538538+ propagatedBuildInputs = [539539+ numpy540540+ scipy541541+ ];573542574543 preConfigure = ''575544 export LDFLAGS="-L${pkgs.fftw.dev}/lib -L${pkgs.fftwFloat.out}/lib -L${pkgs.fftwLongDouble.out}/lib"576545 export CFLAGS="-I${pkgs.fftw.dev}/include -I${pkgs.fftwFloat.dev}/include -I${pkgs.fftwLongDouble.dev}/include"577546 '';578547548548+ # Tests cannot import pyfftw. pyfftw works fine though.549549+ doCheck = false;550550+579551 meta = with lib; {552552+ changelog = "https://github.com/pyFFTW/pyFFTW/releases/tag/v${version}";580553 description = "A pythonic wrapper around FFTW, the FFT library, presenting a unified interface for all the supported transforms";581554 homepage = "http://hgomersall.github.com/pyFFTW";582555 license = with licenses; [ bsd2 bsd3 ];···651590 checkPhase = ''652591 runHook preCheck653592654654- pytest tests/ --ignore=tests/integration -k 'not download and not update'593593+ pytest tests/ --ignore=tests/integration -k 'not download and not update' --ignore=tests/test_failing.py655594656595 runHook postCheck657596 '';···679618Using the example above, the analogous `pytestCheckHook` usage would be:680619681620```682682- nativeCheckInputs = [ pytestCheckHook ];621621+ nativeCheckInputs = [622622+ pytestCheckHook623623+ ];683624684625 # requires additional data685685- pytestFlagsArray = [ "tests/" "--ignore=tests/integration" ];626626+ pytestFlagsArray = [627627+ "tests/"628628+ "--ignore=tests/integration"629629+ ];686630687631 disabledTests = [688632 # touches network···729663the listed modules.730664731665```732732- pythonImportsCheck = [ "requests" "urllib" ];666666+ pythonImportsCheck = [667667+ "requests"668668+ "urllib"669669+ ];733670```734671735672roughly translates to:···773704we can do:774705775706```776776- nativeBuildInputs = [ pythonRelaxDepsHook ];777777- pythonRelaxDeps = [ "pkg1" "pkg3" ];778778- pythonRemoveDeps = [ "pkg2" ];707707+ nativeBuildInputs = [708708+ pythonRelaxDepsHook709709+ ];710710+ pythonRelaxDeps = [711711+ "pkg1"712712+ "pkg3"713713+ ];714714+ pythonRemoveDeps = [715715+ "pkg2"716716+ ];779717```780718781719which would result in the following `requirements.txt` file:···825749`unittestCheckHook` is a hook which will substitute the setuptools `test` command for a `checkPhase` which runs `python -m unittest discover`:826750827751```828828- nativeCheckInputs = [ unittestCheckHook ];752752+ nativeCheckInputs = [753753+ unittestCheckHook754754+ ];829755830830- unittestFlagsArray = [ "-s" "tests" "-v" ];756756+ unittestFlagsArray = [757757+ "-s" "tests" "-v"758758+ ];831759```832760833761#### Using sphinxHook {#using-sphinxhook}···896816is a local source, and if the local source has a `setup.py`, then development897817mode is activated.898818899899-In the following example, we create a simple environment that has a Python 3.9819819+In the following example, we create a simple environment that has a Python 3.11900820version of our package in it, as well as its dependencies and other packages we901821like to have in the environment, all specified with `propagatedBuildInputs`.902822Indeed, we can just add any package we like to have in our environment to···904824905825```nix906826with import <nixpkgs> {};907907-with python39Packages;827827+with python311Packages;908828909829buildPythonPackage rec {910830 name = "mypackage";911831 src = ./path/to/package/source;912912- propagatedBuildInputs = [ pytest numpy pkgs.libsndfile ];832832+ propagatedBuildInputs = [833833+ pytest834834+ numpy835835+ pkgs.libsndfile836836+ ];913837}914838```915839···941857We first create a function that builds `toolz` in `~/path/to/toolz/release.nix`942858943859```nix944944-{ lib, buildPythonPackage }:860860+{ lib861861+, buildPythonPackage862862+}:945863946864buildPythonPackage rec {947865 pname = "toolz";948866 version = "0.10.0";867867+ format = "setuptools";949868950869 src = fetchPypi {951870 inherit pname version;···956869 };957870958871 meta = with lib; {872872+ changelog = "https://github.com/pytoolz/toolz/releases/tag/${version}";959873 homepage = "https://github.com/pytoolz/toolz/";960874 description = "List processing tools and functional utilities";961875 license = licenses.bsd3;···973885974886( let975887 toolz = callPackage /path/to/toolz/release.nix {976976- buildPythonPackage = python38Packages.buildPythonPackage;888888+ buildPythonPackage = python310889889+Packages.buildPythonPackage;977890 };978978- in python38.withPackages (ps: [ ps.numpy toolz ])891891+ in python310.withPackages (ps: [892892+ ps.numpy893893+ toolz894894+ ])979895).env980896```981897···987895depends on the `python` derivation that is passed to `buildPythonPackage`. Nix988896tries to automatically pass arguments when possible, which is why generally you989897don't explicitly define which `python` derivation should be used. In the above990990-example we use `buildPythonPackage` that is part of the set `python38Packages`,991991-and in this case the `python38` interpreter is automatically used.898898+example we use `buildPythonPackage` that is part of the set `python3Packages`,899899+and in this case the `python3` interpreter is automatically used.992900993901## Reference {#reference}994902995903### Interpreters {#interpreters}996904997997-Versions 2.7, 3.7, 3.8, 3.9 and 3.10 of the CPython interpreter are available998998-as respectively `python27`, `python37`, `python38`, `python39` and `python310`.905905+Versions 2.7, 3.8, 3.9, 3.10 and 3.11 of the CPython interpreter are available906906+as respectively `python27`, python38`, `python39`, `python310` and `python311`.999907The aliases `python2` and `python3` correspond to respectively `python27` and10001000-`python39`. The attribute `python` maps to `python2`. The PyPy interpreters908908+`python310`. The attribute `python` maps to `python2`. The PyPy interpreters1001909compatible with Python 2.7 and 3 are available as `pypy27` and `pypy3`, with1002910aliases `pypy2` mapping to `pypy27` and `pypy` mapping to `pypy2`. The Nix1003911expressions for the interpreters can be found in···1020928- `buildEnv`. Function to build python interpreter environments with extra packages bundled together. See section *python.buildEnv function* for usage and documentation.1021929- `withPackages`. Simpler interface to `buildEnv`. See section *python.withPackages function* for usage and documentation.1022930- `sitePackages`. Alias for `lib/${libPrefix}/site-packages`.10231023-- `executable`. Name of the interpreter executable, e.g. `python3.8`.931931+- `executable`. Name of the interpreter executable, e.g. `python3.10`.1024932- `pkgs`. Set of Python packages for that specific interpreter. The package set can be modified by overriding the interpreter and passing `packageOverrides`.10259331026934### Optimizations {#optimizations}···1060968sets are10619691062970* `pkgs.python27Packages`10631063-* `pkgs.python37Packages`971971+* `pkgs.python3Packages`1064972* `pkgs.python38Packages`1065973* `pkgs.python39Packages`1066974* `pkgs.python310Packages`···1070978and the aliases10719791072980* `pkgs.python2Packages` pointing to `pkgs.python27Packages`10731073-* `pkgs.python3Packages` pointing to `pkgs.python39Packages`981981+* `pkgs.python3Packages` pointing to `pkgs.python310Packages`1074982* `pkgs.pythonPackages` pointing to `pkgs.python2Packages`10759831076984#### `buildPythonPackage` function {#buildpythonpackage-function}···1082990The following is an example:10839911084992```nix10851085-{ lib, buildPythonPackage, fetchPypi, hypothesis, setuptools-scm, attrs, py, setuptools, six, pluggy }:993993+{ lib994994+, buildPythonPackage995995+, fetchPypi996996+997997+# build-system998998+, setuptools-scm999999+10001000+# dependencies10011001+, attrs10021002+, pluggy10031003+, py10041004+, setuptools10051005+, six10061006+10071007+# tests10081008+, hypothesis10091009+ }:1086101010871011buildPythonPackage rec {10881012 pname = "pytest";10891013 version = "3.3.1";10141014+ format = "setuptools";1090101510911016 src = fetchPypi {10921017 inherit pname version;···11151006 rm testing/test_argcomplete.py11161007 '';1117100811181118- nativeCheckInputs = [ hypothesis ];11191119- nativeBuildInputs = [ setuptools-scm ];11201120- propagatedBuildInputs = [ attrs py setuptools six pluggy ];10091009+ nativeBuildInputs = [10101010+ setuptools-scm10111011+ ];10121012+10131013+ propagatedBuildInputs = [10141014+ attrs10151015+ py10161016+ setuptools10171017+ six10181018+ pluggy10191019+ ];10201020+10211021+ nativeCheckInputs = [10221022+ hypothesis10231023+ ];1121102411221025 meta = with lib; {11231123- maintainers = with maintainers; [ domenkozar lovek323 madjar lsix ];10261026+ changelog = "https://github.com/pytest-dev/pytest/releases/tag/${version}";11241027 description = "Framework for writing tests";10281028+ homepage = "https://github.com/pytest-dev/pytest";10291029+ license = licenses.mit;10301030+ maintainers = with maintainers; [ domenkozar lovek323 madjar lsix ];11251031 };11261032}11271033```···12381114 };12391115 in pkgs.python3.override {inherit packageOverrides; self = python;};1240111612411241-in python.withPackages(ps: [ps.blaze])).env11171117+in python.withPackages(ps: [ ps.blaze ])).env12421118```1243111912441120#### Optional extra dependencies {#python-optional-dependencies}···12841160specifying an interpreter version), like this:1285116112861162```nix12871287-{ lib, python3 }:11631163+{ lib11641164+, python311651165+}:1288116612891167python3.pkgs.buildPythonApplication rec {12901168 pname = "luigi";12911169 version = "2.7.9";11701170+ format = "setuptools";1292117112931172 src = python3.pkgs.fetchPypi {12941173 inherit pname version;12951174 hash = "sha256-Pe229rT0aHwA98s+nTHQMEFKZPo/yw6sot8MivFDvAw=";12961175 };1297117612981298- propagatedBuildInputs = with python3.pkgs; [ tornado python-daemon ];11771177+ propagatedBuildInputs = with python3.pkgs; [11781178+ tornado11791179+ python-daemon11801180+ ];1299118113001182 meta = with lib; {13011183 ...···13831253with import <nixpkgs> {};1384125413851255(python3.buildEnv.override {13861386- extraLibs = with python3Packages; [ numpy requests ];12561256+ extraLibs = with python3Packages; [12571257+ numpy12581258+ requests12591259+ ];13871260}).env13881261```13891262···14121279```nix14131280with import <nixpkgs> {};1414128114151415-python.withPackages (ps: [ps.pyramid])12821282+python.withPackages (ps: [ ps.pyramid ])14161283```1417128414181285`withPackages` passes the correct package set for the specific interpreter···14221289```nix14231290with import <nixpkgs> {};1424129114251425-python3.withPackages (ps: [ps.pyramid])12921292+python3.withPackages (ps: [ ps.pyramid ])14261293```1427129414281295Now, `ps` is set to `python3Packages`, matching the version of the interpreter.···14341301```nix14351302with import <nixpkgs> {};1436130314371437-(python38.withPackages (ps: [ps.numpy ps.requests])).env13041304+(python3.withPackages (ps: with ps; [13051305+ numpy13061306+ requests13071307+])).env14381308```1439130914401310In contrast to `python.buildEnv`, `python.withPackages` does not support the···1529139315301394When the environment variable `DETERMINISTIC_BUILD` is set, all bytecode will15311395have timestamp 1. The `buildPythonPackage` function sets `DETERMINISTIC_BUILD=1`15321532-and [PYTHONHASHSEED=0](https://docs.python.org/3.8/using/cmdline.html#envvar-PYTHONHASHSEED).13961396+and [PYTHONHASHSEED=0](https://docs.python.org/3.11/using/cmdline.html#envvar-PYTHONHASHSEED).15331397Both are also exported in `nix-shell`.1534139815351399### Automatic tests {#automatic-tests}···15441408#### Common issues {#common-issues}1545140915461410* Non-working tests can often be deselected. By default `buildPythonPackage`15471547- runs `python setup.py test`. Most Python modules follows the standard test15481548- protocol where the pytest runner can be used instead. `py.test` supports a15491549- `-k` parameter to ignore test methods or classes:14111411+ runs `python setup.py test`. which is deprecated. Most Python modules however14121412+ do follow the standard test protocol where the pytest runner can be used14131413+ instead. `pytest` supports the `-k` and `--ignore` parameters to ignore test14141414+ methods or classes as well as whole files. For `pytestCheckHook` these are14151415+ conveniently exposed as `disabledTests` and `disabledTestPaths` respectively.1550141615511417 ```nix15521418 buildPythonPackage {15531419 # ...15541554- # assumes the tests are located in tests15551555- nativeCheckInputs = [ pytest ];15561556- checkPhase = ''15571557- runHook preCheck14201420+ nativeCheckInputs = [14211421+ pytestCheckHook14221422+ ];1558142315591559- py.test -k 'not function_name and not other_function' tests14241424+ disabledTests = [14251425+ "function_name"14261426+ "other_function"14271427+ ];1560142815611561- runHook postCheck15621562- '';14291429+ disabledTestPaths = [14301430+ "this/file.py"14311431+ ];15631432 }15641433 ```15651434···15921451 packageOverrides = self: super: {15931452 pandas = super.pandas.overridePythonAttrs(old: {name="foo";});15941453 };15951595- in pkgs.python38.override {inherit packageOverrides;};14541454+ in pkgs.python310.override {14551455+ inherit packageOverrides;14561456+ };1596145715971597-in python.withPackages(ps: [ps.pandas])).env14581458+in python.withPackages (ps: [14591459+ ps.pandas14601460+])).env15981461```1599146216001463Using `nix-build` on this expression will build an environment that contains the···16181473 packageOverrides = self: super: {16191474 scipy = super.scipy_0_17;16201475 };16211621- in (pkgs.python38.override {inherit packageOverrides;}).withPackages (ps: [ps.blaze])14761476+ in (pkgs.python310.override {14771477+ inherit packageOverrides;14781478+ }).withPackages (ps: [14791479+ ps.blaze14801480+ ])16221481).env16231482```16241483···16361487let16371488 pkgs = import <nixpkgs> {};16381489 newpkgs = import pkgs.path { overlays = [ (self: super: {16391639- python38 = let14901490+ python310 = let16401491 packageOverrides = python-self: python-super: {16411492 numpy = python-super.numpy_1_18;16421493 };16431643- in super.python38.override {inherit packageOverrides;};14941494+ in super.python310.override {inherit packageOverrides;};16441495 } ) ]; };16451496in newpkgs.inkscape16461497```
+1-1
doc/stdenv/stdenv.chapter.md
···1204120412051205In order to alleviate this burden, the setup hook mechanism was written, where any package can include a shell script that \[by convention rather than enforcement by Nix\], any downstream reverse-dependency will source as part of its build process. That allows the downstream dependency to merely specify its dependencies, and lets those dependencies effectively initialize themselves. No boilerplate mirroring the list of dependencies is needed.1206120612071207-The setup hook mechanism is a bit of a sledgehammer though: a powerful feature with a broad and indiscriminate area of effect. The combination of its power and implicit use may be expedient, but isn’t without costs. Nix itself is unchanged, but the spirit of added dependencies being effect-free is violated even if the letter isn’t. For example, if a derivation path is mentioned more than once, Nix itself doesn’t care and simply makes sure the dependency derivation is already built just the same—depending is just needing something to exist, and needing is idempotent. However, a dependency specified twice will have its setup hook run twice, and that could easily change the build environment (though a well-written setup hook will therefore strive to be idempotent so this is in fact not observable). More broadly, setup hooks are anti-modular in that multiple dependencies, whether the same or different, should not interfere and yet their setup hooks may well do so.12071207+The setup hook mechanism is a bit of a sledgehammer though: a powerful feature with a broad and indiscriminate area of effect. The combination of its power and implicit use may be expedient, but isn’t without costs. Nix itself is unchanged, but the spirit of added dependencies being effect-free is violated even if the latter isn’t. For example, if a derivation path is mentioned more than once, Nix itself doesn’t care and simply makes sure the dependency derivation is already built just the same—depending is just needing something to exist, and needing is idempotent. However, a dependency specified twice will have its setup hook run twice, and that could easily change the build environment (though a well-written setup hook will therefore strive to be idempotent so this is in fact not observable). More broadly, setup hooks are anti-modular in that multiple dependencies, whether the same or different, should not interfere and yet their setup hooks may well do so.1208120812091209The most typical use of the setup hook is actually to add other hooks which are then run (i.e. after all the setup hooks) on each dependency. For example, the C compiler wrapper’s setup hook feeds itself flags for each dependency that contains relevant libraries and headers. This is done by defining a bash function, and appending its name to one of `envBuildBuildHooks`, `envBuildHostHooks`, `envBuildTargetHooks`, `envHostHostHooks`, `envHostTargetHooks`, or `envTargetTargetHooks`. These 6 bash variables correspond to the 6 sorts of dependencies by platform (there’s 12 total but we ignore the propagated/non-propagated axis).12101210
+2
nixos/doc/manual/release-notes/rl-2305.section.md
···190190191191- `nushell` has been updated to at least version 0.77.0, which includes potential breaking changes in aliases. The old aliases are now available as `old-alias` but it is recommended you migrate to the new format. See [Reworked aliases](https://www.nushell.sh/blog/2023-03-14-nushell_0_77.html#reworked-aliases-breaking-changes-kubouch).192192193193+- `gajim` has been updated to version 1.7.3 which has disabled legacy ciphers. See [changelog for version 1.7.0](https://dev.gajim.org/gajim/gajim/-/releases/1.7.0).194194+193195- `keepassx` and `keepassx2` have been removed, due to upstream [stopping development](https://www.keepassx.org/index.html%3Fp=636.html). Consider [KeePassXC](https://keepassxc.org) as a maintained alternative.194196195197- The [services.kubo.settings](#opt-services.kubo.settings) option is now no longer stateful. If you changed any of the options in [services.kubo.settings](#opt-services.kubo.settings) in the past and then removed them from your NixOS configuration again, those changes are still in your Kubo configuration file but will now be reset to the default. If you're unsure, you may want to make a backup of your configuration file (probably /var/lib/ipfs/config) and compare after the update.
···22, buildPythonPackage33, fetchpatch44, fetchPypi55+, pythonAtLeast56}:6778buildPythonPackage rec {89 pname = "fn";910 version = "0.4.3";1111+1212+ # Python 3.11 changed the API of the `inspect` module and fn was never1313+ # updated to adapt; last commit was in 2014.1414+ disabled = pythonAtLeast "3.11";10151116 src = fetchPypi {1217 inherit pname version;
···3737 version = esVersion;3838 src = fetchurl {3939 url = "https://artifacts.elastic.co/downloads/elasticsearch-plugins/${pluginName}/${pluginName}-${version}.zip";4040- sha256 =4141- if version == "7.17.9" then "sha256-70KU7aGUHEZsjykXqHUYspGyX0CCrlS1er9WdUbxxSE="4040+ hash =4141+ if version == "7.17.10" then "sha256-D08CVW/qHpZZaKnploM4aCJ4bunvPjVmieDYr1d6jQA="4242 else throw "unsupported version ${version} for plugin ${pluginName}";4343 };4444 meta = with lib; {···5353 version = esVersion;5454 src = fetchurl {5555 url = "https://artifacts.elastic.co/downloads/elasticsearch-plugins/${pluginName}/${pluginName}-${version}.zip";5656- sha256 =5757- if version == "7.17.9" then "sha256-oRTs1eK7jpoKaMvc+6rx9qiA8wg+gYUADM0HuJU0nOY="5656+ hash =5757+ if version == "7.17.10" then "sha256-cpgr2zPCpsLrmshWJWoGNcGl0X+bO/K4A9bMqLv8+H8="5858 else throw "unsupported version ${version} for plugin ${pluginName}";5959 };6060 meta = with lib; {···6969 version = esVersion;7070 src = fetchurl {7171 url = "https://github.com/vhyza/elasticsearch-${pluginName}/releases/download/v${version}/elasticsearch-${pluginName}-${version}-plugin.zip";7272- sha256 =7272+ hash =7373 if version == "7.17.9" then "sha256-iY25apDkS6s0RoR9dVL2o/hFuUo6XhMzLjl8wDSFejk="7474 else throw "unsupported version ${version} for plugin ${pluginName}";7575 };···7777 homepage = "https://github.com/vhyza/elasticsearch-analysis-lemmagen";7878 description = "LemmaGen Analysis plugin provides jLemmaGen lemmatizer as Elasticsearch token filter";7979 license = licenses.asl20;8080+ broken = true; # Not released yet for ES 7.17.108081 };8182 };8283···8685 version = esVersion;8786 src = fetchurl {8887 url = "https://artifacts.elastic.co/downloads/elasticsearch-plugins/${pluginName}/${pluginName}-${version}.zip";8989- sha256 =9090- if version == "7.17.9" then "sha256-xlEabvNiddEwRfKrHIq1QPFJFMd2gByurIZF9LOxVSs="8888+ hash =8989+ if version == "7.17.10" then "sha256-UmykO+hZDvlFhEbf7zL2bdw4j6NhByRBu9eH3F6/EtM="9190 else throw "unsupported version ${version} for plugin ${pluginName}";9291 };9392 meta = with lib; {···102101 version = esVersion;103102 src = fetchurl {104103 url = "https://artifacts.elastic.co/downloads/elasticsearch-plugins/${pluginName}/${pluginName}-${version}.zip";105105- sha256 =106106- if version == "7.17.9" then "sha256-J1q87fhL4A5tkxPADgHflPbO2RRMGPUk58l7DEpgd94="104104+ hash =105105+ if version == "7.17.10" then "sha256-Y/AbLfHSdocX0NQbnKm63gTWgwzssb4kpSwRqLozD9w="107106 else throw "unsupported version ${version} for plugin ${pluginName}";108107 };109108 meta = with lib; {···118117 version = esVersion;119118 src = fetchurl {120119 url = "https://artifacts.elastic.co/downloads/elasticsearch-plugins/${pluginName}/${pluginName}-${version}.zip";121121- sha256 =122122- if version == "7.17.9" then "sha256-BhJtBdsT5Xapehfn0xaTWpSrvT1W+Hhv/yqliA6dBG8="120120+ hash =121121+ if version == "7.17.10" then "sha256-QIYD7cGpJQg+csv/tekN6GFtdnuhYU6VyAXk7nY/uWs="123122 else throw "unsupported version ${version} for plugin ${pluginName}";124123 };125124 meta = with lib; {···134133 version = esVersion;135134 src = fetchurl {136135 url = "https://artifacts.elastic.co/downloads/elasticsearch-plugins/${pluginName}/${pluginName}-${esVersion}.zip";137137- sha256 =138138- if version == "7.17.9" then "sha256-bjVMVwZfj9WyjkwTXwTJdmaqZ1sWuvOZKXh9PFTOwb8="136136+ hash =137137+ if version == "7.17.10" then "sha256-L8lS+EPYuhNNTnP3ImeZsBQ5a5DAncs3qBFDWGWISRI="139138 else throw "unsupported version ${version} for plugin ${pluginName}";140139 };141140 meta = with lib; {···150149 version = esVersion;151150 src = fetchurl {152151 url = "https://artifacts.elastic.co/downloads/elasticsearch-plugins/${pluginName}/${pluginName}-${esVersion}.zip";153153- sha256 =154154- if version == "7.17.9" then "sha256-ZyImIHYOz5bOEA+ARtPB2CznTOSjFKsavzWXXEzfkO8="152152+ hash =153153+ if version == "7.17.10" then "sha256-eXstbxlyS8WzW8u5YiMFXGpILCcEWrIb/IxXVzAGFLU="155154 else throw "unsupported version ${version} for plugin ${pluginName}";156155 };157156 meta = with lib; {···167166 pluginName = "search-guard";168167 version =169168 # https://docs.search-guard.com/latest/search-guard-versions170170- if esVersion == "7.17.9" then "${esVersion}-53.6.0"169169+ if esVersion == "7.17.10" then "${esVersion}-53.7.0"171170 else throw "unsupported version ${esVersion} for plugin ${pluginName}";172171 src =173173- if esVersion == "7.17.9" then172172+ if esVersion == "7.17.10" then174173 fetchurl {175174 url = "https://maven.search-guard.com/search-guard-suite-release/com/floragunn/search-guard-suite-plugin/${version}/search-guard-suite-plugin-${version}.zip";176176- sha256 = "sha256-HwxNvWvjqaI3ytSjNnsGcyt3omIZp69bgwxoufL2Nj8=";175175+ hash = "sha256-FIF4O8z0U2giXVA2cNEdCDbpuJDJhaxHBOmv2fACucw=";177176 }178177 else throw "unsupported version ${version} for plugin ${pluginName}";179178 meta = with lib; {