mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-01 17:53:14 +00:00
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:
parent
f662c8be61
commit
baaf9459d6
@ -87,8 +87,11 @@ let
|
|||||||
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;
|
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.
|
# this wraps the `drv` function to add a `overrideScope` function to the result.
|
||||||
drvScope = allArgs: drv allArgs // {
|
drvScope = allArgs: ensureAttrs (drv allArgs) // {
|
||||||
overrideScope = f:
|
overrideScope = f:
|
||||||
let newScope = mkScope (fix' (extends f scope.__unfix__));
|
let newScope = mkScope (fix' (extends f scope.__unfix__));
|
||||||
# note that we have to be careful here: `allArgs` includes the auto-arguments that
|
# note that we have to be careful here: `allArgs` includes the auto-arguments that
|
||||||
|
Loading…
Reference in New Issue
Block a user