From 5f138aebde2269eeee123dcc0a789dbee792281a Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sat, 19 Sep 2009 16:49:31 +0000 Subject: [PATCH] Fix: Use the check function defined in the option declaration if it exists. svn path=/nixpkgs/trunk/; revision=17277 --- pkgs/lib/options.nix | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix index 06d4fad8a325..b9ed6e2ec6c6 100644 --- a/pkgs/lib/options.nix +++ b/pkgs/lib/options.nix @@ -46,19 +46,21 @@ rec { apply = lib.id; }; - mergeFromType = opt: + functionsFromType = opt: if decl ? type && decl.type ? merge then - opt // { merge = decl.type.merge; } + opt + // optionalAttrs (decl.type ? merge) { inherit (decl.type) merge; } + // optionalAttrs (decl.type ? check) { inherit (decl.type) check; } else opt; addDeclaration = opt: opt // decl; ensureMergeInputType = opt: - if decl ? type then + if opt ? check then opt // { merge = list: - if all decl.type.check list then + if all opt.check list then opt.merge list else throw "One of the definitions has a bad type."; @@ -66,18 +68,18 @@ rec { else opt; ensureDefaultType = opt: - if decl ? type && decl ? default then + if opt ? check && opt ? default then opt // { default = - if decl.type.check decl.default then - decl.default + if opt.check opt.default then + opt.default else throw "The default value has a bad type."; } else opt; handleOptionSets = opt: - if decl ? type && decl.type.hasOptions then + if opt ? type && opt.type.hasOptions then let optionConfig = opts: config: @@ -86,7 +88,7 @@ rec { in opt // { merge = list: - decl.type.iter + opt.type.iter (path: opts: (lib.fix (fixableMergeFun (recurseInto path) (optionConfig opts)) @@ -95,7 +97,7 @@ rec { opt.name (opt.merge list); options = - let path = decl.type.docPath opt.name; in + let path = opt.type.docPath opt.name; in (lib.fix (fixableMergeFun (recurseInto path) (optionConfig [])) ).options; @@ -105,7 +107,7 @@ rec { in foldl (opt: f: f opt) init [ # default settings - mergeFromType + functionsFromType # user settings addDeclaration