From 3c61d227cf189967071501fa73b27697fc2d63a5 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 13 Jun 2016 01:12:10 +0200 Subject: lib.guard: init --- krebs/4lib/default.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'krebs/4lib') 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; }; -- cgit v1.2.3