summaryrefslogtreecommitdiffstats
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
parentac3b87b9a62929a81d2a275b808681352cc3c10e (diff)
lib.guard: init
-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 bfe8c581c..da936fad6 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; };