Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/languages-frameworks/neovim.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just keep one codepath for simplicity.
Aka we always create a nvimRequireCheckPackPath so we can get rid of the if and the else part.

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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion pkgs/applications/editors/vim/plugins/utils/vim-utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
makeSetupHook,
linkFarm,
config,
neovimUtils,
}:

/*
Expand Down Expand Up @@ -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
);
Comment thread
saadndm marked this conversation as resolved.
modules = lib.unique (getRequiredLuaModules finalAttrs ++ vimPackageInfo.luaDependencies);
Comment thread
saadndm marked this conversation as resolved.
luaEnv = lua.withPackages (_: modules);
in
{
Expand Down Expand Up @@ -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;
};
Comment on lines 561 to +565

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: keep check-only dependencies out of builds with doCheck = false

The new pack path and transitive Lua paths still reference checkInputs when checks are disabled, so a broken check-only plugin can now prevent evaluation. Guard all three attributes with finalAttrs.doCheck to preserve the disabled-check behavior.

Suggested change
nvimRequireCheckLuaPath = lib.optionalString (modules != [ ]) (lua.pkgs.getLuaPath luaEnv);
nvimRequireCheckLuaCPath = lib.optionalString (modules != [ ]) (lua.pkgs.getLuaCPath luaEnv);
nvimRequireCheckPackPath = neovimUtils.packDir {
plugins = vimPackageInfo.vimPackage;
};
nvimRequireCheckLuaPath = lib.optionalString (finalAttrs.doCheck && modules != [ ]) (lua.pkgs.getLuaPath luaEnv);
nvimRequireCheckLuaCPath = lib.optionalString (finalAttrs.doCheck && modules != [ ]) (lua.pkgs.getLuaCPath luaEnv);
nvimRequireCheckPackPath = lib.optionalString finalAttrs.doCheck (neovimUtils.packDir {
plugins = vimPackageInfo.vimPackage;
});


passthru = (oldAttrs.passthru or { }) // {
vimPlugin = true;
Expand Down
Loading