haskellPackages.callPackage: support returning functions

Overrideable functions are possible by wrapping them as functors in an
attribute set first and appending the overrideScope and override
attributes later.
This commit is contained in:
sternenseemann 2021-11-20 16:31:02 +01:00 committed by sterni
parent f662c8be61
commit baaf9459d6

View file

@ -87,8 +87,11 @@ let
drv = if lib.isFunction fn then fn else import fn;
auto = builtins.intersectAttrs (lib.functionArgs drv) scope;
# Converts a returned function to a functor attribute set if necessary
ensureAttrs = v: if builtins.isFunction v then { __functor = _: v; } else v;
# this wraps the `drv` function to add a `overrideScope` function to the result.
drvScope = allArgs: drv allArgs // {
drvScope = allArgs: ensureAttrs (drv allArgs) // {
overrideScope = f:
let newScope = mkScope (fix' (extends f scope.__unfix__));
# note that we have to be careful here: `allArgs` includes the auto-arguments that