This type correctly merges multiple option types together while also annotating them with file information. In a future commit this will be used for `_module.freeformType`
···6161 boolToString
6262 ;
63636464- inherit (lib.modules) mergeDefinitions;
6464+ inherit (lib.modules)
6565+ mergeDefinitions
6666+ fixupOptionType
6767+ mergeOptionDecls
6868+ ;
6569 outer_types =
6670rec {
6771 isType = type: x: (x._type or "") == type;
···523527 submodule = modules: submoduleWith {
524528 shorthandOnlyDefinesConfig = true;
525529 modules = toList modules;
530530+ };
531531+532532+ # The type of a type!
533533+ optionType = mkOptionType {
534534+ name = "optionType";
535535+ description = "optionType";
536536+ check = value: value._type or null == "option-type";
537537+ merge = loc: defs:
538538+ let
539539+ # Prepares the type definitions for mergeOptionDecls, which
540540+ # annotates submodules types with file locations
541541+ optionModules = map ({ value, file }:
542542+ {
543543+ _file = file;
544544+ # There's no way to merge types directly from the module system,
545545+ # but we can cheat a bit by just declaring an option with the type
546546+ options = lib.mkOption {
547547+ type = value;
548548+ };
549549+ }
550550+ ) defs;
551551+ # Merges all the types into a single one, including submodule merging.
552552+ # This also propagates file information to all submodules
553553+ mergedOption = fixupOptionType loc (mergeOptionDecls loc optionModules);
554554+ in mergedOption.type;
526555 };
527556528557 submoduleWith =
···7474 should only be used when checking, merging and nested evaluation are not
7575 desirable.
76767777+`types.optionType`
7878+7979+: The type of an option's type. Its merging operation ensures that nested
8080+ options have the correct file location annotated, and that if possible,
8181+ multiple option definitions are correctly merged together. The main use
8282+ case is as the type of the `_module.freeformType` option.
8383+7784`types.attrs`
78857986: A free-form attribute set.
···113113 </varlistentry>
114114 <varlistentry>
115115 <term>
116116+ <literal>types.optionType</literal>
117117+ </term>
118118+ <listitem>
119119+ <para>
120120+ The type of an option’s type. Its merging operation ensures
121121+ that nested options have the correct file location
122122+ annotated, and that if possible, multiple option definitions
123123+ are correctly merged together. The main use case is as the
124124+ type of the <literal>_module.freeformType</literal> option.
125125+ </para>
126126+ </listitem>
127127+ </varlistentry>
128128+ <varlistentry>
129129+ <term>
116130 <literal>types.attrs</literal>
117131 </term>
118132 <listitem>