buildPython*: allow stdenv customization through <function>.override

This commit is contained in:
Yueh-Shun Li
2025-01-23 02:07:35 +08:00
parent 7a4ad371b1
commit c4e3b67afb
3 changed files with 33 additions and 13 deletions

View File

@@ -4,6 +4,8 @@
lib,
config,
python,
# Allow passing in a custom stdenv to buildPython*.override
stdenv,
wrapPython,
unzip,
ensureNewerSourcesForZipFilesHook,
@@ -192,9 +194,6 @@ in
doCheck ? true,
# Allow passing in a custom stdenv to buildPython*
stdenv ? python.stdenv,
...
}@attrs:

View File

@@ -45,21 +45,42 @@ let
override = lib.mirrorFunctionArgs f.override (fdrv: makeOverridablePythonPackage (f.override fdrv));
};
overrideStdenvCompat =
f:
lib.setFunctionArgs (
args:
if !(lib.isFunction args) && (args ? stdenv) then
# TODO: warn that `args ? stdenv` is deprecated (once in-tree usage is migrated)
f.override { stdenv = args.stdenv; } args
else
f args
) (removeAttrs (lib.functionArgs f) [ "stdenv" ])
// {
# Intentionally drop the effect of overrideStdenvCompat when calling `buildPython*.override`.
inherit (f) override;
};
mkPythonDerivation =
if python.isPy3k then ./mk-python-derivation.nix else ./python2/mk-python-derivation.nix;
buildPythonPackage = makeOverridablePythonPackage (
callPackage mkPythonDerivation {
inherit namePrefix; # We want Python libraries to be named like e.g. "python3.6-${name}"
inherit toPythonModule; # Libraries provide modules
}
overrideStdenvCompat (
callPackage mkPythonDerivation {
inherit namePrefix; # We want Python libraries to be named like e.g. "python3.6-${name}"
inherit toPythonModule; # Libraries provide modules
inherit (python) stdenv;
}
)
);
buildPythonApplication = makeOverridablePythonPackage (
callPackage mkPythonDerivation {
namePrefix = ""; # Python applications should not have any prefix
toPythonModule = x: x; # Application does not provide modules.
}
overrideStdenvCompat (
callPackage mkPythonDerivation {
namePrefix = ""; # Python applications should not have any prefix
toPythonModule = x: x; # Application does not provide modules.
inherit (python) stdenv;
}
)
);
# Check whether a derivation provides a Python module.

View File

@@ -4,6 +4,8 @@
lib,
config,
python,
# Allow passing in a custom stdenv to buildPython*.override
stdenv,
wrapPython,
unzip,
ensureNewerSourcesForZipFilesHook,
@@ -101,8 +103,6 @@
}@attrs:
let
inherit (python) stdenv;
withDistOutput = lib.elem format [
"pyproject"
"setuptools"