Added assertions

This commit is contained in:
Alexander Nortung 2023-01-22 20:31:23 +01:00
parent 5a222885fc
commit 6ad7575d6f
5 changed files with 27 additions and 12 deletions

View file

@ -1,31 +1,33 @@
{ lib, ... }: { lib, ... }:
with 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 = mkDeprecatedOption =
{ option # an array of the path to the option { option # an array of the path to the option
, alternative ? null , alternative ? null
, message ? null , message ? null
, visible ? false , visible ? false
, ...
}: }:
{ options, ... }: { options, ... }:
let let
fromOpt = getAttrFromPath option options; fromOpt = getAttrFromPath option options;
fullMessage = "The option `${showOption option}` has been deprecated." + 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
{ {
options = setAttrByPath option
(mkOption {
inherit visible;
description = fullMessage;
});
config = mkIf (fromOpt.isDefined) { config = mkIf (fromOpt.isDefined) {
warnings = [ warnings = [
("Nixvim: ${fullMessage}") ("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
} }

View file

@ -8,5 +8,10 @@ with lib;
visible = false; visible = false;
default = []; default = [];
}; };
assertions = mkOption {
type = types.listOf types.attrs; # Not sure what the correct type is here
visible = false;
default = [];
};
}; };
} }

View file

@ -11,13 +11,19 @@ in
programs.nixvim = mkOption { programs.nixvim = mkOption {
type = types.submodule ((modules pkgs) ++ [{ type = types.submodule ((modules pkgs) ++ [{
options.enable = mkEnableOption "nixvim"; options.enable = mkEnableOption "nixvim";
config.wrapRc = mkForce true; config.wrapRc = mkForce true;
}]); }]);
}; };
nixvim.helpers = shared.helpers; nixvim.helpers = shared.helpers;
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable mkMerge [
environment.systemPackages = [ cfg.finalPackage ]; {
}; environment.systemPackages = [ cfg.finalPackage ];
}
{
warnings = cfg.warnings;
assertions = cfg.assertions;
}
];
} }

View file

@ -24,6 +24,7 @@ in
}) })
({ ({
warnings = cfg.warnings; warnings = cfg.warnings;
assertions = cfg.assertions;
}) })
]); ]);
} }

View file

@ -25,6 +25,7 @@ in
}) })
({ ({
warnings = cfg.warnings; warnings = cfg.warnings;
assertions = cfg.assertions;
}) })
]); ]);
} }