Merge pull request #265 from Pacman99/collect-profiles

collect profiles recursively with lib function
This commit is contained in:
Pacman99 2021-04-26 09:58:57 -07:00 committed by GitHub
commit c0d6453b08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 8 deletions

View file

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

View file

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

View file

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

View file

@ -1,5 +1,16 @@
{ lib }: { 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: pathsIn = dir:
let let
fullPath = name: "${toString dir}/${name}"; fullPath = name: "${toString dir}/${name}";