summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2021-10-27 20:42:05 +0200
committerRobert Hensing <robert@roberthensing.nl>2021-11-01 09:34:07 +0100
commitdece37b83a46d488787859332e18286727b96cc4 (patch)
tree979d27f2821373269bf00f13912b2b02a7ebb234 /lib/modules.nix
parent9ec8a16c7908c7807e46fa4f38479ccc0af2b64e (diff)
downloadnixpkgs-dece37b83a46d488787859332e18286727b96cc4.tar
nixpkgs-dece37b83a46d488787859332e18286727b96cc4.tar.gz
nixpkgs-dece37b83a46d488787859332e18286727b96cc4.tar.bz2
nixpkgs-dece37b83a46d488787859332e18286727b96cc4.tar.lz
nixpkgs-dece37b83a46d488787859332e18286727b96cc4.tar.xz
nixpkgs-dece37b83a46d488787859332e18286727b96cc4.tar.zst
nixpkgs-dece37b83a46d488787859332e18286727b96cc4.zip
lib.evalModules: Add extendModules and type to result
Allows the simultaneous construction of top-level invocations and
submodule types.

This helps structure configuration systems integration code.
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix27
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 46ae3f13631..c25972999df 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -60,7 +60,8 @@ rec {
      it is to transparently move a set of modules to be a submodule of another
      config (as the proper arguments need to be replicated at each call to
      evalModules) and the less declarative the module set is. */
-  evalModules = { modules
+  evalModules = evalModulesArgs@
+                { modules
                 , prefix ? []
                 , # This should only be used for special arguments that need to be evaluated
                   # when resolving module structure (like in imports). For everything else,
@@ -183,10 +184,26 @@ rec {
             else throw baseMsg
         else null;
 
-      result = builtins.seq checkUnmatched {
-        inherit options;
-        config = removeAttrs config [ "_module" ];
-        inherit (config) _module;
+      checked = builtins.seq checkUnmatched;
+
+      result = {
+        options = checked options;
+        config = checked (removeAttrs config [ "_module" ]);
+        _module = checked (config._module);
+
+        extendModules = extendArgs@{
+          modules ? [],
+          specialArgs ? {},
+          prefix ? [],
+          }:
+            evalModules (evalModulesArgs // {
+              modules = evalModulesArgs.modules ++ modules;
+              specialArgs = evalModulesArgs.specialArgs or {} // specialArgs;
+              prefix = extendArgs.prefix or evalModulesArgs.prefix;
+            });
+        type = lib.types.submoduleWith {
+          inherit modules specialArgs;
+        };
       };
     in result;