forked from DGNum/infrastructure
lib: Add utility functions
This commit is contained in:
parent
e64c32bf34
commit
c06fe743b0
2 changed files with 18 additions and 0 deletions
|
@ -5,6 +5,8 @@ let
|
||||||
in
|
in
|
||||||
|
|
||||||
trivial // (with trivial; rec {
|
trivial // (with trivial; rec {
|
||||||
|
recursiveFuse = builtins.foldl' lib.recursiveUpdate { };
|
||||||
|
|
||||||
mkImport = root: file:
|
mkImport = root: file:
|
||||||
let path = mkRel root file; in
|
let path = mkRel root file; in
|
||||||
path + (lib.optionalString (!lib.pathIsDirectory path) ".nix");
|
path + (lib.optionalString (!lib.pathIsDirectory path) ".nix");
|
||||||
|
@ -19,4 +21,14 @@ trivial // (with trivial; rec {
|
||||||
getAllKeys = names: builtins.concatLists (builtins.map getKeys names);
|
getAllKeys = names: builtins.concatLists (builtins.map getKeys names);
|
||||||
|
|
||||||
getKeyFiles = builtins.map (compose (n: "${n}.keys") (mkRel ../keys));
|
getKeyFiles = builtins.map (compose (n: "${n}.keys") (mkRel ../keys));
|
||||||
|
|
||||||
|
getNodeKeys = node:
|
||||||
|
let
|
||||||
|
meta = import ../meta;
|
||||||
|
names = builtins.foldl'
|
||||||
|
(names: group: names ++ meta.members.groups.${group})
|
||||||
|
(meta.nodes.${node}.admins ++ [ "/machines/${node}" ])
|
||||||
|
(meta.nodes.${node}.adminGroups ++ [ "root" ]);
|
||||||
|
in
|
||||||
|
getAllKeys names;
|
||||||
})
|
})
|
||||||
|
|
|
@ -27,6 +27,8 @@ rec {
|
||||||
|
|
||||||
mapSingleFuse = f: mapFuse (x: singleAttr x (f x));
|
mapSingleFuse = f: mapFuse (x: singleAttr x (f x));
|
||||||
|
|
||||||
|
setDefault = default: mapFuse (name: { ${name} = default; });
|
||||||
|
|
||||||
/* Creates a relative path as a string
|
/* Creates a relative path as a string
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
@ -36,4 +38,8 @@ rec {
|
||||||
mkRel = path: file: path + "/${file}";
|
mkRel = path: file: path + "/${file}";
|
||||||
|
|
||||||
compose = f: g: (x: g (f x));
|
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"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue