Fixed deprecated option

This commit is contained in:
Alexander Nortung 2023-01-22 21:42:23 +01:00
parent d1278097c2
commit f2dbecdf3f

View file

@ -10,15 +10,16 @@ rec {
, message ? null , message ? null
, visible ? false , visible ? false
}: }:
{ options, ... }: { options, config, ... }:
let let
fromOpt = getAttrFromPath option options; fromOpt = getAttrFromPath option options;
fromValue = getAttrFromPath option config;
fullMessage = "The option `${showOption option}` has been deprecated, but might still work." + fullMessage = "The option `${showOption option}` has been deprecated, but might still work." +
(optionalString (alternative != null) " You may want to use `${showOption alternative}` instead.") + (optionalString (alternative != null) " You may want to use `${showOption alternative}` instead.") +
(optionalString (message != null) " Message: ${message}"); (optionalString (message != null) " Message: ${message}");
in in
{ {
config = mkIf (fromOpt.isDefined) { config = mkIf (fromOpt.isDefined && fromValue != fromOpt.default) {
warnings = [ warnings = [
("Nixvim: ${fullMessage}") ("Nixvim: ${fullMessage}")
]; ];
@ -35,8 +36,8 @@ rec {
{ options, ... }: { options, ... }:
let let
fromOpt = getAttrFromPath option options; fromOpt = getAttrFromPath option options;
toOf = attrByPath newOption # toOf = attrByPath newOption
(abort "Renaming error: option `${showOption newOption}` does not exist."); # (abort "Renaming error: option `${showOption newOption}` does not exist.");
toType = let opt = attrByPath newOption { } options; in toType = let opt = attrByPath newOption { } options; in
opt.type or (types.submodule { }); opt.type or (types.submodule { });
message = "`${showOption option}` has been renamed to `${showOption newOption}`, but can still be used for compatibility"; message = "`${showOption option}` has been renamed to `${showOption newOption}`, but can still be used for compatibility";
@ -54,7 +55,7 @@ rec {
}); });
config = mkMerge [ config = mkMerge [
{ {
warnings = mkIf (warn) [ "Nixvim: ${message}" ]; warnings = mkIf (warn && fromOpt.isDefined) [ "Nixvim: ${message}" ];
} }
(mkAliasAndWrapDefinitions (setAttrByPath newOption) fromOpt) (mkAliasAndWrapDefinitions (setAttrByPath newOption) fromOpt)
]; ];