Skip to content

Commit f28d384

Browse files
committed
modules/performance/combine-plugins: propagate lua dependencies
Plugins from luarocks (e.g. telescope-nvim) have dependencies specified in propagatedBuildInputs. These dependencies are not added as plugins in Nvim runtime. They are added to LUA_PATH env var for wrapped neovim. This commit collects all propagatedBuildInputs from input plugin list and puts them in the combined plugin. Note that such dependencies are never combined, because they are not plugins.
1 parent 57e19ec commit f28d384

File tree

2 files changed

+70
-16
lines changed

2 files changed

+70
-16
lines changed

modules/top-level/plugins/mk-plugin-pack.nix

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,38 @@ let
2828
(builtins.concatMap (f: f ps))
2929
];
3030

31+
# propagatedBuildInputs contain lua dependencies
32+
propagatedBuildInputs = lib.pipe pluginsToCombine [
33+
(builtins.catAttrs "plugin")
34+
(builtins.catAttrs "propagatedBuildInputs")
35+
builtins.concatLists
36+
lib.unique
37+
];
38+
3139
# Combined plugin
32-
combinedPlugin = pkgs.vimUtils.toVimPlugin (
33-
pkgs.buildEnv {
34-
name = "plugin-pack";
35-
paths = overriddenPlugins;
36-
inherit pathsToLink;
40+
combinedPlugin =
41+
lib.pipe
42+
{
43+
name = "plugin-pack";
44+
paths = overriddenPlugins;
45+
inherit pathsToLink;
3746

38-
# Remove empty directories and activate vimGenDocHook
39-
# TODO: figure out why we are running the `preFixup` hook in `postBuild`
40-
postBuild = ''
41-
find $out -type d -empty -delete
42-
runHook preFixup
43-
'';
44-
passthru = {
45-
inherit python3Dependencies;
46-
};
47-
}
48-
);
47+
# buildEnv uses runCommand under the hood. runCommand doesn't run any build phases.
48+
# To run custom commands buildEnv takes postBuild argument.
49+
# fixupPhase is used for propagating build inputs and to trigger vimGenDocHook
50+
postBuild = ''
51+
find $out -type d -empty -delete
52+
fixupPhase
53+
'';
54+
passthru = {
55+
inherit python3Dependencies;
56+
};
57+
}
58+
[
59+
pkgs.buildEnv
60+
pkgs.vimUtils.toVimPlugin
61+
(drv: drv.overrideAttrs { inherit propagatedBuildInputs; })
62+
];
4963

5064
# Combined plugin configs
5165
combinedConfig = lib.pipe pluginsToCombine [

tests/test-sources/modules/performance/combine-plugins.nix

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ let
6969
pluginWithPyDeps3 = mkPlugin "plugin-with-py-deps-3" {
7070
passthru.python3Dependencies = ps: [ ps.requests ];
7171
};
72+
# Plugins with Lua dependencies
73+
ensureDep =
74+
drv: dep:
75+
drv.overrideAttrs (prev: {
76+
propagatedBuildInputs = lib.unique (
77+
prev.propagatedBuildInputs or [ ] ++ [ prev.passthru.lua.pkgs.${dep} ]
78+
);
79+
});
80+
pluginWithLuaDeps1 = ensureDep pkgs.vimPlugins.telescope-nvim "plenary-nvim";
81+
pluginWithLuaDeps2 = ensureDep pkgs.vimPlugins.nvim-cmp "plenary-nvim";
82+
pluginWithLuaDeps3 = ensureDep pkgs.vimPlugins.gitsigns-nvim "nui-nvim";
7283
in
7384
{
7485
# Test basic functionality
@@ -222,6 +233,35 @@ in
222233
];
223234
};
224235

236+
# Test that plugin lua dependencies are handled
237+
lua-dependencies =
238+
{ config, ... }:
239+
{
240+
performance.combinePlugins.enable = true;
241+
extraPlugins = [
242+
simplePlugin1
243+
# Duplicated plenary-nvim dependency
244+
pluginWithLuaDeps1
245+
pluginWithLuaDeps2
246+
# nui-nvim dependency
247+
pluginWithLuaDeps3
248+
];
249+
extraConfigLuaPost = ''
250+
-- All packages and its dependencies are importable
251+
require("telescope")
252+
require("plenary")
253+
require("cmp")
254+
require("gitsigns")
255+
require("nui.popup")
256+
'';
257+
assertions = [
258+
{
259+
assertion = pluginCount config.build.nvimPackage config.build.extraFiles "start" == 1;
260+
message = "More than one plugin is defined in packpathDirs.";
261+
}
262+
];
263+
};
264+
225265
# Test that optional plugins are handled
226266
optional-plugins =
227267
{ config, ... }:

0 commit comments

Comments
 (0)