Skip to content

Commit e5e69b7

Browse files
committed
lib.types.anything: remove custom logic for lists (default to 'mergeEqualOption')
Previously, for values of type list, the merge function would only retain the value if the number of option definitions was less than or equal to 1, and would throw an error for conflicting definitions to avoid potentially unwanted list merges. This change removes that logic, defaulting to the 'mergeEqualOption' function for values of type list. This approach maintains the same safeguard against merging different lists while allowing lists with identical values to be merged.
1 parent 187de2e commit e5e69b7

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

lib/tests/modules.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,16 @@ checkConfigOutput '^null$' config.value.l1.l2.foo ./types-anything/nested-attrs.
426426
checkConfigOutput '^null$' config.value.l1.l2.l3.foo ./types-anything/nested-attrs.nix
427427
# Attribute sets that are coercible to strings shouldn't be recursed into
428428
checkConfigOutput '^"foo"$' config.value.outPath ./types-anything/attrs-coercible.nix
429-
# Multiple lists aren't concatenated together
430-
checkConfigError 'The option .* has conflicting definitions' config.value ./types-anything/lists.nix
429+
# Multiple lists aren't concatenated together if their definitions are not equal
430+
checkConfigError 'The option .* has conflicting definition values' config.value ./types-anything/lists.nix
431431
# Check that all equalizable atoms can be used as long as all definitions are equal
432432
checkConfigOutput '^0$' config.value.int ./types-anything/equal-atoms.nix
433433
checkConfigOutput '^false$' config.value.bool ./types-anything/equal-atoms.nix
434434
checkConfigOutput '^""$' config.value.string ./types-anything/equal-atoms.nix
435435
checkConfigOutput '^"/[^"]+"$' config.value.path ./types-anything/equal-atoms.nix
436436
checkConfigOutput '^null$' config.value.null ./types-anything/equal-atoms.nix
437437
checkConfigOutput '^0.1$' config.value.float ./types-anything/equal-atoms.nix
438+
checkConfigOutput '^\[1,"a",{"x":null}\]$' config.value.list ./types-anything/equal-atoms.nix
438439
# Functions can't be merged together
439440
checkConfigError "The option .value.multiple-lambdas.<function body>. has conflicting option types" config.applied.multiple-lambdas ./types-anything/functions.nix
440441
checkConfigOutput '^true$' config.valueIsFunction.single-lambda ./types-anything/functions.nix

lib/tests/modules/types-anything/equal-atoms.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
value.path = ./.;
1313
value.null = null;
1414
value.float = 0.1;
15+
value.list = [1 "a" {x=null;}];
1516
}
1617
{
1718
value.int = 0;
@@ -20,6 +21,7 @@
2021
value.path = ./.;
2122
value.null = null;
2223
value.float = 0.1;
24+
value.list = [1 "a" {x=null;}];
2325
}
2426
];
2527

lib/tests/modules/types-anything/lists.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
config = lib.mkMerge [
88
{
9-
value = [ null ];
9+
value = [ "a value" ];
1010
}
1111
{
12-
value = [ null ];
12+
value = [ "another value" ];
1313
}
1414
];
1515

lib/types.nix

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,6 @@ rec {
253253
mergeFunction = {
254254
# Recursively merge attribute sets
255255
set = (attrsOf anything).merge;
256-
# Safe and deterministic behavior for lists is to only accept one definition
257-
# listOf only used to apply mkIf and co.
258-
list =
259-
if length defs > 1
260-
then throw "The option `${showOption loc}' has conflicting definitions, in ${showFiles (getFiles defs)}."
261-
else (listOf anything).merge;
262256
# This is the type of packages, only accept a single definition
263257
stringCoercibleSet = mergeOneOption;
264258
lambda = loc: defs: arg: anything.merge

0 commit comments

Comments
 (0)