about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorAlexis Destrez <krostar@users.noreply.github.com>2024-09-06 21:23:42 +0200
committerAlexis Destrez <krostar@users.noreply.github.com>2024-09-07 01:15:32 +0200
commite5e69b748f3049680c418854930c2f2b792d4a82 (patch)
tree7ed8e5117de8bbad82ea4378e7012fabc57d624c /lib
parent187de2e3606c22596fa9edfe768ecf763f0711e5 (diff)
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.
Diffstat (limited to 'lib')
-rwxr-xr-xlib/tests/modules.sh5
-rw-r--r--lib/tests/modules/types-anything/equal-atoms.nix2
-rw-r--r--lib/tests/modules/types-anything/lists.nix4
-rw-r--r--lib/types.nix6
4 files changed, 7 insertions, 10 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index a14fe8cb30a54..a46434560d134 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -426,8 +426,8 @@ checkConfigOutput '^null$' config.value.l1.l2.foo ./types-anything/nested-attrs.
 checkConfigOutput '^null$' config.value.l1.l2.l3.foo ./types-anything/nested-attrs.nix
 # Attribute sets that are coercible to strings shouldn't be recursed into
 checkConfigOutput '^"foo"$' config.value.outPath ./types-anything/attrs-coercible.nix
-# Multiple lists aren't concatenated together
-checkConfigError 'The option .* has conflicting definitions' config.value ./types-anything/lists.nix
+# Multiple lists aren't concatenated together if their definitions are not equal
+checkConfigError 'The option .* has conflicting definition values' config.value ./types-anything/lists.nix
 # Check that all equalizable atoms can be used as long as all definitions are equal
 checkConfigOutput '^0$' config.value.int ./types-anything/equal-atoms.nix
 checkConfigOutput '^false$' config.value.bool ./types-anything/equal-atoms.nix
@@ -435,6 +435,7 @@ checkConfigOutput '^""$' config.value.string ./types-anything/equal-atoms.nix
 checkConfigOutput '^"/[^"]+"$' config.value.path ./types-anything/equal-atoms.nix
 checkConfigOutput '^null$' config.value.null ./types-anything/equal-atoms.nix
 checkConfigOutput '^0.1$' config.value.float ./types-anything/equal-atoms.nix
+checkConfigOutput '^\[1,"a",{"x":null}\]$' config.value.list ./types-anything/equal-atoms.nix
 # Functions can't be merged together
 checkConfigError "The option .value.multiple-lambdas.<function body>. has conflicting option types" config.applied.multiple-lambdas ./types-anything/functions.nix
 checkConfigOutput '^true$' config.valueIsFunction.single-lambda ./types-anything/functions.nix
diff --git a/lib/tests/modules/types-anything/equal-atoms.nix b/lib/tests/modules/types-anything/equal-atoms.nix
index 9925cfd608928..28d2b53ceee34 100644
--- a/lib/tests/modules/types-anything/equal-atoms.nix
+++ b/lib/tests/modules/types-anything/equal-atoms.nix
@@ -12,6 +12,7 @@
       value.path = ./.;
       value.null = null;
       value.float = 0.1;
+      value.list = [1 "a" {x=null;}];
     }
     {
       value.int = 0;
@@ -20,6 +21,7 @@
       value.path = ./.;
       value.null = null;
       value.float = 0.1;
+      value.list = [1 "a" {x=null;}];
     }
   ];
 
diff --git a/lib/tests/modules/types-anything/lists.nix b/lib/tests/modules/types-anything/lists.nix
index bd846afd3d185..21ca9d24f7a85 100644
--- a/lib/tests/modules/types-anything/lists.nix
+++ b/lib/tests/modules/types-anything/lists.nix
@@ -6,10 +6,10 @@
 
   config = lib.mkMerge [
     {
-      value = [ null ];
+      value = [ "a value" ];
     }
     {
-      value = [ null ];
+      value = [ "another value" ];
     }
   ];
 
diff --git a/lib/types.nix b/lib/types.nix
index 8b1d19ff2c613..06c4397cda2eb 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -253,12 +253,6 @@ rec {
           mergeFunction = {
             # Recursively merge attribute sets
             set = (attrsOf anything).merge;
-            # Safe and deterministic behavior for lists is to only accept one definition
-            # listOf only used to apply mkIf and co.
-            list =
-              if length defs > 1
-              then throw "The option `${showOption loc}' has conflicting definitions, in ${showFiles (getFiles defs)}."
-              else (listOf anything).merge;
             # This is the type of packages, only accept a single definition
             stringCoercibleSet = mergeOneOption;
             lambda = loc: defs: arg: anything.merge