Extend package calling to allow single pkgs arg or no args

This commit is contained in:
Archit Gupta
2023-04-15 01:26:00 -07:00
parent 2775ef4d94
commit b2721d44d5

View File

@ -4,12 +4,12 @@
nixpkgs: nixpkgs:
let let
inherit (builtins) readDir; inherit (builtins) functionArgs isFunction isList isPath isString readDir;
inherit (nixpkgs.lib) attrNames attrVals composeManyExtensions filter inherit (nixpkgs.lib) attrNames attrVals composeManyExtensions filter
filterAttrs foldAttrs foldl genAttrs hasSuffix isFunction isList listToAttrs filterAttrs foldAttrs foldl genAttrs hasSuffix listToAttrs mapAttrs
mapAttrs mapAttrsToList mapAttrs' mergeAttrs nameValuePair optional mapAttrsToList mapAttrs' mergeAttrs nameValuePair optional optionalAttrs
optionalAttrs optionalString parseDrvName pathExists pipe recursiveUpdate optionalString parseDrvName pathExists pipe recursiveUpdate removeSuffix
removeSuffix zipAttrsWith; zipAttrsWith;
exports = { inherit mkFlake loadNixDir systems; }; exports = { inherit mkFlake loadNixDir systems; };
@ -126,7 +126,17 @@ let
((map (m: normalizeModule (m src inputs root')) ((map (m: normalizeModule (m src inputs root'))
([ baseModule ] ++ modules)) ++ [ root' ]); ([ baseModule ] ++ modules)) ++ [ root' ]);
genPackages = pkgs: mapAttrs (_: v: pkgs.callPackage v { }); callWith = pkgs: x:
let
x' = if (isPath x) || (isString x) then import x else x;
in
if ! isFunction x' then x'
else
if functionArgs x' == { }
then x' pkgs
else pkgs.callPackage x' { };
genPackages = pkgs: mapAttrs (_: callWith pkgs);
pkgsFor = system: import (inputs.nixpkgs or nixpkgs) { pkgsFor = system: import (inputs.nixpkgs or nixpkgs) {
inherit system; inherit system;