diff options
author | Robert Hensing | 2023-04-17 20:00:07 +0200 |
---|---|---|
committer | Robert Hensing | 2023-05-06 18:32:59 +0200 |
commit | 7459c024950282da952d43762ad93ff30995cc6a (patch) | |
tree | e95e5153ff67dee1702c808796ac51c480ef02e9 /lib/tests | |
parent | 8054785157119ea12e526481924d6676427904bb (diff) |
lib/tests/modules.sh: Add submodule + class tests
Diffstat (limited to 'lib/tests')
-rwxr-xr-x | lib/tests/modules.sh | 9 | ||||
-rw-r--r-- | lib/tests/modules/class-check.nix | 41 |
2 files changed, 49 insertions, 1 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 116a0778aebc..8f4553464ad0 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 02d1431cc88b..7874d0e28ec7 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 ]; }; }; } |