summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2021-10-05 13:50:42 +0200
committerGitHub <noreply@github.com>2021-10-05 13:50:42 +0200
commitd193e632bc7e9154a5a5243701f07b0ed1554967 (patch)
tree7ff914a8033c640a6c77ecb12cd109443c2d81d3 /lib
parent2384362ca765da34e4089b0dbb738d2ae0340cf3 (diff)
parent48293bd6b6b791b9af745e9b7b94a6856e279fa0 (diff)
downloadnixpkgs-d193e632bc7e9154a5a5243701f07b0ed1554967.tar
nixpkgs-d193e632bc7e9154a5a5243701f07b0ed1554967.tar.gz
nixpkgs-d193e632bc7e9154a5a5243701f07b0ed1554967.tar.bz2
nixpkgs-d193e632bc7e9154a5a5243701f07b0ed1554967.tar.lz
nixpkgs-d193e632bc7e9154a5a5243701f07b0ed1554967.tar.xz
nixpkgs-d193e632bc7e9154a5a5243701f07b0ed1554967.tar.zst
nixpkgs-d193e632bc7e9154a5a5243701f07b0ed1554967.zip
Merge pull request #140284 from Infinisil/types-anything-lambdas
lib/types: Make types.anything merge functions
Diffstat (limited to 'lib')
-rwxr-xr-xlib/tests/modules.sh4
-rw-r--r--lib/tests/modules/types-anything/functions.nix12
-rw-r--r--lib/types.nix6
3 files changed, 18 insertions, 4 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 2e57c2f8e2a..b51db91f6b0 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -254,8 +254,10 @@ 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
 # Functions can't be merged together
-checkConfigError "The option .* has conflicting definition values" config.value.multiple-lambdas ./types-anything/functions.nix
+checkConfigError "The option .value.multiple-lambdas.<function body>. has conflicting option types" config.applied.multiple-lambdas ./types-anything/functions.nix
 checkConfigOutput '<LAMBDA>' config.value.single-lambda ./types-anything/functions.nix
+checkConfigOutput 'null' config.applied.merging-lambdas.x ./types-anything/functions.nix
+checkConfigOutput 'null' config.applied.merging-lambdas.y ./types-anything/functions.nix
 # Check that all mk* modifiers are applied
 checkConfigError 'attribute .* not found' config.value.mkiffalse ./types-anything/mk-mods.nix
 checkConfigOutput '{ }' config.value.mkiftrue ./types-anything/mk-mods.nix
diff --git a/lib/tests/modules/types-anything/functions.nix b/lib/tests/modules/types-anything/functions.nix
index 07951891391..21edd4aff9c 100644
--- a/lib/tests/modules/types-anything/functions.nix
+++ b/lib/tests/modules/types-anything/functions.nix
@@ -1,16 +1,22 @@
-{ lib, ... }: {
+{ lib, config, ... }: {
 
   options.value = lib.mkOption {
     type = lib.types.anything;
   };
 
+  options.applied = lib.mkOption {
+    default = lib.mapAttrs (name: fun: fun null) config.value;
+  };
+
   config = lib.mkMerge [
     {
       value.single-lambda = x: x;
-      value.multiple-lambdas = x: x;
+      value.multiple-lambdas = x: { inherit x; };
+      value.merging-lambdas = x: { inherit x; };
     }
     {
-      value.multiple-lambdas = x: x;
+      value.multiple-lambdas = x: [ x ];
+      value.merging-lambdas = y: { inherit y; };
     }
   ];
 
diff --git a/lib/types.nix b/lib/types.nix
index a0be2ff3a45..c2532065d7e 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -192,6 +192,12 @@ rec {
               else (listOf anything).merge;
             # This is the type of packages, only accept a single definition
             stringCoercibleSet = mergeOneOption;
+            lambda = loc: defs: arg: anything.merge
+              (loc ++ [ "<function body>" ])
+              (map (def: {
+                file = def.file;
+                value = def.value arg;
+              }) defs);
             # Otherwise fall back to only allowing all equal definitions
           }.${commonType} or mergeEqualOption;
         in mergeFunction loc defs;