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

View File

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

View File

@ -170,6 +170,12 @@ in
}) })
(f: import f.packages.x86_64-linux.default); (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 package-prevent-recursion = test
(flakelight ./empty { (flakelight ./empty {
package = { hello }: hello; package = { hello }: hello;