lib/types: Make types.anything merge functions

Previously it would give an error if there were multiple function
definitions.

Changed files
+18 -4
lib
tests
modules
types-anything
+3 -1
lib/tests/modules.sh
···
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
+9 -3
lib/tests/modules/types-anything/functions.nix
···
-
{ 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; };
}
];
+6
lib/types.nix
···
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;