Fix: Use the check function defined in the option declaration if it exists.

svn path=/nixpkgs/trunk/; revision=17277
This commit is contained in:
Nicolas Pierron 2009-09-19 16:49:31 +00:00
parent bf4162eb0b
commit 5f138aebde

View File

@ -46,19 +46,21 @@ rec {
apply = lib.id; apply = lib.id;
}; };
mergeFromType = opt: functionsFromType = opt:
if decl ? type && decl.type ? merge then 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 else
opt; opt;
addDeclaration = opt: opt // decl; addDeclaration = opt: opt // decl;
ensureMergeInputType = opt: ensureMergeInputType = opt:
if decl ? type then if opt ? check then
opt // { opt // {
merge = list: merge = list:
if all decl.type.check list then if all opt.check list then
opt.merge list opt.merge list
else else
throw "One of the definitions has a bad type."; throw "One of the definitions has a bad type.";
@ -66,18 +68,18 @@ rec {
else opt; else opt;
ensureDefaultType = opt: ensureDefaultType = opt:
if decl ? type && decl ? default then if opt ? check && opt ? default then
opt // { opt // {
default = default =
if decl.type.check decl.default then if opt.check opt.default then
decl.default opt.default
else else
throw "The default value has a bad type."; throw "The default value has a bad type.";
} }
else opt; else opt;
handleOptionSets = opt: handleOptionSets = opt:
if decl ? type && decl.type.hasOptions then if opt ? type && opt.type.hasOptions then
let let
optionConfig = opts: config: optionConfig = opts: config:
@ -86,7 +88,7 @@ rec {
in in
opt // { opt // {
merge = list: merge = list:
decl.type.iter opt.type.iter
(path: opts: (path: opts:
(lib.fix (lib.fix
(fixableMergeFun (recurseInto path) (optionConfig opts)) (fixableMergeFun (recurseInto path) (optionConfig opts))
@ -95,7 +97,7 @@ rec {
opt.name opt.name
(opt.merge list); (opt.merge list);
options = options =
let path = decl.type.docPath opt.name; in let path = opt.type.docPath opt.name; in
(lib.fix (lib.fix
(fixableMergeFun (recurseInto path) (optionConfig [])) (fixableMergeFun (recurseInto path) (optionConfig []))
).options; ).options;
@ -105,7 +107,7 @@ rec {
in in
foldl (opt: f: f opt) init [ foldl (opt: f: f opt) init [
# default settings # default settings
mergeFromType functionsFromType
# user settings # user settings
addDeclaration addDeclaration