1
1
forked from extern/flakelight

Support package functions without named args

This commit is contained in:
Archit Gupta 2024-01-16 11:01:32 -08:00
parent a90223da37
commit 787ce03070
3 changed files with 12 additions and 3 deletions

View File

@ -13,8 +13,11 @@ let
genPkg = final: prev: name: pkg:
let
args = functionArgs pkg;
noArgs = args == { };
pkg' = if noArgs then { pkgs }: pkg pkgs else pkg;
dependsOnSelf = hasAttr name (functionArgs pkg);
dependsOnPkgs = (functionArgs pkg) ? pkgs;
dependsOnPkgs = noArgs || (args ? pkgs);
selfOverride = {
${name} = prev.${name} or
(throw "${name} depends on ${name}, but no existing ${name}.");
@ -22,7 +25,7 @@ let
overrides = optionalAttrs dependsOnSelf selfOverride
// optionalAttrs dependsOnPkgs { pkgs = final.pkgs // selfOverride; };
in
final.callPackage pkg overrides;
final.callPackage pkg' overrides;
genPkgs = final: prev: pkgs:
mapAttrs (name: genPkg final prev name) pkgs;
in

View File

@ -14,6 +14,7 @@ let
fargs = lib.functionArgs f;
mock = lib.mapAttrs (_: _: throw "") (lib.filterAttrs (_: v: !v) fargs);
in
assert fargs != { };
f (mock // builtins.intersectAttrs fargs autoArgs // args);
mockStdenv = real: stdenv: real.${stdenv} or (throw "") // {
@ -22,7 +23,6 @@ let
};
in
lib.fix (self: {
pkgs = self;
lib = lib // { inherit callPackageWith; };
callPackage = callPackageWith self;

View File

@ -170,6 +170,12 @@ in
})
(f: import f.packages.x86_64-linux.default);
package-no-named-args = test
(flakelight ./empty {
package = pkgs: pkgs.hello;
})
(f: f.packages.aarch64-linux.default.pname == "hello");
package-prevent-recursion = test
(flakelight ./empty {
package = { hello }: hello;