buildPython*: preserve overrideStdenvCompat on subsequent overrides

This is needed to support the deprecated method of overriding `stdenv`
via `overridePythonAttrs`.
This commit is contained in:
Matt Sturgeon
2025-12-11 01:15:17 +00:00
parent 32ecc2256b
commit 553a6c3d3a
2 changed files with 24 additions and 14 deletions
@@ -45,20 +45,23 @@ let
overrideStdenvCompat =
f:
lib.mirrorFunctionArgs f (
args:
if !(lib.isFunction args) && (args ? stdenv) then
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511) ''
Passing `stdenv` directly to `buildPythonPackage` or `buildPythonApplication` is deprecated. You should use their `.override` function instead, e.g:
buildPythonPackage.override { stdenv = customStdenv; } { }
'' (f.override { inherit (args) stdenv; } (removeAttrs args [ "stdenv" ]))
else
f args
)
// {
# Intentionally drop the effect of overrideStdenvCompat when calling `buildPython*.override`.
inherit (f) override;
};
lib.fix (
f':
lib.mirrorFunctionArgs f (
args:
if !(lib.isFunction args) && (args ? stdenv) then
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511) ''
Passing `stdenv` directly to `buildPythonPackage` or `buildPythonApplication` is deprecated. You should use their `.override` function instead, e.g:
buildPythonPackage.override { stdenv = customStdenv; } { }
'' (f'.override { inherit (args) stdenv; } (removeAttrs args [ "stdenv" ]))
else
f args
)
// {
# Preserve the effect of overrideStdenvCompat when calling `buildPython*.override`.
override = lib.mirrorFunctionArgs f.override (newArgs: overrideStdenvCompat (f.override newArgs));
}
);
mkPythonDerivation =
if python.isPy3k then ./mk-python-derivation.nix else ./python2/mk-python-derivation.nix;