From 0aebd262f121eb2162636a57db666d39d623bdd3 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Sun, 28 Sep 2025 17:00:12 +0800 Subject: [PATCH 1/7] python3Packages.buildPythonPackage: add internal helper getFinalPassthru Add getFinalPassthru, an internal helper function that produces informative error message when an atttribute is not found in `finalAttrs.passthru`. --- .../interpreters/python/mk-python-derivation.nix | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index eb8e76101c49..98565766e54b 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -204,6 +204,20 @@ let self = stdenv.mkDerivation ( finalAttrs: let + getFinalPassthru = + let + pos = unsafeGetAttrPos "passthru" finalAttrs; + in + attrName: + finalAttrs.passthru.${attrName} or (throw ( + '' + ${finalAttrs.name}: passthru.${attrName} missing after overrideAttrs overriding. + '' + + optionalString (pos != null) '' + Last overridden at ${pos.file}:${toString pos.line} + '' + )); + format' = assert (pyproject != null) -> (format == null); if pyproject != null then From b02dda8ea8dc38124cf7f98628e5a4476a380afd Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 27 Jan 2025 01:46:05 +0800 Subject: [PATCH 2/7] python3Packages.buildPythonPackage: make passthru.pyproject overridable --- .../python/mk-python-derivation.nix | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index 98565766e54b..1dd87d22f2de 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -219,9 +219,9 @@ let )); format' = - assert (pyproject != null) -> (format == null); - if pyproject != null then - if pyproject then "pyproject" else "other" + assert (getFinalPassthru "pyproject" != null) -> (format == null); + if getFinalPassthru "pyproject" != null then + if getFinalPassthru "pyproject" then "pyproject" else "other" else if format != null then format else @@ -276,11 +276,11 @@ let in attrName: inputs: map (checkDrv attrName) inputs; - isBootstrapInstallPackage = isBootstrapInstallPackage' (attrs.pname or null); + isBootstrapInstallPackage = isBootstrapInstallPackage' (finalAttrs.pname or null); - isBootstrapPackage = isBootstrapInstallPackage || isBootstrapPackage' (attrs.pname or null); + isBootstrapPackage = isBootstrapInstallPackage || isBootstrapPackage' (finalAttrs.pname or null); - isSetuptoolsDependency = isSetuptoolsDependency' (attrs.pname or null); + isSetuptoolsDependency = isSetuptoolsDependency' (finalAttrs.pname or null); name = namePrefix + attrs.name or "${finalAttrs.pname}-${finalAttrs.version}"; @@ -410,7 +410,10 @@ let outputs = outputs ++ optional withDistOutput "dist"; passthru = { - inherit disabled; + inherit + disabled + pyproject + ; } // { updateScript = nix-update-script { }; From e25f3c91031ac08c9c03983ce12e250c0cf79cc7 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 27 Jan 2025 01:46:32 +0800 Subject: [PATCH 3/7] python3Packages.buildPythonPackage: make src overridable --- pkgs/development/interpreters/python/mk-python-derivation.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index 1dd87d22f2de..c2099c6c4d4b 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -314,7 +314,7 @@ let ++ optionals removeBinBytecode [ pythonRemoveBinBytecodeHook ] - ++ optionals (hasSuffix "zip" (attrs.src.name or "")) [ + ++ optionals (hasSuffix "zip" (finalAttrs.src.name or "")) [ unzip ] ++ optionals (format' == "setuptools") [ From e2f75c6f5e2db43203821a207af9b650391973ed Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 27 Jan 2025 01:48:44 +0800 Subject: [PATCH 4/7] python3Packages.buildPythonPackage: use pythonRelaxDepsHook iff related attributes non-empty --- .../interpreters/python/mk-python-derivation.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index c2099c6c4d4b..b79d5325a4f3 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -308,9 +308,11 @@ let # pythonCatchConflictsHook ] - ++ optionals (attrs ? pythonRelaxDeps || attrs ? pythonRemoveDeps) [ - pythonRelaxDepsHook - ] + ++ + optionals (finalAttrs.pythonRelaxDeps or [ ] != [ ] || finalAttrs.pythonRemoveDeps or [ ] != [ ]) + [ + pythonRelaxDepsHook + ] ++ optionals removeBinBytecode [ pythonRemoveBinBytecodeHook ] From 67d2a84468c7d2952cb03d4462386bb44a22e8bc Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 27 Jan 2025 01:07:30 +0800 Subject: [PATCH 5/7] python3Packages.buildPythonPackage: pass passthru.dependencies empty or not --- .../interpreters/python/mk-python-derivation.nix | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index b79d5325a4f3..6b4db7c9a273 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -415,20 +415,14 @@ let inherit disabled pyproject + build-system + dependencies + optional-dependencies ; } // { updateScript = nix-update-script { }; } - // optionalAttrs (dependencies != [ ]) { - inherit dependencies; - } - // optionalAttrs (optional-dependencies != { }) { - inherit optional-dependencies; - } - // optionalAttrs (build-system != [ ]) { - inherit build-system; - } // attrs.passthru or { }; meta = { From 42ba377ba8bc6e1156d4a30215019819528e88f4 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 27 Jan 2025 01:09:12 +0800 Subject: [PATCH 6/7] python3Packages.buildPythonPackage: make passthru.{dependencies,build-system} overridable --- pkgs/development/interpreters/python/mk-python-derivation.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index 6b4db7c9a273..046aa5e604ca 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -371,13 +371,13 @@ let pythonOutputDistHook ] ++ nativeBuildInputs - ++ build-system; + ++ getFinalPassthru "build-system"; buildInputs = validatePythonMatches "buildInputs" (buildInputs ++ pythonPath); propagatedBuildInputs = validatePythonMatches "propagatedBuildInputs" ( propagatedBuildInputs - ++ dependencies + ++ getFinalPassthru "dependencies" ++ [ # we propagate python even for packages transformed with 'toPythonApplication' # this pollutes the PATH but avoids rebuilds From bc122a602a1c8f54fcf3e82ad4ccffecfa8efec8 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 27 Jan 2025 01:53:03 +0800 Subject: [PATCH 7/7] python3Packages.buildPythonPackage: remove ineffective outputs cleanAttrs --- pkgs/development/interpreters/python/mk-python-derivation.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index 046aa5e604ca..b3ef73804311 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -106,7 +106,6 @@ let "doInstallCheck" "pyproject" "format" - "outputs" "stdenv" "dependencies" "optional-dependencies"