diff --git a/lib/modules.nix b/lib/modules.nix index decb96ffe111..412c7f1df712 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -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; diff --git a/lib/types.nix b/lib/types.nix index 951fad291cca..ef2c78082f8d 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -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; };