From 146bc8dcb2c41f221b277042b8f6a9139947c3a7 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 23a03b8c259e..6472c3f57789 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 bf2b4029e8d0..97637b55e505 100644 --- a/doc/redirects.json +++ b/doc/redirects.json @@ -4059,6 +4059,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 7dfebf9c96112a4e68dedb093d48a5fc1af65012 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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index 6472c3f57789..990b12d3a9db 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -241,6 +241,27 @@ 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` +- `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 bfa489d718c7dccb8e2e364560f0be951fdf967d 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 990b12d3a9db..28826768cd0b 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 f8f04a972e3c53148fb9d28f6fb6fb227659ce99 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 | 40 +++++++++------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index 28826768cd0b..da76fb682b39 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -293,29 +293,23 @@ 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="; - }; - }); - }; - in - pkgs.python3.override { - inherit packageOverrides; - self = python; - }; - - in - python.withPackages (ps: [ ps.blaze ]) -).env +let + python = pkgs.python3.override { + packageOverrides = self: super: { + pandas = super.pandas.overridePythonAttrs ( + finalAttrs: prevAttrs: { + version = "0.19.1"; + src = fetchPypi { + pname = "pandas"; + inherit (finalAttrs) version; + hash = "sha256-JQn+rtpy/OA2deLszSKEuxyttqBzcAil50H+JDHUdCE="; + }; + } + ); + }; + }; +in +(python.withPackages (ps: [ ps.blaze ])).env ``` The next example shows a non trivial overriding of the `blas` implementation to