nix-community.nixvim/lib/option-warnings.nix

34 lines
1.1 KiB
Nix
Raw Normal View History

2023-01-20 00:15:58 +01:00
{ lib, ... }:
with lib;
2023-01-22 20:31:23 +01:00
{
# 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
2023-01-20 00:15:58 +01:00
mkDeprecatedOption =
{ option # an array of the path to the option
, alternative ? null
, message ? null
, visible ? false
}:
{ options, ... }:
let
fromOpt = getAttrFromPath option options;
2023-01-22 20:31:23 +01:00
fullMessage = "The option `${showOption option}` has been deprecated, but might still work." +
2023-01-20 00:15:58 +01:00
(optionalString (alternative != null) " You may want to use `${showOption alternative}` instead.") +
(optionalString (message != null) " Message: ${message}");
in
{
config = mkIf (fromOpt.isDefined) {
warnings = [
("Nixvim: ${fullMessage}")
];
};
};
2023-01-22 20:31:23 +01:00
# For removed options, we can just use nixpkgs mkRemovedOptionModule, which is already in lib
mkRemovedOption = mkRemovedOptionModule;
# For renamed options, we can also use the function from nixpkgs
mkRenamedOption = mkRenamedOptionModule; # use the function from nixpkgs
2023-01-20 00:15:58 +01:00
}