diff --git a/doc/languages-frameworks/neovim.section.md b/doc/languages-frameworks/neovim.section.md index 164ebd163807b..2eedc1eb337a7 100644 --- a/doc/languages-frameworks/neovim.section.md +++ b/doc/languages-frameworks/neovim.section.md @@ -384,6 +384,8 @@ It accepts a single string for a module, or a list of module strings to test. When `nvimRequireCheck` is not specified, we will search the plugin's directory for lua modules to attempt loading. This quick smoke test can catch obvious dependency errors that might be missed. The check hook will fail the build if any modules cannot be loaded. This encourages inspecting the logs to identify potential issues. +Vim plugins listed in `dependencies` or `checkInputs`, along with their transitive `dependencies` and `requiredLuaModules`, are added to the check environment. Use `checkInputs` for plugins needed only during checks, such as optional integrations. + To only check a specific module, add it manually to the plugin definition [overrides](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/overrides.nix). ```nix diff --git a/pkgs/applications/editors/vim/plugins/hooks/neovim-require-check-hook.sh b/pkgs/applications/editors/vim/plugins/hooks/neovim-require-check-hook.sh index af3960ba98b35..423a3995ef9fc 100644 --- a/pkgs/applications/editors/vim/plugins/hooks/neovim-require-check-hook.sh +++ b/pkgs/applications/editors/vim/plugins/hooks/neovim-require-check-hook.sh @@ -60,9 +60,23 @@ run_require_checks() { successful_modules=() export HOME="$TMPDIR" - local deps="${dependencies[*]}" - local nativeCheckInputs="${nativeBuildInputs[*]}" - local checkInputs="${buildInputs[*]}" + + local -a dependencyPathArgs=() + local -a dependencyLoadArgs=() + + if [ -n "${nvimRequireCheckPackPath:-}" ]; then + dependencyPathArgs=(--cmd "set packpath^=$nvimRequireCheckPackPath") + dependencyLoadArgs=(--cmd "packloadall") + else + local deps="${dependencies[*]}" + local nativeCheckInputs="${nativeBuildInputs[*]}" + local checkInputs="${buildInputs[*]}" + dependencyPathArgs=( + --cmd "set rtp+=${deps// /,}" + --cmd "set rtp+=${nativeCheckInputs// /,}" + --cmd "set rtp+=${checkInputs// /,}" + ) + fi local -a luaPathArgs=() if [ -n "${nvimRequireCheckLuaPath:-}" ] || [ -n "${nvimRequireCheckLuaCPath:-}" ]; then @@ -98,10 +112,9 @@ run_require_checks() { if [ "$skip" = false ]; then echo "Attempting to require module: $name" if @nvimBinary@ -es --headless -n -u NONE -i NONE --clean -V1 \ - --cmd "set rtp+=${deps// /,}" \ - --cmd "set rtp+=${nativeCheckInputs// /,}" \ - --cmd "set rtp+=${checkInputs// /,}" \ + "${dependencyPathArgs[@]}" \ "${luaPathArgs[@]}" \ + "${dependencyLoadArgs[@]}" \ --cmd "set packpath^=$packPathDir" \ --cmd "packadd testPlugin" \ --cmd "lua require('$name')"; then diff --git a/pkgs/applications/editors/vim/plugins/utils/vim-utils.nix b/pkgs/applications/editors/vim/plugins/utils/vim-utils.nix index 7d5af312e4766..d67e949d3dc20 100644 --- a/pkgs/applications/editors/vim/plugins/utils/vim-utils.nix +++ b/pkgs/applications/editors/vim/plugins/utils/vim-utils.nix @@ -15,6 +15,7 @@ makeSetupHook, linkFarm, config, + neovimUtils, }: /* @@ -523,7 +524,14 @@ rec { finalAttrs: oldAttrs: let getRequiredLuaModules = attrs: attrs.requiredLuaModules or attrs.passthru.requiredLuaModules or [ ]; - modules = getRequiredLuaModules finalAttrs; + checkPlugins = lib.filter (p: p.passthru.vimPlugin or false) (finalAttrs.checkInputs or [ ]); + checkDependencies = lib.unique ( + findDependenciesRecursively ((finalAttrs.dependencies or [ ]) ++ checkPlugins) + ); + vimPackageInfo = neovimUtils.makeVimPackageInfo ( + lib.filter (p: p.passthru.vimPlugin or false) checkDependencies + ); + modules = lib.unique (getRequiredLuaModules finalAttrs ++ vimPackageInfo.luaDependencies); luaEnv = lua.withPackages (_: modules); in { @@ -552,6 +560,9 @@ rec { nvimRequireCheckLuaPath = lib.optionalString (modules != [ ]) (lua.pkgs.getLuaPath luaEnv); nvimRequireCheckLuaCPath = lib.optionalString (modules != [ ]) (lua.pkgs.getLuaCPath luaEnv); + nvimRequireCheckPackPath = neovimUtils.packDir { + plugins = vimPackageInfo.vimPackage; + }; passthru = (oldAttrs.passthru or { }) // { vimPlugin = true;