summary refs log tree commit diff
path: root/lib/types.nix
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2022-05-25 17:45:28 +0200
committerRobert Hensing <robert@roberthensing.nl>2022-06-14 23:01:27 +0200
commit19a069ab8b17834da249b5ecb507c2eabe76a3e3 (patch)
treee5984b60e5cc0b51be41663f6bc1f50e2db09fcd /lib/types.nix
parent781c2e0789f7f6b75454a8e986c675ad36e6ee36 (diff)
lib.types: Add deferredModuleWith
Diffstat (limited to 'lib/types.nix')
-rw-r--r--lib/types.nix24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/types.nix b/lib/types.nix
index f5d13ea10d281..68dfa5843dee5 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -540,11 +540,31 @@ rec {
     };
 
     # A module to be imported in some other part of the configuration.
-    deferredModule = mkOptionType {
+    deferredModule = deferredModuleWith { };
+
+    # A module to be imported in some other part of the configuration.
+    # `staticModules`' options will be added to the documentation, unlike
+    # options declared via `config`.
+    deferredModuleWith = attrs@{ staticModules ? [] }: mkOptionType {
       name = "deferredModule";
       description = "module";
       check = x: isAttrs x || isFunction x || path.check x;
-      merge = loc: defs: map (def: lib.setDefaultModuleLocation "${def.file}, via option ${showOption loc}" def.value) defs;
+      merge = loc: defs: staticModules ++ map (def: lib.setDefaultModuleLocation "${def.file}, via option ${showOption loc}" def.value) defs;
+      inherit (submoduleWith { modules = staticModules; })
+        getSubOptions
+        getSubModules;
+      substSubModules = m: deferredModuleWith (attrs // {
+        staticModules = m;
+      });
+      functor = defaultFunctor "deferredModuleWith" // {
+        type = types.deferredModuleWith;
+        payload = {
+          inherit staticModules;
+        };
+        binOp = lhs: rhs: {
+          staticModules = lhs.staticModules ++ rhs.staticModules;
+        };
+      };
     };
 
     # The type of a type!