From 5339e49cd48a1f72ab711440d451f670fcb9450b Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Mon, 5 Jan 2026 15:27:21 +0200 Subject: [PATCH 1/4] doc/python: document fixed-point arguments (#271387) --- doc/languages-frameworks/python.section.md | 34 ++++++++++++++++++++++ doc/redirects.json | 3 ++ 2 files changed, 37 insertions(+) diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index fad930c8206dd..61a2c493c6a8f 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -207,6 +207,40 @@ following are specific to `buildPythonPackage`: * `setupPyGlobalFlags ? []`: List of flags passed to `setup.py` command. * `setupPyBuildFlags ? []`: List of flags passed to `setup.py build_ext` command. +##### Using fixed-point arguments {#buildpythonpackage-fixed-point-arguments} + +Both `buildPythonPackage` and `buildPythonApplication` support [fixed-point arguments](#chap-build-helpers-finalAttrs), similar to `stdenv.mkDerivation`. +This allows you to reference the final attributes of the derivation. + +Instead of using `rec`: + +```nix +buildPythonPackage rec { + pname = "pyspread"; + version = "2.4"; + src = fetchPypi { + inherit pname version; + hash = "sha256-..."; + }; +} +``` + +You can use the `finalAttrs` pattern: + +```nix +buildPythonPackage (finalAttrs: { + pname = "pyspread"; + version = "2.4"; + src = fetchPypi { + pname = "pyspread"; + inherit (finalAttrs) version; + hash = "sha256-..."; + }; +}) +``` + +See the [general documentation on fixed-point arguments](#chap-build-helpers-finalAttrs) for more details on the benefits of this pattern. + The [`stdenv.mkDerivation`](#sec-using-stdenv) function accepts various parameters for describing build inputs (see "Specifying dependencies"). The following are of special interest for Python packages, either because these are primarily used, or diff --git a/doc/redirects.json b/doc/redirects.json index bc0bf55213846..e81e8471a7d43 100644 --- a/doc/redirects.json +++ b/doc/redirects.json @@ -3845,6 +3845,9 @@ "buildpythonpackage-parameters": [ "index.html#buildpythonpackage-parameters" ], + "buildpythonpackage-fixed-point-arguments": [ + "index.html#buildpythonpackage-fixed-point-arguments" + ], "overriding-python-build-helpers": [ "index.html#overriding-python-build-helpers" ], From ad54fe3517305abffe4d46068b33aa5159c42ca6 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Tue, 6 Jan 2026 17:02:08 +0200 Subject: [PATCH 2/4] python.section.md: List finalAttrs.passthru only attributes --- doc/languages-frameworks/python.section.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index 61a2c493c6a8f..bc3267566c835 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -241,6 +241,26 @@ buildPythonPackage (finalAttrs: { See the [general documentation on fixed-point arguments](#chap-build-helpers-finalAttrs) for more details on the benefits of this pattern. +::: {.note} + +Some `buildPythonPackage`/`buildPythonApplication` arguments are passed down indirectly to `stdenv.mkDerivation` via `passthru`. +Therefore the final states of these attributes can be accessed via `finalAttrs.passthru.${name}`, and they can be overridden via [`.overrideAttrs`](#sec-pkg-overrideAttrs) under the `passthru` attribute. +Such arguments include: + +- `disabled` +- `pyproject` +- `format` +- `build-system`, `dependencies` and `optional-dependencies` + + +::: + The [`stdenv.mkDerivation`](#sec-using-stdenv) function accepts various parameters for describing build inputs (see "Specifying dependencies"). The following are of special interest for Python packages, either because these are primarily used, or From daf1d4675e4437284ef7403b6ef68ad7a75f3a03 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Mon, 12 Jan 2026 20:44:52 +0200 Subject: [PATCH 3/4] doc/python: explain better passthru note Co-authored-by: Matt Sturgeon --- doc/languages-frameworks/python.section.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index bc3267566c835..50a05a98ed027 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -244,7 +244,8 @@ See the [general documentation on fixed-point arguments](#chap-build-helpers-fin ::: {.note} Some `buildPythonPackage`/`buildPythonApplication` arguments are passed down indirectly to `stdenv.mkDerivation` via `passthru`. -Therefore the final states of these attributes can be accessed via `finalAttrs.passthru.${name}`, and they can be overridden via [`.overrideAttrs`](#sec-pkg-overrideAttrs) under the `passthru` attribute. +Therefore the final state of these attributes can be accessed via `finalAttrs.passthru.${name}`. +[`.overrideAttrs`](#sec-pkg-overrideAttrs) can override them using the `passthru = prevAttrs.passthru // { foo = "bar"; }` pattern. Such arguments include: - `disabled` From 5ac29962b7190156b41c1f7be2641b79d865e664 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Mon, 12 Jan 2026 20:40:53 +0200 Subject: [PATCH 4/4] doc/python: simplify packageOverrides example --- doc/languages-frameworks/python.section.md | 36 +++++++++------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index 50a05a98ed027..e8c4435f7fc4d 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -292,29 +292,21 @@ the overrides for packages in the package set. ```nix with import { }; -( - let - python = - let - packageOverrides = self: super: { - pandas = super.pandas.overridePythonAttrs (old: rec { - version = "0.19.1"; - src = fetchPypi { - pname = "pandas"; - inherit version; - hash = "sha256-JQn+rtpy/OA2deLszSKEuxyttqBzcAil50H+JDHUdCE="; - }; - }); +let + python = pkgs.python3.override { + packageOverrides = self: super: { + pandas = super.pandas.overridePythonAttrs (old: { + version = "0.19.1"; + src = fetchPypi { + pname = "pandas"; + inherit version; + hash = "sha256-JQn+rtpy/OA2deLszSKEuxyttqBzcAil50H+JDHUdCE="; }; - in - pkgs.python3.override { - inherit packageOverrides; - self = python; - }; - - in - python.withPackages (ps: [ ps.blaze ]) -).env + }); + }; + }; +in +(python.withPackages (ps: [ ps.blaze ])).env ``` The next example shows a non trivial overriding of the `blas` implementation to