diff options
author | Robert Hensing <robert@roberthensing.nl> | 2021-11-22 14:39:10 +0100 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2021-11-22 16:50:50 +0100 |
commit | d464ccfdd9e101d4f5a112ab58d91ccbb912524a (patch) | |
tree | 2e2e45996c8bcaf13baeb01c681fa50001226d65 /lib/tests | |
parent | 426ab31fdeb828886c22ec0e561eca2b90b84b94 (diff) |
modules: Add moduleType to module arguments
Diffstat (limited to 'lib/tests')
-rwxr-xr-x | lib/tests/modules.sh | 5 | ||||
-rw-r--r-- | lib/tests/modules/declare-variants.nix | 9 | ||||
-rw-r--r-- | lib/tests/modules/define-variant.nix | 22 |
3 files changed, 36 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index aba3f08122f5..2f36d6107ca4 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -281,6 +281,11 @@ checkConfigError 'A definition for option .fun.\[function body\]. is not of type checkConfigOutput "b a" config.result ./functionTo/list-order.nix checkConfigOutput "a c" config.result ./functionTo/merging-attrs.nix +# moduleType +checkConfigOutput "a b" config.resultFoo ./declare-variants.nix ./define-variant.nix +checkConfigOutput "a y z" config.resultFooBar ./declare-variants.nix ./define-variant.nix +checkConfigOutput "a b c" config.resultFooFoo ./declare-variants.nix ./define-variant.nix + cat <<EOF ====== module tests ====== $pass Pass diff --git a/lib/tests/modules/declare-variants.nix b/lib/tests/modules/declare-variants.nix new file mode 100644 index 000000000000..3ed6fa689e21 --- /dev/null +++ b/lib/tests/modules/declare-variants.nix @@ -0,0 +1,9 @@ +{ lib, moduleType, ... }: +let inherit (lib) mkOption types; +in +{ + options.variants = mkOption { + type = types.lazyAttrsOf moduleType; + default = {}; + }; +} diff --git a/lib/tests/modules/define-variant.nix b/lib/tests/modules/define-variant.nix new file mode 100644 index 000000000000..423cb0e37cb5 --- /dev/null +++ b/lib/tests/modules/define-variant.nix @@ -0,0 +1,22 @@ +{ config, lib, ... }: +let inherit (lib) types mkOption attrNames; +in +{ + options = { + attrs = mkOption { type = types.attrsOf lib.types.int; }; + result = mkOption { }; + resultFoo = mkOption { }; + resultFooBar = mkOption { }; + resultFooFoo = mkOption { }; + }; + config = { + attrs.a = 1; + variants.foo.attrs.b = 1; + variants.bar.attrs.y = 1; + variants.foo.variants.bar.attrs.z = 1; + variants.foo.variants.foo.attrs.c = 3; + resultFoo = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.attrs); + resultFooBar = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.variants.bar.attrs); + resultFooFoo = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.variants.foo.attrs); + }; +} |