Partial way to unifying nixos and home-manager modules

This commit is contained in:
marc
2022-11-16 20:28:32 +01:00
parent 5c609ddd42
commit 882c04a6bf
8 changed files with 121 additions and 66 deletions

View File

@@ -11,6 +11,8 @@ rec {
# (name -> value -> bool)
# (name -> value -> { name = any; value = any; })
# attrs
# Generate an attribute set by mapping a function (f) to it and then filter
# by the predicate (pred)
mapFilterAttrs = pred: f: attrs: filterAttrs pred (mapAttrs' f attrs);
# Generate an attribute set by mapping a function over a list of values.

View File

@@ -6,6 +6,10 @@ let
inherit (self.attrs) mapFilterAttrs;
in
rec {
# Returns an attribute set with the keys being the files in a directory
# and the values a function applied to their paths
# Only *.nix files and directories with a default.nix file are considered.
# The ".nix" suffix is removed from the keys of the attribute set.
mapModules = dir: fn:
mapFilterAttrs
(n: v:
@@ -22,9 +26,14 @@ rec {
else nameValuePair "" null)
(readDir dir);
# Like mapModules above, but it just returns the values
# (map the function fn over the files in a directory)
mapModules' = dir: fn:
attrValues (mapModules dir fn);
# Like mapModules, but recursive. That is, if there is a directory, the
# value will be another attribute set with its contents as keys and the funcion
# applied to them as values.
mapModulesRec = dir: fn:
mapFilterAttrs
(n: v:
@@ -39,6 +48,9 @@ rec {
else nameValuePair "" null)
(readDir dir);
# Like mapModulesRec but flattened and only the values. That is, it returns a list
# with fn applied to all *.nix files within the directory and subdirectories
# excluding default.nix files.
mapModulesRec' = dir: fn:
let
dirs =