diff options
author | lassulus <lass@aidsballs.de> | 2016-06-13 13:50:52 +0200 |
---|---|---|
committer | lassulus <lass@aidsballs.de> | 2016-06-13 13:50:52 +0200 |
commit | 23385c2984c9d4fbff65c920d9d59bc29314a639 (patch) | |
tree | d7e4f635be78922359b21970f6a6c8731995e38d /krebs/4lib/default.nix | |
parent | de43b0e6f50e4d044cc0609a3d7d7c7d869552fe (diff) | |
parent | 2dd4dbbf6ea77972c7d5edb0ec25b8e778bfeb50 (diff) |
Merge remote-tracking branch 'cd/master'
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; |