diff options
Diffstat (limited to 'krebs/4lib/default.nix')
-rw-r--r-- | krebs/4lib/default.nix | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/krebs/4lib/default.nix b/krebs/4lib/default.nix index bfe8c581c..afff17296 100644 --- a/krebs/4lib/default.nix +++ b/krebs/4lib/default.nix @@ -15,6 +15,16 @@ let out = rec { addNames = mapAttrs addName; + guard = spec@{ type, value, ... }: + assert isOptionType type; + if type.check value + then value + else throw (toString (filter isString [ + "argument" + (if spec ? name then "‘${spec.name}’" else null) + "is not a ${type.name}" + ])); + types = import ./types.nix { inherit config; lib = lib // { inherit genid optionalTrace; }; @@ -27,6 +37,11 @@ let out = rec { shell = import ./shell.nix { inherit lib; }; tree = import ./tree.nix { inherit lib; }; + lpad = n: c: s: + if stringLength s < n + then lpad n c (c + s) + else s; + toC = x: let type = typeOf x; reject = throw "cannot convert ${type}"; @@ -41,6 +56,8 @@ let out = rec { mapAttrs (name: _: path + "/${name}") (filterAttrs (_: eq "directory") (readDir path)); + genAttrs' = names: f: listToAttrs (map f names); + setAttr = name: value: set: set // { ${name} = value; }; optionalTrace = c: msg: x: if c then trace msg x else x; |