diff --git a/pkgs/development/interpreters/python/python-packages-base.nix b/pkgs/development/interpreters/python/python-packages-base.nix index 92b0a456b0779..738248a2cf04e 100644 --- a/pkgs/development/interpreters/python/python-packages-base.nix +++ b/pkgs/development/interpreters/python/python-packages-base.nix @@ -16,17 +16,22 @@ let # This function introduces `overridePythonAttrs` and it overrides the call to `buildPythonPackage`. makeOverridablePythonPackage = f: origArgs: let - ff = f origArgs; - overrideWith = newArgs: origArgs // (if pkgs.lib.isFunction newArgs then newArgs origArgs else newArgs); + args = lib.fix (lib.extends + (_: previousAttrs: { + passthru = (previousAttrs.passthru or { }) // { + overridePythonAttrs = newArgs: makeOverridablePythonPackage f (overrideWith newArgs); + }; + }) + (_: origArgs)); + result = f args; + overrideWith = newArgs: args // (if pkgs.lib.isFunction newArgs then newArgs args else newArgs); in - if builtins.isAttrs ff then (ff // { + if builtins.isAttrs result then result + else if builtins.isFunction result then { overridePythonAttrs = newArgs: makeOverridablePythonPackage f (overrideWith newArgs); - }) - else if builtins.isFunction ff then { - overridePythonAttrs = newArgs: makeOverridablePythonPackage f (overrideWith newArgs); - __functor = self: ff; + __functor = self: result; } - else ff; + else result; buildPythonPackage = makeOverridablePythonPackage (lib.makeOverridable (callPackage ./mk-python-derivation.nix { inherit namePrefix; # We want Python libraries to be named like e.g. "python3.6-${name}"