add and use lib.collectProfiles

this function collects profiles recursively
This commit is contained in:
Pacman99 2021-04-25 20:53:16 -07:00
parent 60bfb24af1
commit 2cab5b5d2b
4 changed files with 15 additions and 8 deletions

View file

@ -81,7 +81,7 @@
"utils": "utils_2"
},
"locked": {
"narHash": "sha256-IvKVn4U3Ts2aw8JoKvBCte6Z77JynuNob8LClmsopFo=",
"narHash": "sha256-t14TKUtw83dZ2mbqjRpeUvdAx4zpe/ySr5KhPhB1JMU=",
"path": "./lib",
"type": "path"
},

View file

@ -8,13 +8,9 @@ let
inherit (args) users profiles userProfiles;
};
allProfiles =
let defaults = lib.collect (x: x ? default) profiles;
in map (x: x.default) defaults;
allProfiles = lib.collectProfiles profiles;
allUsers =
let defaults = lib.collect (x: x ? default) users;
in map (x: x.default) defaults;
allUsers = lib.collectProfiles users;
createSuites = _: suites: lib.mapAttrs (_: v: os.profileMap v) suites // {
inherit allProfiles allUsers;

View file

@ -50,7 +50,7 @@
pathsToImportedAttrs
concatAttrs
filterPackages;
inherit (lists) pathsIn;
inherit (lists) pathsIn collectProfiles;
inherit (strings) rgxToString;
inherit modules;
}

View file

@ -1,5 +1,16 @@
{ lib }:
{
collectProfiles = set:
let
collectNestedProfiles = set:
lib.mapAttrsToList (n: v:
if builtins.isAttrs v then
[ v.default or null ] ++ collectNestedProfiles v
else null
) set;
in
builtins.filter (x: x != null) (lib.flatten (collectNestedProfiles set));
pathsIn = dir:
let
fullPath = name: "${toString dir}/${name}";