summary refs log tree commit diff
path: root/pkgs/lib
diff options
context:
space:
mode:
authorNicolas Pierron <nicolas.b.pierron@gmail.com>2009-10-09 23:03:24 +0000
committerNicolas Pierron <nicolas.b.pierron@gmail.com>2009-10-09 23:03:24 +0000
commit926f20a1eecab8e40e669018819c43503ff4e4c0 (patch)
tree8e66904f467ddece46d414c80ef372acdaf96df7 /pkgs/lib
parent037a777b7d29d7c748b3cb3746ad67f31763e339 (diff)
downloadnixpkgs-926f20a1eecab8e40e669018819c43503ff4e4c0.tar
nixpkgs-926f20a1eecab8e40e669018819c43503ff4e4c0.tar.gz
nixpkgs-926f20a1eecab8e40e669018819c43503ff4e4c0.tar.bz2
nixpkgs-926f20a1eecab8e40e669018819c43503ff4e4c0.tar.lz
nixpkgs-926f20a1eecab8e40e669018819c43503ff4e4c0.tar.xz
nixpkgs-926f20a1eecab8e40e669018819c43503ff4e4c0.tar.zst
nixpkgs-926f20a1eecab8e40e669018819c43503ff4e4c0.zip
Revert "* Revert the last two commits ..." (rev 17738) & Fix.
svn path=/nixpkgs/trunk/; revision=17740
Diffstat (limited to 'pkgs/lib')
-rw-r--r--pkgs/lib/modules.nix10
-rw-r--r--pkgs/lib/properties.nix15
-rw-r--r--pkgs/lib/types.nix14
3 files changed, 31 insertions, 8 deletions
diff --git a/pkgs/lib/modules.nix b/pkgs/lib/modules.nix
index aeabf640cc2..6626812076e 100644
--- a/pkgs/lib/modules.nix
+++ b/pkgs/lib/modules.nix
@@ -113,9 +113,17 @@ rec {
         value
     ) module;
 
+
   delayModule = module:
     moduleApply { config = delayProperties; } module;
 
+  evalDefinitions = opt: values:
+    if opt ? type && opt.type.delayProperties then
+      map (delayPropertiesWithIter opt.type.iter opt.name) values
+    else
+      evalProperties values;
+
+
   selectModule = name: m:
     { inherit (m) key;
     } // (
@@ -243,7 +251,7 @@ rec {
                   opt.extraConfigs;
 
             in if hasOpt && isOption opt then
-              let defs = evalProperties values; in
+              let defs = evalDefinitions opt values; in
               lib.addErrorContext "${eol
                 }while evaluating the option '${addName name}'.${eol
                 }${errorSource (modulesOf name)}${eol
diff --git a/pkgs/lib/properties.nix b/pkgs/lib/properties.nix
index f523e6067b7..ddf3d6cf594 100644
--- a/pkgs/lib/properties.nix
+++ b/pkgs/lib/properties.nix
@@ -69,18 +69,21 @@ rec {
   # Move properties from the current attribute set to the attribute
   # contained in this attribute set.  This trigger property handlers called
   # `onDelay' and `onGlobalDelay'.
-  delayProperties = attrs:
+  delayPropertiesWithIter = iter: path: attrs:
     let cleanAttrs = rmProperties attrs; in
     if isProperty attrs then
-      lib.mapAttrs (a: v:
+      iter (a: v:
         lib.addErrorContext "while moving properties on the attribute `${a}'." (
           triggerPropertiesGlobalDelay a (
             triggerPropertiesDelay a (
               copyProperties attrs v
-      )))) cleanAttrs
+      )))) path cleanAttrs
     else
       attrs;
 
+  delayProperties = # implicit attrs argument.
+    delayPropertiesWithIter (f: p: v: lib.mapAttrs f v) "";
+
   # Call onDelay functions.
   triggerPropertiesDelay = name: attrs:
     let
@@ -285,7 +288,7 @@ rec {
   # priorities are kept.  The template argument must reproduce the same
   # attribute set hierarchy to override leaves of the hierarchy.
   isOverride = attrs: (typeOf attrs) == "override";
-  mkOverride = priority: template: content: mkProperty {
+  mkOverrideTemplate = priority: template: content: mkProperty {
     property = {
       _type = "override";
       onDelay = onOverrideDelay;
@@ -295,6 +298,10 @@ rec {
     inherit content;
   };
 
+  # Currently an alias, but sooner or later the template argument should be
+  # removed.
+  mkOverride = mkOverrideTemplate;
+
   # Sugar to override the default value of the option by making a new
   # default value based on the configuration.
   mkDefaultValue = content: mkOverride 1000 {} content;
diff --git a/pkgs/lib/types.nix b/pkgs/lib/types.nix
index 5e0393e9604..723dd22e2f0 100644
--- a/pkgs/lib/types.nix
+++ b/pkgs/lib/types.nix
@@ -19,7 +19,8 @@ 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)
-  # path (path contatenated to the option name contained contained in the option set)
+  # delayProperties (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 =
     { name
@@ -31,10 +32,11 @@ rec {
     , docPath ? lib.id
     # If the type can contains option sets.
     , hasOptions ? false
+    , delayProperties ? false
     }:
 
     { _type = "option-type";
-      inherit name check merge iter fold docPath hasOptions;
+      inherit name check merge iter fold docPath hasOptions delayProperties;
     };
 
     
@@ -73,6 +75,7 @@ rec {
       check = lib.traceValIfNot isDerivation;
     };
 
+    listOf = types.list;
     list = elemType: mkOptionType {
       name = "list of ${elemType.name}s";
       check = value: lib.traceValIfNot isList value && all elemType.check value;
@@ -81,6 +84,10 @@ rec {
       fold = op: nul: list: lib.fold (e: l: elemType.fold op l e) nul list;
       docPath = path: elemType.docPath (path + ".*");
       inherit (elemType) hasOptions;
+
+      # You cannot define multiple configurations of one entity, therefore
+      # no reason justify to delay properties inside list elements.
+      delayProperties = false;
     };
 
     attrsOf = elemType: mkOptionType {
@@ -91,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;
+      inherit (elemType) hasOptions delayProperties;
     };
 
     uniq = elemType: mkOptionType {
@@ -118,6 +125,7 @@ rec {
       merge = lib.id;
       check = x: lib.traceValIfNot builtins.isAttrs x;
       hasOptions = true;
+      delayProperties = true;
     };
 
   };