summaryrefslogtreecommitdiffstats
path: root/krebs/4lib
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2016-06-13 01:12:10 +0200
committertv <tv@krebsco.de>2016-06-13 01:16:21 +0200
commit3c61d227cf189967071501fa73b27697fc2d63a5 (patch)
treed086b806d06cf943bdb51cf37f2f2b0b4a8f64db /krebs/4lib
parentac3b87b9a62929a81d2a275b808681352cc3c10e (diff)
lib.guard: init
Diffstat (limited to 'krebs/4lib')
-rw-r--r--krebs/4lib/default.nix10
1 files changed, 10 insertions, 0 deletions
diff --git a/krebs/4lib/default.nix b/krebs/4lib/default.nix
index bfe8c581..da936fad 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; };