nix-community.nixvim/lib/option-warnings.nix
Alexander Nortung 6ad7575d6f Added assertions
2023-01-22 20:31:23 +01:00

33 lines
1.1 KiB
Nix

{ lib, ... }:
with lib;
{
# 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, ... }:
let
fromOpt = getAttrFromPath option options;
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) {
warnings = [
("Nixvim: ${fullMessage}")
];
};
};
# 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
}