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; moduleApply { config = delayProperties; } module;
evalDefinitions = opt: values: evalDefinitions = opt: values:
if opt ? type && opt.type.delayProperties then if opt ? type && opt.type.delayOnGlobalEval then
map (delayPropertiesWithIter opt.type.iter opt.name) values map (delayPropertiesWithIter opt.type.iter opt.name)
(evalLocalProperties values)
else else
evalProperties values; evalProperties values;

View File

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

View File

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