Skip to content

Commit c4e3b67

Browse files
committed
buildPython*: allow stdenv customization through <function>.override
1 parent 7a4ad37 commit c4e3b67

3 files changed

Lines changed: 33 additions & 13 deletions

File tree

pkgs/development/interpreters/python/mk-python-derivation.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
lib,
55
config,
66
python,
7+
# Allow passing in a custom stdenv to buildPython*.override
8+
stdenv,
79
wrapPython,
810
unzip,
911
ensureNewerSourcesForZipFilesHook,
@@ -192,9 +194,6 @@ in
192194

193195
doCheck ? true,
194196

195-
# Allow passing in a custom stdenv to buildPython*
196-
stdenv ? python.stdenv,
197-
198197
...
199198
}@attrs:
200199

pkgs/development/interpreters/python/python-packages-base.nix

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,42 @@ let
4545
override = lib.mirrorFunctionArgs f.override (fdrv: makeOverridablePythonPackage (f.override fdrv));
4646
};
4747

48+
overrideStdenvCompat =
49+
f:
50+
lib.setFunctionArgs (
51+
args:
52+
if !(lib.isFunction args) && (args ? stdenv) then
53+
# TODO: warn that `args ? stdenv` is deprecated (once in-tree usage is migrated)
54+
f.override { stdenv = args.stdenv; } args
55+
else
56+
f args
57+
) (removeAttrs (lib.functionArgs f) [ "stdenv" ])
58+
// {
59+
# Intentionally drop the effect of overrideStdenvCompat when calling `buildPython*.override`.
60+
inherit (f) override;
61+
};
62+
4863
mkPythonDerivation =
4964
if python.isPy3k then ./mk-python-derivation.nix else ./python2/mk-python-derivation.nix;
5065

5166
buildPythonPackage = makeOverridablePythonPackage (
52-
callPackage mkPythonDerivation {
53-
inherit namePrefix; # We want Python libraries to be named like e.g. "python3.6-${name}"
54-
inherit toPythonModule; # Libraries provide modules
55-
}
67+
overrideStdenvCompat (
68+
callPackage mkPythonDerivation {
69+
inherit namePrefix; # We want Python libraries to be named like e.g. "python3.6-${name}"
70+
inherit toPythonModule; # Libraries provide modules
71+
inherit (python) stdenv;
72+
}
73+
)
5674
);
5775

5876
buildPythonApplication = makeOverridablePythonPackage (
59-
callPackage mkPythonDerivation {
60-
namePrefix = ""; # Python applications should not have any prefix
61-
toPythonModule = x: x; # Application does not provide modules.
62-
}
77+
overrideStdenvCompat (
78+
callPackage mkPythonDerivation {
79+
namePrefix = ""; # Python applications should not have any prefix
80+
toPythonModule = x: x; # Application does not provide modules.
81+
inherit (python) stdenv;
82+
}
83+
)
6384
);
6485

6586
# Check whether a derivation provides a Python module.

pkgs/development/interpreters/python/python2/mk-python-derivation.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
lib,
55
config,
66
python,
7+
# Allow passing in a custom stdenv to buildPython*.override
8+
stdenv,
79
wrapPython,
810
unzip,
911
ensureNewerSourcesForZipFilesHook,
@@ -101,8 +103,6 @@
101103
}@attrs:
102104

103105
let
104-
inherit (python) stdenv;
105-
106106
withDistOutput = lib.elem format [
107107
"pyproject"
108108
"setuptools"

0 commit comments

Comments
 (0)