diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 685856f16f69d..ca02e6be55b62 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -570,6 +570,11 @@ checkConfigOutput '^38|27$' options.submoduleLine38.declarationPositions.1.line # nested options work checkConfigOutput '^34$' options.nested.nestedLine34.declarationPositions.0.line ./declaration-positions.nix +# AttrsWith tests +checkConfigOutput '^11$' config.result ./lazy-attrsWith.nix +checkConfigOutput '^"mergedName..nested"$' config.result ./name-merge-attrsWith-1.nix +checkConfigError 'The option .mergedName. in .*\.nix. is already declared in .*\.nix' config.mergedName ./name-merge-attrsWith-2.nix + cat < = "id" + name = "id"; + elemType = types.submodule { + options.nested = mkOption { + type = types.int; + default = 1; + }; + }; + }; + }; + } + ) + # Module B + ( + { ... }: + { + options.mergedName = mkOption { + # default: "" + type = types.attrsOf (types.submodule { }); + # default = {}; + }; + } + ) + + # Output + ( + { + options, + ... + }: + { + options.result = mkOption { + default = lib.concatStringsSep "." (options.mergedName.type.getSubOptions options.mergedName.loc) + .nested.loc; + }; + } + ) + ]; +} diff --git a/lib/tests/modules/name-merge-attrsWith-2.nix b/lib/tests/modules/name-merge-attrsWith-2.nix new file mode 100644 index 0000000000000..ab7e8e3193e6d --- /dev/null +++ b/lib/tests/modules/name-merge-attrsWith-2.nix @@ -0,0 +1,39 @@ +# Non mergable attrsWith +{ lib, ... }: +let + inherit (lib) types mkOption; +in +{ + imports = [ + # Module A + ( + { ... }: + { + options.mergedName = mkOption { + default = { }; + type = types.attrsWith { + name = "id"; + elemType = types.submodule { + options.nested = mkOption { + type = types.int; + default = 1; + }; + }; + }; + }; + } + ) + # Module B + ( + { ... }: + { + options.mergedName = mkOption { + type = types.attrsWith { + name = "other"; + elemType = types.submodule { }; + }; + }; + } + ) + ]; +} diff --git a/lib/types.nix b/lib/types.nix index a63608df6abca..29a4dcef7928e 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -617,9 +617,9 @@ rec { getSubModules = elemType.getSubModules; substSubModules = m: attrsWith { elemType = elemType.substSubModules m; inherit name lazy; }; functor = defaultFunctor "attrsWith" // { - wrapped = elemType; - type = t: attrsWith { elemType = t; inherit name lazy; }; + type = payload: attrsWith payload; payload = { + # Important!: Add new function attributes here in case of future changes inherit elemType name lazy; }; binOp = lhs: rhs: