neovim: use improved submodule deprecation detection

Prevent false positives with deprecation warning.
This commit is contained in:
Austin Horstman 2026-04-07 08:04:05 -05:00
parent fbc97e23f6
commit 0eddb2cc1a
4 changed files with 101 additions and 28 deletions

View file

@ -1,4 +1,4 @@
{ config, pkgs, ... }:
{ config, ... }:
{
time = "2026-04-01T20:28:19+00:00";
condition = config.programs.neovim.enable;
@ -22,20 +22,13 @@
which can be triggered for instance by:
programs.neovim.plugins = [
{ plugin = vimPlugins.fugitive-vim; }
{ plugin = vimPlugins.fugitive-vim; config = "# some viml"; }
];
Fix it with:
programs.neovim.plugins = [
{ plugin = vimPlugins.fugitive-vim; type = "viml"; }
{ plugin = vimPlugins.fugitive-vim; config = "# some viml"; type = "viml"; }
];
or
programs.neovim.plugins = [
vimPlugins.fugitive-vim
];
'';
}

View file

@ -1,6 +1,7 @@
{
config,
lib,
options,
pkgs,
...
}:
@ -30,6 +31,20 @@ let
inherit (pkgs) neovimUtils;
jsonFormat = pkgs.formats.json { };
pluginTypeStateVersion = lib.hm.deprecations.mkStateVersionOptionDefault {
inherit (config.home) stateVersion;
since = "26.05";
optionPath = [
"programs"
"neovim"
"plugins"
"PLUGIN"
"type"
];
legacy.value = "viml";
current.value = "lua";
};
in
{
meta.maintainers = with lib.maintainers; [ khaneliman ];
@ -282,23 +297,8 @@ in
"fennel"
]) types.str;
description = "Language used in config. Configurations are aggregated per-language.";
inherit
(lib.hm.deprecations.mkStateVersionOptionDefault {
inherit (config.home) stateVersion;
optionPath = [
"programs"
"neovim"
"plugins"
"PLUGIN"
"type"
];
since = "26.05";
legacy.value = "viml";
current.value = "lua";
})
default
defaultText
;
default = pluginTypeStateVersion.effectiveDefault;
inherit (pluginTypeStateVersion) defaultText;
};
optional = mkEnableOption "optional" // {
@ -435,6 +435,26 @@ in
config = mkIf cfg.enable (
let
legacyPluginTypeWarnings = lib.hm.deprecations.mkStateVersionListSubmoduleWarnings {
inherit (config.home) stateVersion;
since = "26.05";
baseWarning = pluginTypeStateVersion.warning;
definitions = options.programs.neovim.plugins.definitionsWithLocations;
shouldWarnEntry = lib.hm.deprecations.mkListEntryOmittedFieldPredicate {
omittedField = "type";
triggerField = "config";
};
describeEntry =
entry:
if entry.value ? plugin && entry.value.plugin != null then
"plugin `${lib.getName entry.value.plugin}`"
else
"a plugin entry";
extraEntryWarning =
_entry:
''Set `type = "viml"` or `type = "lua"` on that plugin entry to make the config language explicit.'';
};
allPlugins =
cfg.plugins
++ lib.optional cfg.coc.enable {
@ -445,7 +465,7 @@ in
};
defaultPlugin = {
type = "viml";
type = pluginTypeStateVersion.effectiveDefault;
plugin = null;
config = null;
optional = false;
@ -520,6 +540,8 @@ in
wrapperHasUserConfig = wrappedNeovim'.luaRcContent != wrappedNeovim'.providerLuaRc;
in
{
warnings = legacyPluginTypeWarnings;
programs.neovim = {
generatedConfigViml = cfg.extraConfig;

View file

@ -9,4 +9,5 @@
neovim-extra-lua-init = ./extra-lua-init.nix;
neovim-extra-lua-default = ./extra-lua-default.nix;
neovim-extra-lua-empty-plugin = ./extra-lua-empty-plugin.nix;
neovim-plugin-type-warning = ./plugin-type-warning.nix;
}

View file

@ -0,0 +1,57 @@
{
config,
lib,
pkgs,
...
}:
{
imports = [ ./stubs.nix ];
home.stateVersion = "25.11";
programs.neovim = {
enable = true;
plugins = with pkgs.vimPlugins; [
{
plugin = vim-commentary;
}
{
plugin = vim-nix;
config = ''
let g:hmLegacyPluginType = 1
'';
}
{
plugin = unicode-vim;
type = "lua";
config = ''
vim.g.hmExplicitPluginType = 1
'';
}
];
};
test.asserts.warnings.expected = [
(lib.concatStringsSep "\n" [
"The default value of `programs.neovim.plugins.PLUGIN.type` has changed from `\"viml\"` to `\"lua\"`."
"You are currently using the legacy default (`\"viml\"`) because `home.stateVersion` is less than \"26.05\"."
"To silence this warning and keep legacy behavior, set:"
" programs.neovim.plugins.PLUGIN.type = \"viml\";"
"To adopt the new default behavior, set:"
" programs.neovim.plugins.PLUGIN.type = \"lua\";"
"Triggered by plugin `vim-nix` defined in `plugin-type-warning.nix` at list index 2."
"Set `type = \"viml\"` or `type = \"lua\"` on that plugin entry to make the config language explicit."
])
];
assertions = [
{
assertion = lib.hasInfix "let g:hmLegacyPluginType = 1" config.programs.neovim.generatedConfigs.viml;
message = "Implicit legacy plugin type should still route old-state-version config to viml.";
}
{
assertion = lib.hasInfix "vim.g.hmExplicitPluginType = 1" config.programs.neovim.generatedConfigs.lua;
message = "Explicit lua plugin type should still route config to lua.";
}
];
}