Unverified Commit e6959ad5 authored by Matt Sturgeon's avatar Matt Sturgeon Committed by GitHub
Browse files

buildPython*: extend overrideStdenvCompat to fixed-point arguments (#477208)

parents 9e83fef8 de48b6a8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -418,6 +418,7 @@ lib.extendMkDerivation {
          optional-dependencies
          ;
        updateScript = nix-update-script { };
        ${if attrs ? stdenv then "__stdenvPythonCompat" else null} = attrs.stdenv;
      }
      // attrs.passthru or { };

+21 −8
Original line number Diff line number Diff line
@@ -53,15 +53,28 @@ let
      f':
      lib.mirrorFunctionArgs f (
        args:
        if !(lib.isFunction args) && (args ? stdenv) then
        let
          result = f args;
          getName = x: x.pname or (lib.getName (x.name or "<unnamed>"));
          applyMsgStdenvArg =
            name:
            lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511) ''
            ${
              args.name or args.pname or "<unnamed>"
            }: Passing `stdenv` directly to `buildPythonPackage` or `buildPythonApplication` is deprecated. You should use their `.override` function instead, e.g:
              ${name}: 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" ]))
            '';
        in
        if lib.isFunction args && result ? __stdenvPythonCompat then
          # Less reliable, as constructing with the wrong `stdenv` might lead to evaluation errors in the package definition.
          f'.override { stdenv = applyMsgStdenvArg (getName result) result.__stdenvPythonCompat; } (
            finalAttrs: removeAttrs (args finalAttrs) [ "stdenv" ]
          )
        else if (!lib.isFunction args) && (args ? stdenv) then
          # More reliable, but only works when args is not `(finalAttrs: { })`
          f'.override { stdenv = applyMsgStdenvArg (getName args) args.stdenv; } (
            removeAttrs args [ "stdenv" ]
          )
        else
          f args
          result
      )
      // {
        # Preserve the effect of overrideStdenvCompat when calling `buildPython*.override`.