diff options
author | Silvan Mosberger <contact@infinisil.com> | 2021-10-05 13:50:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-05 13:50:42 +0200 |
commit | d193e632bc7e9154a5a5243701f07b0ed1554967 (patch) | |
tree | 7ff914a8033c640a6c77ecb12cd109443c2d81d3 /lib | |
parent | 2384362ca765da34e4089b0dbb738d2ae0340cf3 (diff) | |
parent | 48293bd6b6b791b9af745e9b7b94a6856e279fa0 (diff) | |
download | nixlib-d193e632bc7e9154a5a5243701f07b0ed1554967.tar nixlib-d193e632bc7e9154a5a5243701f07b0ed1554967.tar.gz nixlib-d193e632bc7e9154a5a5243701f07b0ed1554967.tar.bz2 nixlib-d193e632bc7e9154a5a5243701f07b0ed1554967.tar.lz nixlib-d193e632bc7e9154a5a5243701f07b0ed1554967.tar.xz nixlib-d193e632bc7e9154a5a5243701f07b0ed1554967.tar.zst nixlib-d193e632bc7e9154a5a5243701f07b0ed1554967.zip |
Merge pull request #140284 from Infinisil/types-anything-lambdas
lib/types: Make types.anything merge functions
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/tests/modules.sh | 4 | ||||
-rw-r--r-- | lib/tests/modules/types-anything/functions.nix | 12 | ||||
-rw-r--r-- | lib/types.nix | 6 |
3 files changed, 18 insertions, 4 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 2e57c2f8e2a1..b51db91f6b07 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 079518913918..21edd4aff9c4 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 a0be2ff3a452..c2532065d7ea 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; |