summaryrefslogtreecommitdiffstats
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2020-09-04 13:39:27 +0200
committerSilvan Mosberger <contact@infinisil.com>2020-09-07 13:17:14 +0200
commit1d4656225d4f1e93ea9801c72eb0b1b0bffa245d (patch)
tree84247b31c8aceb1cae02fd6286610f28abdf0952 /lib/modules.nix
parentf3bf0f173ec9b302c2613dfb6d76dc49b889f321 (diff)
lib/types: Allow types to emit a deprecation warning
Previously the only way to deprecate a type was using theType = lib.warn "deprecated" (mkOptionType ...) This caused the warning to be emitted when the type was evaluated, but the error didn't include which option actually used that type. With this commit, types can specify a deprecationMessage, which when non-null, is printed along with the option that uses the type
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix6
1 files changed, 5 insertions, 1 deletions
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;