forked from mirrors/nixpkgs
Add support for a new module syntax.
Introduce optional argument to optionSet options. svn path=/nixpkgs/trunk/; revision=15935
This commit is contained in:
parent
2b68672d1c
commit
b32002c3a3
|
@ -70,14 +70,21 @@ rec {
|
||||||
|
|
||||||
handleOptionSets = opt:
|
handleOptionSets = opt:
|
||||||
if decl ? type && decl.type.hasOptions then
|
if decl ? type && decl.type.hasOptions then
|
||||||
opt // {
|
let
|
||||||
merge = list:
|
optionConfig = opts: config:
|
||||||
decl.type.iter
|
map (f: applyIfFunction f config)
|
||||||
(path: opts: recurseInto path (decl.options ++ [opts]))
|
(decl.options ++ [opts]);
|
||||||
opt.name
|
in
|
||||||
(opt.merge list);
|
opt // {
|
||||||
options = recurseInto (decl.type.docPath opt.name) decl.options;
|
merge = list:
|
||||||
}
|
decl.type.iter
|
||||||
|
(path: opts:
|
||||||
|
fixMergeFun (recurseInto path) (optionConfig opts)
|
||||||
|
)
|
||||||
|
opt.name
|
||||||
|
(opt.merge list);
|
||||||
|
options = recurseInto (decl.type.docPath opt.name) decl.options;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
opt;
|
opt;
|
||||||
in
|
in
|
||||||
|
@ -361,6 +368,56 @@ rec {
|
||||||
|| builtins.isList x
|
|| builtins.isList x
|
||||||
);
|
);
|
||||||
|
|
||||||
|
applyIfFunction = f: arg:
|
||||||
|
if builtins.isFunction f then
|
||||||
|
f arg
|
||||||
|
else
|
||||||
|
f;
|
||||||
|
|
||||||
|
moduleClosure = initModules: args:
|
||||||
|
let
|
||||||
|
moduleImport = path:
|
||||||
|
(applyIfFunction (import path) args) // {
|
||||||
|
# used by generic closure to avoid duplicated imports.
|
||||||
|
key = path;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
builtins.genericClosure {
|
||||||
|
startSet = map moduleImport initModules;
|
||||||
|
operator = m:
|
||||||
|
map moduleImport (attrByPath ["imports"] [] m);
|
||||||
|
};
|
||||||
|
|
||||||
|
selectDeclsAndDefs = modules:
|
||||||
|
lib.concatMap (m:
|
||||||
|
attrByPath ["options"] [] m
|
||||||
|
++ attrByPath ["config"] [] m
|
||||||
|
) modules;
|
||||||
|
|
||||||
|
fixMergeFun = merge: optFun:
|
||||||
|
lib.fix (config:
|
||||||
|
merge (
|
||||||
|
# Delay top-level properties like mkIf
|
||||||
|
map delayProperties (
|
||||||
|
# generate the list of option sets.
|
||||||
|
optFun config
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
fixMergeModules = merge: initModules: {...}@args:
|
||||||
|
fixMergeFun (config:
|
||||||
|
selectDeclsAndDefs (
|
||||||
|
moduleClosure initModules (args // { inherit config; })
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
fixModulesConfig = initModules: {...}@args:
|
||||||
|
fixMergeModules (mergeOptionSets "") initModules args;
|
||||||
|
|
||||||
|
fixOptionsConfig = initModules: {...}@args:
|
||||||
|
fixMergeModules (filterOptionSets "") initModules args;
|
||||||
|
|
||||||
|
|
||||||
# Evaluate a list of option sets that would be merged with the
|
# Evaluate a list of option sets that would be merged with the
|
||||||
# function "merge" which expects two arguments. The attribute named
|
# function "merge" which expects two arguments. The attribute named
|
||||||
|
|
Loading…
Reference in a new issue