diff --git a/lib/modules.nix b/lib/modules.nix index abcdd1a894cc..0b3560a12661 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -113,6 +113,10 @@ rec { args ? {} , # This would be remove in the future, Prefer _module.check option instead. check ? true + # Internal variable to avoid `_key` collisions regardless + # of `extendModules`. Used in `submoduleWith`. + # Test case: lib/tests/modules, "168767" + , extensionOffset ? 0 }: let withWarnings = x: @@ -338,15 +342,17 @@ rec { modules ? [], specialArgs ? {}, prefix ? [], + extensionOffset ? length modules, }: evalModules (evalModulesArgs // { modules = regularModules ++ modules; specialArgs = evalModulesArgs.specialArgs or {} // specialArgs; prefix = extendArgs.prefix or evalModulesArgs.prefix; + inherit extensionOffset; }); type = lib.types.submoduleWith { - inherit modules specialArgs; + inherit modules specialArgs extensionOffset; }; result = withWarnings { diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 8050c6539fc2..cc13a8d38e37 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -293,7 +293,7 @@ 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 y z"$' config.resultFooBar ./declare-variants.nix ./define-variant.nix checkConfigOutput '^"a b c"$' config.resultFooFoo ./declare-variants.nix ./define-variant.nix ## emptyValue's @@ -327,6 +327,10 @@ checkConfigError 'The option .theOption.nested. in .other.nix. is already declar # Test that types.optionType leaves types untouched as long as they don't need to be merged checkConfigOutput 'ok' config.freeformItems.foo.bar ./adhoc-freeformType-survives-type-merge.nix +# Anonymous submodules don't get nixed by import resolution/deduplication +# because of an `extendModules` bug, issue 168767. +checkConfigOutput '^1$' config.sub.specialisation.value ./extendModules-168767-imports.nix + cat <