Commit de48b6a8 authored by Yueh-Shun Li's avatar Yueh-Shun Li
Browse files

buildPython*: extend overrideStdenvCompat to fixed-point arguments



with `passthru.__stdenvPythonCompat`

Co-authored-by: default avatarMatt Sturgeon <matt@sturgeon.me.uk>
parent 5b114f05
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 { };

+9 −2
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ let
      lib.mirrorFunctionArgs f (
        args:
        let
          result = f args;
          getName = x: x.pname or (lib.getName (x.name or "<unnamed>"));
          applyMsgStdenvArg =
            name:
@@ -62,12 +63,18 @@ let
                buildPythonPackage.override { stdenv = customStdenv; } { }
            '';
        in
        if !(lib.isFunction args) && (args ? stdenv) then
        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`.