Skip to content

Commit

Permalink
treewide: use mkAssertions wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Jan 20, 2025
1 parent a7e516b commit af6e4b0
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 72 deletions.
6 changes: 3 additions & 3 deletions plugins/by-name/alpha/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,17 @@ in

extraPlugins = [ cfg.package ];

assertions = [
assertions = lib.nixvim.mkAssertions "plugins.alpha" [
{
assertion = themeDefined || layoutDefined;
message = ''
Nixvim (plugins.alpha): You have to either set a `theme` or define some sections in `layout`.
You have to either set a `theme` or define some sections in `layout`.
'';
}
{
assertion = !(themeDefined && layoutDefined);
message = ''
Nixvim (plugins.alpha): You can't define both a `theme` and custom options.
You can't define both a `theme` and custom options.
Set `plugins.alpha.theme = null` if you want to configure alpha manually using the `layout` option.
'';
}
Expand Down
14 changes: 6 additions & 8 deletions plugins/by-name/lsp-status/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,12 @@ lib.nixvim.plugins.mkNeovimPlugin {

callSetup = false;
extraConfig = cfg: {
assertions = [
{
assertion = config.plugins.lsp.enable;
message = ''
Nixvim (plugins.lsp-status): `plugins.lsp` must be enabled to use lsp-status
'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.lsp-status" {
assertion = config.plugins.lsp.enable;
message = ''
`plugins.lsp` must be enabled to use lsp-status
'';
};

plugins.lsp = {
preConfig = ''
Expand Down
14 changes: 6 additions & 8 deletions plugins/by-name/marks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,12 @@ in
config = mkIf cfg.enable {
extraPlugins = [ cfg.package ];

assertions = [
{
assertion = all (n: elem n (range 0 9)) (attrNames cfg.bookmarks);
message = ''
Nixvim (plugins.marks): The keys of the `bookmarks` option should be integers between 0 and 9.
'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.mark" {
assertion = all (n: elem n (range 0 9)) (attrNames cfg.bookmarks);
message = ''
The keys of the `bookmarks` option should be integers between 0 and 9.
'';
};

extraConfigLua =
let
Expand Down
20 changes: 9 additions & 11 deletions plugins/by-name/neoclip/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,14 @@ lib.nixvim.plugins.mkNeovimPlugin {
'';
};

assertions = [
{
assertion =
isBool cfg.settings.enable_persistent_history && cfg.settings.enable_persistent_history
-> config.plugins.sqlite-lua.enable;
message = ''
Nixvim (plugins.neoclip): The persistent history sqlite storage backend needs `sqlite-lua` to function as intended.
You can enable it by setting `plugins.sqlite-lua.enable` to `true`.
'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.neoclip" {
assertion =
isBool cfg.settings.enable_persistent_history && cfg.settings.enable_persistent_history
-> config.plugins.sqlite-lua.enable;
message = ''
The persistent history sqlite storage backend needs `sqlite-lua` to function as intended.
You can enable it by setting `plugins.sqlite-lua.enable` to `true`.
'';
};
};
}
7 changes: 4 additions & 3 deletions plugins/by-name/neogit/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
assertions =
assertions = lib.nixvim.mkAssertions "plugins.neogit" (
map
(name: {
assertion =
Expand All @@ -121,14 +121,15 @@ lib.nixvim.plugins.mkNeovimPlugin {
in
isEnabled -> config.plugins.${name}.enable;
message = ''
Nixvim (plugins.neogit): You have enabled the `${name}` integration, but `plugins.${name}.enable` is `false`.
You have enabled the `${name}` integration, but `plugins.${name}.enable` is `false`.
'';
})
[
"telescope"
"diffview"
"fzf-lua"
];
]
);

extraPackages =
[
Expand Down
4 changes: 2 additions & 2 deletions plugins/by-name/nvim-jdtls/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ in
} // cfg.extraOptions;
in
mkIf cfg.enable {
assertions = [
assertions = lib.nixvim.mkAssertions "plugins.nvim-jdtls" [
{
assertion = cfg.cmd != null || cfg.data != null;
message = "You have to either set the `plugins.nvim-jdtls.data` or the `plugins.nvim-jdtls.cmd` option.";
}
{
assertion = cfg.cmd == null -> cfg.jdtLanguageServerPackage != null;
message = ''
Nixvim (plugins.nvim-jdtls) You haven't defined a `cmd` or `jdtLanguageServerPackage`.
You haven't defined a `cmd` or `jdtLanguageServerPackage`.
The default `cmd` requires `plugins.nvim-jdtls.jdtLanguageServerPackage` to be set.
'';
Expand Down
14 changes: 6 additions & 8 deletions plugins/by-name/package-info/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,12 @@ lib.nixvim.plugins.mkNeovimPlugin {
};

extraConfig = cfg: {
assertions = [
{
assertion = cfg.enableTelescope -> config.plugins.telescope.enable;
message = ''
Nixvim (plugins.package-info): The telescope integration needs telescope to function as intended.
'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.package-info" {
assertion = cfg.enableTelescope -> config.plugins.telescope.enable;
message = ''
The telescope integration needs telescope to function as intended.
'';
};

extraPackages = [ cfg.packageManagerPackage ];

Expand Down
6 changes: 3 additions & 3 deletions plugins/by-name/rest/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,17 @@ lib.nixvim.plugins.mkNeovimPlugin {
callSetup = false;

extraConfig = cfg: {
assertions = [
assertions = lib.nixvim.mkAssertions "plugins.rest" [
{
assertion = config.plugins.treesitter.enable;
message = ''
Nixvim (plugins.rest): Requires the `http` parser from `plugins.treesitter`, please set `plugins.treesitter.enable`.
Requires the `http` parser from `plugins.treesitter`, please set `plugins.treesitter.enable`.
'';
}
{
assertion = cfg.enableTelescope -> config.plugins.telescope.enable;
message = ''
Nixvim (plugins.rest): You have `plugins.rest.enableTelescope` set to true, but `plugins.telescope.enable` is false.
You have `plugins.rest.enableTelescope` set to true, but `plugins.telescope.enable` is false.
Either disable the telescope integration or enable telescope.
'';
}
Expand Down
16 changes: 7 additions & 9 deletions plugins/by-name/rustaceanvim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ lib.nixvim.plugins.mkNeovimPlugin {

globals.rustaceanvim = cfg.settings;

assertions = [
{
assertion = cfg.enable -> !config.plugins.lsp.servers.rust_analyzer.enable;
message = ''
Nixvim (plugins.rustaceanvim): Both `plugins.rustaceanvim.enable` and `plugins.lsp.servers.rust_analyzer.enable` are true.
Disable one of them otherwise you will have multiple clients attached to each buffer.
'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.rustaceanvim" {
assertion = cfg.enable -> !config.plugins.lsp.servers.rust_analyzer.enable;
message = ''
Both `plugins.rustaceanvim.enable` and `plugins.lsp.servers.rust_analyzer.enable` are true.
Disable one of them otherwise you will have multiple clients attached to each buffer.
'';
};

# TODO: remove after 24.11
warnings = lib.nixvim.mkWarnings "plugins.rustaceanvim" {
Expand Down
6 changes: 3 additions & 3 deletions plugins/by-name/startup/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,19 @@ in
sectionNames = attrNames cfg.sections;
numSections = length sectionNames;
in
[
lib.nixvim.mkAssertions "plugins.startup" [
{
assertion = (cfg.options.paddings == null) || (length cfg.options.paddings) == numSections;
message = ''
Nixvim (plugins.startup): Make sure that `plugins.startup.options.paddings` has the same
Make sure that `plugins.startup.options.paddings` has the same
number of elements as there are sections.
'';
}
{
assertion =
((length cfg.parts) <= numSections) && (all (part: hasAttr part cfg.sections) cfg.parts);
message = ''
Nixvim (plugins.startup): You should not have more section names in `plugins.startup.parts` than you have sections defined.
You should not have more section names in `plugins.startup.parts` than you have sections defined.
'';
}
];
Expand Down
15 changes: 7 additions & 8 deletions plugins/by-name/telekasten/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ lib.nixvim.plugins.mkNeovimPlugin {
# TODO: Remove once nixpkgs #349346 lands, since it will have telescope-nvim
# as a dependency.
extraConfig = cfg: {
assertions = [
{
assertion = config.plugins.telescope.enable;
message = ''
Nixvim (plugins.telekasten): The plugin needs telescope to function as intended.
'';
}
];
assertions = lib.nixvim.mkAssertions "plugins.telekasten" {
assertion = config.plugins.telescope.enable;
message = ''
Nixvim (plugins.telekasten): The plugin needs telescope to function as intended.
'';
};

extraPlugins = [ cfg.plenaryPackage ];
};
}
6 changes: 3 additions & 3 deletions plugins/by-name/yanky/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,17 @@ lib.nixvim.plugins.mkNeovimPlugin {
'';
};

assertions = [
assertions = lib.nixvim.mkAssertions "plugins.yanky" [
{
assertion = cfg.enableTelescope -> config.plugins.telescope.enable;
message = ''
Nixvim (plugins.yanky): The telescope integration needs telescope to function as intended
The telescope integration needs telescope to function as intended
'';
}
{
assertion = cfg.settings.ring.storage == "sqlite" -> config.plugins.sqlite-lua.enable;
message = ''
Nixvim (plugins.yanky): The sqlite storage backend needs `sqlite-lua` to function as intended.
The sqlite storage backend needs `sqlite-lua` to function as intended.
You can enable it by setting `plugins.sqlite-lua.enable` to `true`.
'';
}
Expand Down
7 changes: 4 additions & 3 deletions plugins/colorschemes/palette.nix
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
settingsExample = { };

extraConfig = cfg: {
assertions =
assertions = lib.nixvim.mkAssertions "colorschemes.palette" (
lib.mapAttrsToList
(
name: defaultPaletteNames:
Expand All @@ -131,7 +131,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
{
assertion = lib.isString palette -> lib.elem palette allowedPaletteNames;
message = ''
Nixvim (colorschemes.palette): `settings.palettes.${name}` (${palette}") is not part of the allowed ${name} palette names (${lib.concatStringsSep " " allowedPaletteNames}).
`settings.palettes.${name}` (${palette}") is not part of the allowed ${name} palette names (${lib.concatStringsSep " " allowedPaletteNames}).
'';
}
)
Expand All @@ -150,6 +150,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
"dark"
"bright"
];
};
}
);
};
}

0 comments on commit af6e4b0

Please sign in to comment.