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, ... }:
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, ... }:
let
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 (message != null) " Message: ${message}");
in
{
options = setAttrByPath option
(mkOption {
inherit visible;
description = fullMessage;
});
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
}

View file

@ -8,5 +8,10 @@ with lib;
visible = false;
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 {
type = types.submodule ((modules pkgs) ++ [{
options.enable = mkEnableOption "nixvim";
config.wrapRc = mkForce true;
config.wrapRc = mkForce true;
}]);
};
nixvim.helpers = shared.helpers;
};
config = mkIf cfg.enable {
environment.systemPackages = [ cfg.finalPackage ];
};
config = mkIf cfg.enable mkMerge [
{
environment.systemPackages = [ cfg.finalPackage ];
}
{
warnings = cfg.warnings;
assertions = cfg.assertions;
}
];
}

View file

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

View file

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