Merge pull request #97114 from Infinisil/type-deprecation

Better type deprecation messages
This commit is contained in:
Silvan Mosberger 2020-09-07 19:33:19 +02:00 committed by GitHub
commit ed5a07c0ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 16 deletions

View file

@ -457,7 +457,11 @@ rec {
# yield a value computed from the definitions
value = if opt ? apply then opt.apply res.mergedValue else res.mergedValue;
in opt //
warnDeprecation =
if opt.type.deprecationMessage == null then id
else warn "The type `types.${opt.type.name}' of option `${showOption loc}' defined in ${showFiles opt.declarations} is deprecated. ${opt.type.deprecationMessage}";
in warnDeprecation opt //
{ value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
inherit (res.defsFinal') highestPrio;
definitions = map (def: def.value) res.defsFinal;

View file

@ -91,9 +91,12 @@ rec {
# combinable with the binOp binary operation.
# binOp: binary operation that merge two payloads of the same type.
functor ? defaultFunctor name
, # The deprecation message to display when this type is used by an option
# If null, the type isn't deprecated
deprecationMessage ? null
}:
{ _type = "option-type";
inherit name check merge emptyValue getSubOptions getSubModules substSubModules typeMerge functor;
inherit name check merge emptyValue getSubOptions getSubModules substSubModules typeMerge functor deprecationMessage;
description = if description == null then name else description;
};
@ -222,8 +225,10 @@ rec {
# Deprecated; should not be used because it quietly concatenates
# strings, which is usually not what you want.
string = warn "types.string is deprecated because it quietly concatenates strings"
(separatedString "");
string = separatedString "" // {
name = "string";
deprecationMessage = "See https://github.com/NixOS/nixpkgs/pull/66346 for better alternative types.";
};
attrs = mkOptionType {
name = "attrs";
@ -252,9 +257,6 @@ rec {
merge = mergeEqualOption;
};
# TODO: drop this in the future:
list = builtins.trace "`types.list` has been removed; please use `types.listOf` instead" types.listOf;
listOf = elemType: mkOptionType rec {
name = "listOf";
description = "list of ${elemType.description}s";
@ -327,14 +329,12 @@ rec {
};
# TODO: drop this in the future:
loaOf =
let msg =
''
`types.loaOf` has been removed and mixing lists with attribute values
is no longer possible; please use `types.attrsOf` instead.
See https://github.com/NixOS/nixpkgs/issues/1800 for the motivation.
'';
in builtins.trace msg types.attrsOf;
loaOf = elemType: types.attrsOf elemType // {
name = "loaOf";
deprecationMessage = "Mixing lists with attribute values is no longer"
+ " possible; please use `types.attrsOf` instead. See"
+ " https://github.com/NixOS/nixpkgs/issues/1800 for the motivation.";
};
# Value of given type but with no merging (i.e. `uniq list`s are not concatenated).
uniq = elemType: mkOptionType rec {
@ -534,8 +534,9 @@ rec {
# declarations from the options attribute of containing option
# declaration.
optionSet = mkOptionType {
name = builtins.trace "types.optionSet is deprecated; use types.submodule instead" "optionSet";
name = "optionSet";
description = "option set";
deprecationMessage = "Use `types.submodule' instead";
};
# Augment the given type with an additional type check function.
addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; };