From c9abc97ee5b2b8d1d64257bc8c3b602675c30af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Lepage?= <33058747+GaetanLepage@users.noreply.github.com> Date: Tue, 28 Feb 2023 15:26:01 +0100 Subject: [PATCH] lib/option-warnings: add mkRemovedOption (#209) --- lib/option-warnings.nix | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/option-warnings.nix b/lib/option-warnings.nix index f4d77634..1503133f 100644 --- a/lib/option-warnings.nix +++ b/lib/option-warnings.nix @@ -69,14 +69,27 @@ with lib; rec { overrideDescription = "Alias of ${showOption newOption}"; }; - # TODO: - # mkRemovedOption = - # { option - # , visible ? false - # }: - # { options, ... }: - # { - # options = { }; - # config = { }; - # }; + mkRemovedOption = { + option, # an array of the path to the option + alternative ? null, + message ? null, + visible ? false, + }: { + options, + config, + ... + }: let + fromOpt = getAttrFromPath option options; + fromValue = getAttrFromPath option config; + fullMessage = + "The option `${showOption option}` has been removed." + + (optionalString (alternative != null) " You may want to use `${showOption alternative}` instead.") + + (optionalString (message != null) " Message: ${message}"); + in { + config = mkIf (fromOpt.isDefined && fromValue != fromOpt.default) { + warnings = [ + "Nixvim: ${fullMessage}" + ]; + }; + }; }