Only allow properties with a onGlobalEval function to go through specific

types.

svn path=/nixpkgs/trunk/; revision=17756
This commit is contained in:
Nicolas Pierron 2009-10-12 13:37:00 +00:00
parent c6efc69ad2
commit 03eab95618
3 changed files with 16 additions and 9 deletions

View file

@ -118,8 +118,9 @@ rec {
moduleApply { config = delayProperties; } module;
evalDefinitions = opt: values:
if opt ? type && opt.type.delayProperties then
map (delayPropertiesWithIter opt.type.iter opt.name) values
if opt ? type && opt.type.delayOnGlobalEval then
map (delayPropertiesWithIter opt.type.iter opt.name)
(evalLocalProperties values)
else
evalProperties values;

View file

@ -124,13 +124,19 @@ rec {
evalProperties = valList:
if valList != [] then
filter (x: !isNotdef x) (
lib.addErrorContext "while evaluating properties an attribute." (
lib.addErrorContext "while evaluating properties." (
triggerPropertiesGlobalEval (
map triggerPropertiesEval valList
)))
else
valList;
evalLocalProperties = valList:
filter (x: !isNotdef x) (
lib.addErrorContext "while evaluating local properties." (
map triggerPropertiesEval valList
));
# Call onEval function
triggerPropertiesEval = val:
foldProperty (p@{property, ...}:

View file

@ -19,7 +19,7 @@ rec {
# iter (iterate on all elements contained in this type)
# fold (fold all elements contained in this type)
# hasOptions (boolean: whatever this option contains an option set)
# delayProperties (boolean: should properties go through the evaluation of this option)
# delayOnGlobalEval (boolean: should properties go through the evaluation of this option)
# docPath (path concatenated to the option name contained in the option set)
isOptionType = attrs: typeOf attrs == "option-type";
mkOptionType =
@ -32,11 +32,11 @@ rec {
, docPath ? lib.id
# If the type can contains option sets.
, hasOptions ? false
, delayProperties ? false
, delayOnGlobalEval ? false
}:
{ _type = "option-type";
inherit name check merge iter fold docPath hasOptions delayProperties;
inherit name check merge iter fold docPath hasOptions delayOnGlobalEval;
};
@ -87,7 +87,7 @@ rec {
# You cannot define multiple configurations of one entity, therefore
# no reason justify to delay properties inside list elements.
delayProperties = false;
delayOnGlobalEval = false;
};
attrsOf = elemType: mkOptionType {
@ -98,7 +98,7 @@ rec {
iter = f: path: set: lib.mapAttrs (name: elemType.iter f (path + "." + name)) set;
fold = op: nul: set: fold (e: l: elemType.fold op l e) nul (lib.attrValues set);
docPath = path: elemType.docPath (path + ".<name>");
inherit (elemType) hasOptions delayProperties;
inherit (elemType) hasOptions delayOnGlobalEval;
};
uniq = elemType: mkOptionType {
@ -125,7 +125,7 @@ rec {
merge = lib.id;
check = x: lib.traceValIfNot builtins.isAttrs x;
hasOptions = true;
delayProperties = true;
delayOnGlobalEval = true;
};
};