forked from DGNum/infrastructure
lib: Init
This commit is contained in:
parent
3e052803ca
commit
b3d2cd6071
2 changed files with 59 additions and 0 deletions
20
lib/default.nix
Normal file
20
lib/default.nix
Normal file
|
@ -0,0 +1,20 @@
|
|||
{ lib, ... }:
|
||||
|
||||
let
|
||||
trivial = import ./trivial.nix;
|
||||
in
|
||||
|
||||
trivial // (with trivial; rec {
|
||||
mkImport = root: file:
|
||||
let path = mkRel root file; in
|
||||
path + (lib.optionalString (!lib.pathIsDirectory path) ".nix");
|
||||
|
||||
mkImports = root: builtins.map (mkImport root);
|
||||
|
||||
getKeys = name: builtins.filter (k: k != "") (lib.splitString "\n" (builtins.readFile (../keys + "/${name}.keys")));
|
||||
|
||||
/* List version of getKeys */
|
||||
getAllKeys = names: builtins.concatLists (builtins.map getKeys names);
|
||||
|
||||
getKeyFiles = builtins.map (compose (n: "${n}.keys") (mkRel ../keys));
|
||||
})
|
39
lib/trivial.nix
Normal file
39
lib/trivial.nix
Normal file
|
@ -0,0 +1,39 @@
|
|||
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; };
|
||||
|
||||
mapSingleFuse = f: mapFuse (x: singleAttr x (f x));
|
||||
|
||||
/* Creates a relative path as a string
|
||||
|
||||
Example:
|
||||
mkRel /home/test/ "file.txt"
|
||||
=> "/home/test/file.txt"
|
||||
*/
|
||||
mkRel = path: file: builtins.toString (path + "/${file}");
|
||||
|
||||
compose = f: g: (x: g (f x));
|
||||
}
|
Loading…
Reference in a new issue