forked from DGNum/infrastructure
50 lines
1.3 KiB
Nix
50 lines
1.3 KiB
Nix
rec {
|
|
/* Fuses a list of attribute sets into a single attribute set.
|
|
|
|
Example:
|
|
x = [ { a = 1; } { b = 2; } ]
|
|
fuseAttrs x
|
|
=> { a = 1; b = 2; }
|
|
*/
|
|
fuseAttrs = builtins.foldl' (attrs: x: attrs // x) { };
|
|
|
|
/* Maps then fuses a list of attribute sets into a single attribute set.
|
|
|
|
Example:
|
|
x = [ "a" "b" ]
|
|
mapFuse (c: { ${c} = 42; }) x
|
|
=> { a = 42; b = 42; }
|
|
*/
|
|
mapFuse = f: attrsList: fuseAttrs (builtins.map f attrsList);
|
|
|
|
/* Equivalent of lib.singleton but for an attribute set.
|
|
|
|
Example:
|
|
singleAttr "a" 1
|
|
=> { a = 1; }
|
|
*/
|
|
singleAttr = name: value: { ${name} = value; };
|
|
|
|
/* Enables a list of modules. */
|
|
enableAttrs' = enable: mapFuse (m: { ${m}.${enable} = true; });
|
|
|
|
enableModules = enableAttrs' "enable";
|
|
|
|
mapSingleFuse = f: mapFuse (x: singleAttr x (f x));
|
|
|
|
setDefault = default: mapFuse (name: { ${name} = default; });
|
|
|
|
/* Creates a relative path as a string
|
|
|
|
Example:
|
|
mkRel /home/test/ "file.txt"
|
|
=> "/home/test/file.txt"
|
|
*/
|
|
mkRel = path: file: path + "/${file}";
|
|
|
|
compose = f: g: (x: g (f x));
|
|
|
|
mkBaseSecrets = root: mapFuse (secret: { ${secret}.file = mkRel root secret; });
|
|
|
|
getSecrets = dir: builtins.attrNames (import (mkRel dir "secrets.nix"));
|
|
}
|