summary refs log tree commit diff
path: root/pkgs/lib/modules.nix
diff options
context:
space:
mode:
authorNicolas Pierron <nicolas.b.pierron@gmail.com>2012-04-15 23:31:48 +0000
committerNicolas Pierron <nicolas.b.pierron@gmail.com>2012-04-15 23:31:48 +0000
commit8a677091830176ba5e820f5421e7d6f7eb938f8c (patch)
tree9ac4d09cf8b5efbabfe8dce5b06fd7c359686cc0 /pkgs/lib/modules.nix
parenta9c51d7af3bd5c6b633d56afe1cb854b967e5c57 (diff)
downloadnixpkgs-8a677091830176ba5e820f5421e7d6f7eb938f8c.tar
nixpkgs-8a677091830176ba5e820f5421e7d6f7eb938f8c.tar.gz
nixpkgs-8a677091830176ba5e820f5421e7d6f7eb938f8c.tar.bz2
nixpkgs-8a677091830176ba5e820f5421e7d6f7eb938f8c.tar.lz
nixpkgs-8a677091830176ba5e820f5421e7d6f7eb938f8c.tar.xz
nixpkgs-8a677091830176ba5e820f5421e7d6f7eb938f8c.tar.zst
nixpkgs-8a677091830176ba5e820f5421e7d6f7eb938f8c.zip
Add mkMerge and obsolete mkThenElse.
svn path=/nixpkgs/trunk/; revision=33796
Diffstat (limited to 'pkgs/lib/modules.nix')
-rw-r--r--pkgs/lib/modules.nix46
1 files changed, 32 insertions, 14 deletions
diff --git a/pkgs/lib/modules.nix b/pkgs/lib/modules.nix
index 8ecb04156e7..eb528f141fe 100644
--- a/pkgs/lib/modules.nix
+++ b/pkgs/lib/modules.nix
@@ -41,29 +41,31 @@ rec {
   # attributes.
   unifyModuleSyntax = m:
     let
-      getImports = m:
+      delayedModule = delayProperties m;
+      getImports =
         if m ? config || m ? options then
           attrByPath ["imports"] [] m
         else
-          toList (rmProperties (attrByPath ["require"] [] (delayProperties m)));
+          toList (rmProperties (attrByPath ["require"] [] delayedModule));
 
-      getImportedPaths = m: filter isPath (getImports m);
-      getImportedSets = m: filter (x: !isPath x) (getImports m);
+      getImportedPaths = filter isPath getImports;
+      getImportedSets = filter (x: !isPath x) getImports;
+
+      getConfig =
+        removeAttrs delayedModule ["require" "key"];
 
-      getConfig = m:
-        removeAttrs (delayProperties m) ["require" "key"];
     in
       if isModule m then
         { key = "<unknown location>"; } // m
       else
         {
           key = "<unknown location>";
-          imports = getImportedPaths m;
-          config = getConfig m;
+          imports = getImportedPaths;
+          config = getConfig;
         } // (
-          if getImportedSets m != [] then
-            assert tail (getImportedSets m) == [];
-            { options = head (getImportedSets m); }
+          if getImportedSets != [] then
+            assert tail getImportedSets == [];
+            { options = head getImportedSets; }
           else
             {}
         );
@@ -124,9 +126,25 @@ rec {
         value
     ) module;
 
-
+  # Handle mkMerge function left behind after a delay property.
+  moduleFlattenMerge = module:
+    if module ? config &&
+       isProperty module.config &&
+       isMerge module.config.property
+    then
+      (map (cfg: { key = module.key; config = cfg; }) module.config.content)
+      ++ [ (module // { config = {}; }) ]
+    else
+      [ module ];
+
+  # Handle mkMerge attributes which are left behind by previous delay
+  # properties and convert them into a list of modules. Delay properties
+  # inside the config attribute of a module and create a second module if a
+  # mkMerge attribute was left behind.
+  #
+  # Module -> [ Module ]
   delayModule = module:
-    moduleApply { config = delayProperties; } module;
+    map (moduleApply { config = delayProperties; }) (moduleFlattenMerge module);
 
   evalDefinitions = opt: values:
     if opt ? type && opt.type.delayOnGlobalEval then
@@ -170,7 +188,7 @@ rec {
       addName = name:
         if path == "" then name else path + "." + name;
 
-      modules = map delayModule modules_;
+      modules = concatLists (map delayModule modules_);
 
       modulesOf = name: filterModules name modules;
       declarationsOf = name: filter (m: m ? options) (modulesOf name);