summary refs log tree commit diff
path: root/pkgs/lib/modules.nix
diff options
context:
space:
mode:
authorNicolas Pierron <nicolas.b.pierron@gmail.com>2009-09-14 13:19:00 +0000
committerNicolas Pierron <nicolas.b.pierron@gmail.com>2009-09-14 13:19:00 +0000
commit1557cfd0c60061971325d3c944c332b3af96e8c3 (patch)
tree07b7187554d0b6009a8f7023e5b90b8af02c1d78 /pkgs/lib/modules.nix
parent5b20a89f115ef09cf1566a33adc950406a6ef141 (diff)
downloadnixpkgs-1557cfd0c60061971325d3c944c332b3af96e8c3.tar
nixpkgs-1557cfd0c60061971325d3c944c332b3af96e8c3.tar.gz
nixpkgs-1557cfd0c60061971325d3c944c332b3af96e8c3.tar.bz2
nixpkgs-1557cfd0c60061971325d3c944c332b3af96e8c3.tar.lz
nixpkgs-1557cfd0c60061971325d3c944c332b3af96e8c3.tar.xz
nixpkgs-1557cfd0c60061971325d3c944c332b3af96e8c3.tar.zst
nixpkgs-1557cfd0c60061971325d3c944c332b3af96e8c3.zip
split moduleClosure in two parts:
* unifyModuleSyntax: handle all kind of module syntax to convert them into
  a module which has the following form:

  {
    imports = [ <paths> ];
    options = <attribute set of options declarations>;
    config = <attribute set (with properties) of option definitions>;
  }

  This function assume that there is at most one imported attribute set which
  correspond to option declarations.

* moduleClosure: handle a list of module's paths which are converted with
  the previous function to do the closure of the imports with the function
  lazyGenericClosure (which does the same as builtins.genericClosure except
  that it doesn't evaluate the content of modules).  The "key" and "paths"
  attributes are left to be used as debug information in futur
  implementation(s).

svn path=/nixpkgs/trunk/; revision=17108
Diffstat (limited to 'pkgs/lib/modules.nix')
-rw-r--r--pkgs/lib/modules.nix48
1 files changed, 34 insertions, 14 deletions
diff --git a/pkgs/lib/modules.nix b/pkgs/lib/modules.nix
index 2f1382ac93c..b7c3062f6a8 100644
--- a/pkgs/lib/modules.nix
+++ b/pkgs/lib/modules.nix
@@ -32,16 +32,10 @@ rec {
     else
       f;
 
-  moduleClosure = initModules: args:
+  # Convert module to a set which has imports / options and config
+  # attributes.
+  unifyModuleSyntax = m:
     let
-      moduleImport = m:
-        (applyIfFunction (importIfPath m) args) // {
-          # used by generic closure to avoid duplicated imports.
-          key = m;
-        };
-
-      removeKeys = list: map (m: removeAttrs m ["key"]) list;
-
       getImports = m:
         if m ? config || m ? options then
           attrByPath ["imports"] [] m
@@ -51,13 +45,39 @@ rec {
       getImportedPaths = m: filter isPath (getImports m);
       getImportedSets = m: filter (x: !isPath x) (getImports m);
 
-      inlineImportedSets = list:
-        lib.concatMap (m:[m] ++ map moduleImport (getImportedSets m)) list;
+      getConfig = m:
+        removeAttrs (delayProperties m) ["require"];
+    in
+      if m ? config || m ? options then
+        m
+      else
+        {
+          imports = getImportedPaths m;
+          config = getConfig m;
+        } // (
+          if getImportedSets m != [] then
+            assert tail (getImportedSets m) == [];
+            { options = head (getImportedSets m); }
+          else
+            {}
+        );
+
+  moduleClosure = initModules: args:
+    let
+      moduleImport = m: lib.addErrorContext "Import module ${m}." (
+        (unifyModuleSyntax (applyIfFunction (import m) args)) // {
+          # used by generic closure to avoid duplicated imports.
+          key = m;
+          paths = [ m ];
+        }
+      );
+
+      getImports = m: attrByPath ["imports"] [] m;
     in
-      removeKeys (inlineImportedSets (lazyGenericClosure {
+      lazyGenericClosure {
         startSet = map moduleImport initModules;
-        operator = m: map moduleImport (getImportedPaths m);
-      }));
+        operator = m: map moduleImport (getImports m);
+      };
 
   selectDeclsAndDefs = modules:
     lib.concatMap (m: