mirror of
https://github.com/nix-community/flakelight.git
synced 2024-11-21 23:13:09 +01:00
Support package functions without named args
This commit is contained in:
parent
a90223da37
commit
787ce03070
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user