From bb1e73bf6f4e59616522159d3485d0502b94b884 Mon Sep 17 00:00:00 2001 From: stefan Date: Mon, 8 Jun 2026 11:23:08 -0700 Subject: [PATCH] neovim-require-check-hook: remove `$out` from `rtp` Previously, the tested plugin appeared in `rtp` under two paths: - `/nix/store/-vimPlugins-my-plugin` from `$out` - `/build/.local/share/nvim/site/pack/nvimRequireCheckHook/opt/testPlugin` from `packadd testPlugin` This was causing problems for plugins that use `vim.api.nvim_get_runtime_file()`. For example, plugins that use `blink.lib` to load rust modules fail the require check because `blink.lib` uses this function to locate rust shared libraries and raises an error when duplicate libraries are found. The plugin is already loaded via `packadd testPlugin`, so adding `$out` to `rtp` is unnecessary. Remove `$out` from `rtp` to avoid duplicate runtime entries, and add a regression test to ensure the plugin appears in `rtp` only once. Co-authored-by: Austin Horstman --- .../editors/neovim/tests/default.nix | 21 +++++++++++++++++++ .../hooks/neovim-require-check-hook.sh | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index de18a630cca4..5bc2730da87b 100644 --- a/pkgs/applications/editors/neovim/tests/default.nix +++ b/pkgs/applications/editors/neovim/tests/default.nix @@ -558,4 +558,25 @@ pkgs.lib.recurseIntoAttrs rec { EOF ''; }; + + nvim_require_check_rtp_no_duplicate = vimUtils.buildVimPlugin { + pname = "neovim-require-check-rtp-no-duplicate-test"; + version = "0"; + src = runCommandLocal "neovim-require-check-rtp-no-duplicate-src" { } '' + mkdir -p "$out/lua/require-check-rtp-dedup" + cat > "$out/lua/require-check-rtp-dedup/init.lua" <<'EOF' + local target = "lua/require-check-rtp-dedup/init.lua" + local matches = vim.api.nvim_get_runtime_file(target, true) + if #matches ~= 1 then + error( + ("expected plugin on runtimepath exactly once, found %d:\n%s"):format( + #matches, + table.concat(matches, "\n") + ) + ) + end + return {} + EOF + ''; + }; } 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 5a309207cc53..af3960ba98b3 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 @@ -98,9 +98,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+=$out,${deps// /,}" \ - --cmd "set rtp+=$out,${nativeCheckInputs// /,}" \ - --cmd "set rtp+=$out,${checkInputs// /,}" \ + --cmd "set rtp+=${deps// /,}" \ + --cmd "set rtp+=${nativeCheckInputs// /,}" \ + --cmd "set rtp+=${checkInputs// /,}" \ "${luaPathArgs[@]}" \ --cmd "set packpath^=$packPathDir" \ --cmd "packadd testPlugin" \