about summary refs log tree commit diff
path: root/lib/tests/modules/specialArgs-lib.nix
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tests/modules/specialArgs-lib.nix')
-rw-r--r--lib/tests/modules/specialArgs-lib.nix28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/tests/modules/specialArgs-lib.nix b/lib/tests/modules/specialArgs-lib.nix
new file mode 100644
index 0000000000000..8c9d2103862aa
--- /dev/null
+++ b/lib/tests/modules/specialArgs-lib.nix
@@ -0,0 +1,28 @@
+{ config, lib, ... }:
+
+{
+  options = {
+    result = lib.mkOption { };
+    weird = lib.mkOption {
+      type = lib.types.submoduleWith {
+        # I generally recommend against overriding lib, because that leads to
+        # slightly incompatible dialects of the module system.
+        # Nonetheless, it's worth guarding the property that the module system
+        # evaluates with a completely custom lib, as a matter of separation of
+        # concerns.
+        specialArgs.lib = { };
+        modules = [ ];
+      };
+    };
+  };
+  config.weird = args@{ ... /* note the lack of a `lib` argument */ }:
+  assert args.lib == { };
+  assert args.specialArgs == { lib = { }; };
+  {
+    options.foo = lib.mkOption { };
+    config.foo = lib.mkIf true "alright";
+  };
+  config.result =
+    assert config.weird.foo == "alright";
+    "ok";
+}