Fix: Use the check function defined in the option declaration if it exists.
svn path=/nixpkgs/trunk/; revision=17277
This commit is contained in:
parent
bf4162eb0b
commit
5f138aebde
1 changed files with 13 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue