about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorNicolas Pierron <nicolas.b.pierron@gmail.com>2009-07-10 09:44:09 +0000
committerNicolas Pierron <nicolas.b.pierron@gmail.com>2009-07-10 09:44:09 +0000
commit5cd8eefb26c28e52c3a534c599509e0269a5713c (patch)
tree5f28392da4b0bd0c02897123b1d517cec6ba08bb /pkgs
parentc30a86738312fe20d78c3cfe532ebb99db31bd90 (diff)
downloadnixlib-5cd8eefb26c28e52c3a534c599509e0269a5713c.tar
nixlib-5cd8eefb26c28e52c3a534c599509e0269a5713c.tar.gz
nixlib-5cd8eefb26c28e52c3a534c599509e0269a5713c.tar.bz2
nixlib-5cd8eefb26c28e52c3a534c599509e0269a5713c.tar.lz
nixlib-5cd8eefb26c28e52c3a534c599509e0269a5713c.tar.xz
nixlib-5cd8eefb26c28e52c3a534c599509e0269a5713c.tar.zst
nixlib-5cd8eefb26c28e52c3a534c599509e0269a5713c.zip
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
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/lib/options.nix28
1 files changed, 20 insertions, 8 deletions
diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix
index ca0f3dbe9faf..f674b399415b 100644
--- a/pkgs/lib/options.nix
+++ b/pkgs/lib/options.nix
@@ -670,6 +670,10 @@ rec {
     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
   # the template define a non-empty attribute set, then the property is
   # copied only on all mentionned attributes inside the template.
@@ -701,7 +705,7 @@ rec {
         foldProperty
           (foldFilter isOverride
             (p@{property, content, ...}:
-              if lessThan content.priority property.priority then
+              if content ? priority && lessThan content.priority property.priority then
                 content
               else
                 content // {
@@ -713,16 +717,24 @@ rec {
                 value = p // { content = content.value; };
               }
             )
-          ) (value: { priority = defaultPrio; inherit value; });
+          ) (value: { inherit value; });
+
+      addDefaultPrio = x:
+        if x ? priority then x
+        else x // { priority = defaultPrio; };
 
-      prioValList = map getPrioVal valList;
+      prioValList = map (x: addDefaultPrio (getPrioVal x)) valList;
 
-      higherPrio = fold (x: y:
-        if lessThan x.priority y then
-          x.priority
+      higherPrio =
+        if prioValList == [] then
+          defaultPrio
         else
-          y
-      ) defaultPrio prioValList;
+          fold (x: min:
+            if lessThan x.priority min then
+              x.priority
+            else
+              min
+          ) (head prioValList).priority (tail prioValList);
     in
       map (x:
         if x.priority == higherPrio then