diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2020-09-21 08:49:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-21 08:49:24 +0200 |
commit | f3893d8b534dfb61472c09bd9c8a836599320e65 (patch) | |
tree | 3bdaac5d6359666bf249579beefbab7832adfa87 /lib/types.nix | |
parent | c06b0edde22ce82caa8a996df7d4505d71770287 (diff) | |
parent | 310699319b422210b70ebacf676007172c67c90b (diff) | |
download | nixlib-f3893d8b534dfb61472c09bd9c8a836599320e65.tar nixlib-f3893d8b534dfb61472c09bd9c8a836599320e65.tar.gz nixlib-f3893d8b534dfb61472c09bd9c8a836599320e65.tar.bz2 nixlib-f3893d8b534dfb61472c09bd9c8a836599320e65.tar.lz nixlib-f3893d8b534dfb61472c09bd9c8a836599320e65.tar.xz nixlib-f3893d8b534dfb61472c09bd9c8a836599320e65.tar.zst nixlib-f3893d8b534dfb61472c09bd9c8a836599320e65.zip |
Merge pull request #97119 from Infinisil/types.anything
Introduce `types.anything`
Diffstat (limited to 'lib/types.nix')
-rw-r--r-- | lib/types.nix | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/types.nix b/lib/types.nix index ef2c78082f8d..aae45366b8fb 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -104,6 +104,42 @@ rec { # When adding new types don't forget to document them in # nixos/doc/manual/development/option-types.xml! types = rec { + + anything = mkOptionType { + name = "anything"; + description = "anything"; + check = value: true; + merge = loc: defs: + let + getType = value: + if isAttrs value && isCoercibleToString value + then "stringCoercibleSet" + else builtins.typeOf value; + + # Returns the common type of all definitions, throws an error if they + # don't have the same type + commonType = foldl' (type: def: + if getType def.value == type + then type + else throw "The option `${showOption loc}' has conflicting option types in ${showFiles (getFiles defs)}" + ) (getType (head defs).value) defs; + + 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; + # Otherwise fall back to only allowing all equal definitions + }.${commonType} or mergeEqualOption; + in mergeFunction loc defs; + }; + unspecified = mkOptionType { name = "unspecified"; }; |