summaryrefslogtreecommitdiffstats
path: root/krebs/4lib/default.nix
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2016-06-14 01:36:15 +0200
committermakefu <github@syntax-fehler.de>2016-06-14 01:36:15 +0200
commiteb710a17e28bbec2a4f7877533f101fa78ece209 (patch)
tree591878b08c6d051418928e7dd94bd0d21853157f /krebs/4lib/default.nix
parent618684954207feed26b1b85f0721d41d5ca4c5c3 (diff)
parent5bc3fa88543cdf3aa5b9103f7423a2af490b3d08 (diff)
Merge remote-tracking branch 'cd/master'
Diffstat (limited to 'krebs/4lib/default.nix')
-rw-r--r--krebs/4lib/default.nix17
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;