From e979b816a7b87d8a474fac4fef8ccda731e38638 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Fri, 29 May 2026 11:03:17 -0500 Subject: [PATCH] neovim-require-check-hook: make requiredLuaModules available during checks --- .../editors/neovim/tests/default.nix | 47 ++++++++++++++ .../hooks/neovim-require-check-hook.sh | 7 +++ .../editors/vim/plugins/utils/vim-utils.nix | 61 +++++++++++-------- 3 files changed, 91 insertions(+), 24 deletions(-) diff --git a/pkgs/applications/editors/neovim/tests/default.nix b/pkgs/applications/editors/neovim/tests/default.nix index c7d3bbb29d06..20045b23a10a 100644 --- a/pkgs/applications/editors/neovim/tests/default.nix +++ b/pkgs/applications/editors/neovim/tests/default.nix @@ -444,4 +444,51 @@ pkgs.lib.recurseIntoAttrs rec { ''; inherit (vimPlugins) corePlugins; + + nvim_require_check_lua_module = + let + inherit (neovim-unwrapped.lua.pkgs) luaexpat luassert; + in + vimUtils.buildVimPlugin { + pname = "neovim-require-check-lua-module-test"; + version = "0"; + src = runCommandLocal "neovim-require-check-lua-module-src" { } '' + mkdir -p "$out/lua/require-check-luamods" + mkdir -p "$out/plugin" + cat > "$out/plugin/require-check-luamods.vim" <<'EOF' + let g:require_check_luamods_plugin_loaded = 1 + EOF + cat > "$out/lua/require-check-luamods/init.lua" <<'EOF' + if vim.g.require_check_luamods_plugin_loaded ~= 1 then + error("plugin script was not sourced") + end + -- lxp: direct C dependency from luaexpat (package.cpath) + require("lxp") + -- say: transitive dependency of luassert (package.path closure) + require("say") + return {} + EOF + ''; + requiredLuaModules = [ + luaexpat + luassert + ]; + }; + + nvim_require_check_passthru_lua_module = + let + inherit (neovim-unwrapped.lua.pkgs) luassert; + in + vimUtils.buildVimPlugin { + pname = "neovim-require-check-passthru-lua-module-test"; + version = "0"; + src = runCommandLocal "neovim-require-check-passthru-lua-module-src" { } '' + mkdir -p "$out/lua/require-check-passthru-luamods" + cat > "$out/lua/require-check-passthru-luamods/init.lua" <<'EOF' + require("say") + return {} + EOF + ''; + passthru.requiredLuaModules = [ luassert ]; + }; } 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 56f92e6e1eb9..60e6d6758198 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 @@ -53,6 +53,12 @@ run_require_checks() { local deps="${dependencies[*]}" local nativeCheckInputs="${nativeBuildInputs[*]}" local checkInputs="${buildInputs[*]}" + + local -a luaPathArgs=() + if [ -n "${nvimRequireCheckLuaPath:-}" ] || [ -n "${nvimRequireCheckLuaCPath:-}" ]; then + luaPathArgs=(--cmd "lua package.path='${nvimRequireCheckLuaPath:-}'..';'..package.path; package.cpath='${nvimRequireCheckLuaCPath:-}'..';'..package.cpath") + fi + set +e if [ -v 'nvimSkipModule' ]; then @@ -85,6 +91,7 @@ run_require_checks() { --cmd "set rtp+=$out,${deps// /,}" \ --cmd "set rtp+=$out,${nativeCheckInputs// /,}" \ --cmd "set rtp+=$out,${checkInputs// /,}" \ + "${luaPathArgs[@]}" \ --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 d297ffab0114..7d5af312e476 100644 --- a/pkgs/applications/editors/vim/plugins/utils/vim-utils.nix +++ b/pkgs/applications/editors/vim/plugins/utils/vim-utils.nix @@ -4,6 +4,7 @@ stdenv, vim, vimPlugins, + neovim-unwrapped, buildEnv, symlinkJoin, writeText, @@ -516,35 +517,47 @@ rec { drv: let drv-name = drv.name or "${drv.pname}-${drv.version}"; + lua = neovim-unwrapped.lua; in - drv.overrideAttrs (oldAttrs: { - name = "vimplugin-${drv-name}"; - # dont move the "doc" folder since vim expects it - forceShare = [ - "man" - "info" - ]; - - nativeBuildInputs = - oldAttrs.nativeBuildInputs or [ ] - ++ lib.optionals (stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ - vimGenDocHook + drv.overrideAttrs ( + finalAttrs: oldAttrs: + let + getRequiredLuaModules = attrs: attrs.requiredLuaModules or attrs.passthru.requiredLuaModules or [ ]; + modules = getRequiredLuaModules finalAttrs; + luaEnv = lua.withPackages (_: modules); + in + { + name = "vimplugin-${drv-name}"; + # dont move the "doc" folder since vim expects it + forceShare = [ + "man" + "info" ]; - doCheck = oldAttrs.doCheck or true; + nativeBuildInputs = + oldAttrs.nativeBuildInputs or [ ] + ++ lib.optionals (stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ + vimGenDocHook + ]; - nativeCheckInputs = - oldAttrs.nativeCheckInputs or [ ] - ++ lib.optionals (stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ - vimCommandCheckHook - # many neovim plugins keep using buildVimPlugin - neovimRequireCheckHook - ]; + doCheck = oldAttrs.doCheck or true; - passthru = (oldAttrs.passthru or { }) // { - vimPlugin = true; - }; - }); + nativeCheckInputs = + oldAttrs.nativeCheckInputs or [ ] + ++ lib.optionals (stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ + vimCommandCheckHook + # many neovim plugins keep using buildVimPlugin + neovimRequireCheckHook + ]; + + nvimRequireCheckLuaPath = lib.optionalString (modules != [ ]) (lua.pkgs.getLuaPath luaEnv); + nvimRequireCheckLuaCPath = lib.optionalString (modules != [ ]) (lua.pkgs.getLuaCPath luaEnv); + + passthru = (oldAttrs.passthru or { }) // { + vimPlugin = true; + }; + } + ); } // lib.optionalAttrs config.allowAliases { vimWithRC = throw "vimWithRC was removed, please use vim.customize instead";