haskellPackages.callPackage: preserve functionArgs (#443442)

This commit is contained in:
sternenseemann
2025-09-22 11:26:13 +00:00
committed by GitHub

View File

@@ -107,29 +107,35 @@ let
# is that nix has no way to "passthrough" args while preserving the reflection # is that nix has no way to "passthrough" args while preserving the reflection
# info that callPackage uses to determine the arguments). # info that callPackage uses to determine the arguments).
drv = if lib.isFunction fn then fn else import fn; drv = if lib.isFunction fn then fn else import fn;
auto = builtins.intersectAttrs (lib.functionArgs drv) scope; drvFunctionArgs = lib.functionArgs drv;
auto = builtins.intersectAttrs drvFunctionArgs scope;
# Converts a returned function to a functor attribute set if necessary # Converts a returned function to a functor attribute set if necessary
ensureAttrs = v: if builtins.isFunction v then { __functor = _: v; } else v; ensureAttrs = v: if builtins.isFunction v then { __functor = _: v; } else v;
# this wraps the `drv` function to add `scope` and `overrideScope` to the result. # this wraps the `drv` function to add `scope` and `overrideScope` to the result.
drvScope = # it's a functor, so that we can pass through `functionArgs`
allArgs: drvScope = {
ensureAttrs (drv allArgs) __functor =
// { _: allArgs:
inherit scope; ensureAttrs (drv allArgs)
overrideScope = // {
f: inherit scope;
let overrideScope =
newScope = mkScope (fix' (extends f scope.__unfix__)); f:
in let
# note that we have to be careful here: `allArgs` includes the auto-arguments that newScope = mkScope (fix' (extends f scope.__unfix__));
# weren't manually specified. If we would just pass `allArgs` to the recursive call here, in
# then we wouldn't look up any packages in the scope in the next interation, because it # note that we have to be careful here: `allArgs` includes the auto-arguments that
# appears as if all arguments were already manually passed, so the scope change would do # weren't manually specified. If we would just pass `allArgs` to the recursive call here,
# nothing. # then we wouldn't look up any packages in the scope in the next interation, because it
callPackageWithScope newScope drv manualArgs; # appears as if all arguments were already manually passed, so the scope change would do
}; # nothing.
callPackageWithScope newScope drv manualArgs;
};
# `drvScope` accepts the same arguments as `drv`
__functionArgs = drvFunctionArgs;
};
in in
lib.makeOverridable drvScope (auto // manualArgs); lib.makeOverridable drvScope (auto // manualArgs);