···515515 # yield a value computed from the definitions
516516 value = if opt ? apply then opt.apply res.mergedValue else res.mergedValue;
517517518518- # Issue deprecation warnings recursively over all nested types of the
519519- # given type. But don't recurse if a type with the same name was already
520520- # visited before in order to prevent infinite recursion. So this only
521521- # warns once per type name.
522522- # Returns the new set of visited type names
523523- recursiveWarn = visited: type:
524524- let
525525- maybeWarn = warnIf (type.deprecationMessage != null)
526526- "The type `types.${type.name}' of option `${showOption loc}' defined in ${showFiles opt.declarations} is deprecated. ${type.deprecationMessage}";
527527- in
528528- if visited ? ${type.name} then visited
529529- else lib.foldl' recursiveWarn (maybeWarn visited // { ${type.name} = null; }) (lib.attrValues type.nestedTypes);
518518+ warnDeprecation =
519519+ warnIf (opt.type.deprecationMessage != null)
520520+ "The type `types.${opt.type.name}' of option `${showOption loc}' defined in ${showFiles opt.declarations} is deprecated. ${opt.type.deprecationMessage}";
530521531531- in builtins.seq (recursiveWarn {} opt.type) opt //
522522+ in warnDeprecation opt //
532523 { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
533524 inherit (res.defsFinal') highestPrio;
534525 definitions = map (def: def.value) res.defsFinal;
-6
lib/tests/modules.sh
···272272checkConfigOutput "b a" config.result ./functionTo/list-order.nix
273273checkConfigOutput "a c" config.result ./functionTo/merging-attrs.nix
274274275275-## Type deprecation
276276-checkConfigError 'The type `types.simple'\'' of option `simple'\'' defined in .* is deprecated. simple shall not be used' config.simple ./type-deprecation.nix
277277-checkConfigError 'The type `types.infinite'\'' of option `infinite'\'' defined in .* is deprecated. infinite shall not be used' config.infinite ./type-deprecation.nix
278278-checkConfigError 'The type `types.left'\'' of option `nested'\'' defined in .* is deprecated. left shall not be used' config.nested ./type-deprecation.nix
279279-checkConfigError 'The type `types.right'\'' of option `nested'\'' defined in .* is deprecated. right shall not be used' config.nested ./type-deprecation.nix
280280-281275cat <<EOF
282276====== module tests ======
283277$pass Pass
-39
lib/tests/modules/type-deprecation.nix
···11-{ lib, ... }: {
22-33- options.simple = lib.mkOption {
44- type = lib.mkOptionType {
55- name = "simple";
66- deprecationMessage = "simple shall not be used";
77- };
88- default = throw "";
99- };
1010-1111- options.infinite = lib.mkOption {
1212- type =
1313- let
1414- t = lib.mkOptionType {
1515- name = "infinite";
1616- deprecationMessage = "infinite shall not be used";
1717- };
1818- r = lib.types.either t (lib.types.attrsOf r);
1919- in r;
2020- default = throw "";
2121- };
2222-2323- options.nested = lib.mkOption {
2424- type =
2525- let
2626- left = lib.mkOptionType {
2727- name = "left";
2828- deprecationMessage = "left shall not be used";
2929- };
3030- right = lib.mkOptionType {
3131- name = "right";
3232- deprecationMessage = "right shall not be used";
3333- };
3434- in lib.types.either left right;
3535-3636- default = throw "";
3737- };
3838-3939-}