summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2023-04-17 20:00:07 +0200
committerRobert Hensing <robert@roberthensing.nl>2023-05-06 18:32:59 +0200
commit7459c024950282da952d43762ad93ff30995cc6a (patch)
treee95e5153ff67dee1702c808796ac51c480ef02e9 /lib
parent8054785157119ea12e526481924d6676427904bb (diff)
lib/tests/modules.sh: Add submodule + class tests
Diffstat (limited to 'lib')
-rwxr-xr-xlib/tests/modules.sh9
-rw-r--r--lib/tests/modules/class-check.nix41
2 files changed, 49 insertions, 1 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 116a0778aebc0..8f4553464ad01 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -362,11 +362,18 @@ checkConfigOutput 'ok' config.freeformItems.foo.bar ./adhoc-freeformType-survive
 # because of an `extendModules` bug, issue 168767.
 checkConfigOutput '^1$' config.sub.specialisation.value ./extendModules-168767-imports.nix
 
-# Class checks
+# Class checks, evalModules
 checkConfigOutput '^{ }$' config.ok.config ./class-check.nix
 checkConfigError 'The module .*/module-class-is-darwin.nix was imported into nixos instead of darwin.' config.fail.config ./class-check.nix
 checkConfigError 'The module foo.nix#darwinModules.default was imported into nixos instead of darwin.' config.fail-anon.config ./class-check.nix
 
+# Class checks, submoduleWith
+checkConfigOutput '^{ }$' config.sub.nixosOk ./class-check.nix
+checkConfigError 'The module .*/module-class-is-darwin.nix was imported into nixos instead of darwin.' config.sub.nixosFail.config ./class-check.nix
+
+# submoduleWith type merge with different class
+checkConfigError 'error: A submoduleWith option is declared multiple times with conflicting class values "darwin" and "nixos".' config.sub.mergeFail.config ./class-check.nix
+
 # _type check
 checkConfigError 'Could not load a value as a module, because it is of type "flake", in file .*/module-imports-_type-check.nix' config.ok.config ./module-imports-_type-check.nix
 checkConfigOutput '^true$' "$@" config.enable ./declare-enable.nix ./define-enable-with-top-level-mkIf.nix
diff --git a/lib/tests/modules/class-check.nix b/lib/tests/modules/class-check.nix
index 02d1431cc88b6..7874d0e28ec73 100644
--- a/lib/tests/modules/class-check.nix
+++ b/lib/tests/modules/class-check.nix
@@ -1,4 +1,43 @@
 { lib, ... }: {
+  options = {
+    sub = {
+      nixosOk = lib.mkOption {
+        type = lib.types.submoduleWith {
+          class = "nixos";
+          modules = [ ];
+        };
+      };
+      # Same but will have bad definition
+      nixosFail = lib.mkOption {
+        type = lib.types.submoduleWith {
+          class = "nixos";
+          modules = [ ];
+        };
+      };
+
+      mergeFail = lib.mkOption {
+        type = lib.types.submoduleWith {
+          class = "nixos";
+          modules = [ ];
+        };
+        default = { };
+      };
+    };
+  };
+  imports = [
+    {
+      options = {
+        sub = {
+          mergeFail = lib.mkOption {
+            type = lib.types.submoduleWith {
+              class = "darwin";
+              modules = [ ];
+            };
+          };
+        };
+      };
+    }
+  ];
   config = {
     _module.freeformType = lib.types.anything;
     ok =
@@ -31,5 +70,7 @@
         ];
       };
 
+    sub.nixosOk = { config = {}; class = "nixos"; };
+    sub.nixosFail = { imports = [ ./module-class-is-darwin.nix ]; };
   };
 }