summary refs log tree commit diff
path: root/lib/tests/modules
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2022-03-10 22:45:41 +0100
committerRobert Hensing <robert@roberthensing.nl>2022-06-14 23:01:23 +0200
commit4746f6d03e4f8dc6e7399f45aaba0ca3aac32761 (patch)
tree454bacc3665fb4f41f6f06322dd799367403ebb3 /lib/tests/modules
parent9ef09e06806e79e32e30d17aee6879d69c011037 (diff)
downloadnixpkgs-4746f6d03e4f8dc6e7399f45aaba0ca3aac32761.tar
nixpkgs-4746f6d03e4f8dc6e7399f45aaba0ca3aac32761.tar.gz
nixpkgs-4746f6d03e4f8dc6e7399f45aaba0ca3aac32761.tar.bz2
nixpkgs-4746f6d03e4f8dc6e7399f45aaba0ca3aac32761.tar.lz
nixpkgs-4746f6d03e4f8dc6e7399f45aaba0ca3aac32761.tar.xz
nixpkgs-4746f6d03e4f8dc6e7399f45aaba0ca3aac32761.tar.zst
nixpkgs-4746f6d03e4f8dc6e7399f45aaba0ca3aac32761.zip
lib.types: Add deferredModule
Diffstat (limited to 'lib/tests/modules')
-rw-r--r--lib/tests/modules/deferred-module.nix54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/tests/modules/deferred-module.nix b/lib/tests/modules/deferred-module.nix
new file mode 100644
index 00000000000..faf459a991f
--- /dev/null
+++ b/lib/tests/modules/deferred-module.nix
@@ -0,0 +1,54 @@
+{ lib, ... }:
+let
+  inherit (lib) types mkOption setDefaultModuleLocation;
+  inherit (types) deferredModule lazyAttrsOf submodule str raw;
+in
+{
+  imports = [
+    # generic module, declaring submodules:
+    #   - nodes.<name>
+    #   - default
+    # where all nodes include the default
+    ({ config, ... }: {
+      _file = "generic.nix";
+      options.nodes = mkOption {
+        type = lazyAttrsOf (submodule { imports = config.default; });
+        default = {};
+      };
+      options.default = mkOption {
+        type = deferredModule;
+        default = { };
+        description = ''
+          Module that is included in all nodes.
+        '';
+      };
+    })
+
+    {
+      _file = "default-1.nix";
+      default = { config, ... }: {
+        options.settingsDict = lib.mkOption { type = lazyAttrsOf str; default = {}; };
+      };
+    }
+
+    {
+      _file = "default-a-is-b.nix";
+      default = { config, ... }: {
+        settingsDict.a = config.settingsDict.b;
+      };
+    }
+
+    {
+      _file = "nodes-foo.nix";
+      nodes.foo.settingsDict.b = "beta";
+    }
+
+    {
+      _file = "nodes-foo-c-is-a.nix";
+      nodes.foo = { config, ... }: {
+        settingsDict.c = config.settingsDict.a;
+      };
+    }
+
+  ];
+}