summary refs log tree commit diff
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2019-12-05 03:29:51 +0100
committerSilvan Mosberger <contact@infinisil.com>2020-01-01 01:13:03 +0100
commit5414b4018bf1161ad9bd0e98d0ffbde8aa435fe5 (patch)
tree7272f147840b49cb2c36e500efc50f77ad847479
parent5002e6afbc70c6bf80efa5f997707b877cb59cdd (diff)
downloadnixpkgs-5414b4018bf1161ad9bd0e98d0ffbde8aa435fe5.tar
nixpkgs-5414b4018bf1161ad9bd0e98d0ffbde8aa435fe5.tar.gz
nixpkgs-5414b4018bf1161ad9bd0e98d0ffbde8aa435fe5.tar.bz2
nixpkgs-5414b4018bf1161ad9bd0e98d0ffbde8aa435fe5.tar.lz
nixpkgs-5414b4018bf1161ad9bd0e98d0ffbde8aa435fe5.tar.xz
nixpkgs-5414b4018bf1161ad9bd0e98d0ffbde8aa435fe5.tar.zst
nixpkgs-5414b4018bf1161ad9bd0e98d0ffbde8aa435fe5.zip
lib/modules: Don't pack submodules specially
This has the beneficial side effect of allowing paths to be used as modules in
types.{submodule,submoduleWith}
-rw-r--r--lib/default.nix2
-rw-r--r--lib/modules.nix26
2 files changed, 11 insertions, 17 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 8af53152586..e31edeaaf9e 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -102,7 +102,7 @@ let
       commitIdFromGitRepo cleanSourceWith pathHasContext
       canCleanSource;
     inherit (modules) evalModules closeModules unifyModuleSyntax
-      applyIfFunction unpackSubmodule packSubmodule mergeModules
+      applyIfFunction mergeModules
       mergeModules' mergeOptionDecls evalOptionValue mergeDefinitions
       pushDownProperties dischargeProperties filterOverrides
       sortProperties fixupOptionType mkIf mkAssert mkMerge mkOverride
diff --git a/lib/modules.nix b/lib/modules.nix
index 6bfc314991b..48788ae933d 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -103,7 +103,7 @@ rec {
       toClosureList = file: parentKey: imap1 (n: x:
         if isAttrs x || isFunction x then
           let key = "${parentKey}:anon-${toString n}"; in
-          unifyModuleSyntax file key (unpackSubmodule (applyIfFunction key) x args)
+          unifyModuleSyntax file key (applyIfFunction key x args)
         else
           let file = toString x; key = toString x; in
           unifyModuleSyntax file key (applyIfFunction key (import x) args));
@@ -171,17 +171,6 @@ rec {
   else
     f;
 
-  /* We have to pack and unpack submodules. We cannot wrap the expected
-     result of the function as we would no longer be able to list the arguments
-     of the submodule. (see applyIfFunction) */
-  unpackSubmodule = unpack: m: args:
-    if isType "submodule" m then
-      { _file = m.file; } // (unpack m.submodule args)
-    else unpack m args;
-
-  packSubmodule = file: m:
-    { _type = "submodule"; file = file; submodule = m; };
-
   /* Merge a list of modules.  This will recurse over the option
      declarations in all modules, combining them into a single set.
      At the same time, for each option declaration, it will merge the
@@ -267,7 +256,14 @@ rec {
 
      'opts' is a list of modules.  Each module has an options attribute which
      correspond to the definition of 'loc' in 'opt.file'. */
-  mergeOptionDecls = loc: opts:
+  mergeOptionDecls =
+   let
+    packSubmodule = file: m:
+      { _file = file; imports = [ m ]; };
+    coerceOption = file: opt:
+      if isFunction opt then packSubmodule file opt
+      else packSubmodule file { options = opt; };
+   in loc: opts:
     foldl' (res: opt:
       let t  = res.type;
           t' = opt.options.type;
@@ -293,9 +289,7 @@ rec {
              current option declaration as the file use for the submodule.  If the
              submodule defines any filename, then we ignore the enclosing option file. */
           options' = toList opt.options.options;
-          coerceOption = file: opt:
-            if isFunction opt then packSubmodule file opt
-            else packSubmodule file { options = opt; };
+
           getSubModules = opt.options.type.getSubModules or null;
           submodules =
             if getSubModules != null then map (packSubmodule opt._file) getSubModules ++ res.options