Allow to set priority which are below the default priority level.

This help to define default values which can be override without any extra syntax.

svn path=/nixpkgs/trunk/; revision=16304
This commit is contained in:
Nicolas Pierron 2009-07-10 09:44:09 +00:00
parent c30a867383
commit 5cd8eefb26

View File

@ -670,6 +670,10 @@ rec {
inherit content; inherit content;
}; };
# Sugar to override the default value of the option by making a new
# default value based on the configuration.
mkDefaultValue = content: mkOverride 1000 {} content;
# Make the template traversal in function of the property traversal. If # Make the template traversal in function of the property traversal. If
# the template define a non-empty attribute set, then the property is # the template define a non-empty attribute set, then the property is
# copied only on all mentionned attributes inside the template. # copied only on all mentionned attributes inside the template.
@ -701,7 +705,7 @@ rec {
foldProperty foldProperty
(foldFilter isOverride (foldFilter isOverride
(p@{property, content, ...}: (p@{property, content, ...}:
if lessThan content.priority property.priority then if content ? priority && lessThan content.priority property.priority then
content content
else else
content // { content // {
@ -713,16 +717,24 @@ rec {
value = p // { content = content.value; }; value = p // { content = content.value; };
} }
) )
) (value: { priority = defaultPrio; inherit value; }); ) (value: { inherit value; });
prioValList = map getPrioVal valList; addDefaultPrio = x:
if x ? priority then x
else x // { priority = defaultPrio; };
higherPrio = fold (x: y: prioValList = map (x: addDefaultPrio (getPrioVal x)) valList;
if lessThan x.priority y then
higherPrio =
if prioValList == [] then
defaultPrio
else
fold (x: min:
if lessThan x.priority min then
x.priority x.priority
else else
y min
) defaultPrio prioValList; ) (head prioValList).priority (tail prioValList);
in in
map (x: map (x:
if x.priority == higherPrio then if x.priority == higherPrio then