From 11b22bab0552ce71649f27bae75964455cc5518c Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Tue, 26 Sep 2023 22:41:56 +0200 Subject: [PATCH] lib/option-warnings: deprecate useless option-warnings --- lib/option-warnings.nix | 95 ----------------------------------------- 1 file changed, 95 deletions(-) delete mode 100644 lib/option-warnings.nix diff --git a/lib/option-warnings.nix b/lib/option-warnings.nix deleted file mode 100644 index 1503133f..00000000 --- a/lib/option-warnings.nix +++ /dev/null @@ -1,95 +0,0 @@ -{lib, ...}: -with lib; rec { - # This should be used instead of mkRemovedOptionModule, when the option still works, - # but is just deprecated and should be changed now and for the future - mkDeprecatedOption = { - 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 deprecated, but might still work." - + (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}" - ]; - }; - }; - - mkRenamedOption = { - option, - newOption, - visible ? false, - warn ? true, - overrideDescription ? null, - }: {options, ...}: let - fromOpt = getAttrFromPath option options; - # toOf = attrByPath newOption - # (abort "Renaming error: option `${showOption newOption}` does not exist."); - toType = let - opt = attrByPath newOption {} options; - in - opt.type or (types.submodule {}); - message = "`${showOption option}` has been renamed to `${showOption newOption}`, but can still be used for compatibility"; - in { - options = setAttrByPath option (mkOption - { - inherit visible; - description = - if overrideDescription == null - then message - else overrideDescription; - } - // optionalAttrs (toType != null) { - type = toType; - }); - config = mkMerge [ - { - warnings = mkIf (warn && fromOpt.isDefined) ["Nixvim: ${message}"]; - } - (mkAliasAndWrapDefinitions (setAttrByPath newOption) fromOpt) - ]; - }; - - mkAliasOption = option: newOption: - mkRenamedOption { - inherit option newOption; - visible = true; - warn = false; - overrideDescription = "Alias of ${showOption newOption}"; - }; - - 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}" - ]; - }; - }; -}