Skip to content

Commit 16ee221

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 3966ebb commit 16ee221

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,28 @@ let
3535
paths = overriddenPlugins;
3636
inherit pathsToLink;
3737

38-
# Remove empty directories and activate vimGenDocHook
39-
# TODO: figure out why we are running the `preFixup` hook in `postBuild`
38+
# buildEnv uses runCommand under the hood. runCommand doesn't run any build phases.
39+
# To run custom commands buildEnv takes postBuild argument.
40+
# fixupPhase is used for propagating build inputs and to trigger vimGenDocHook
4041
postBuild = ''
4142
find $out -type d -empty -delete
42-
runHook preFixup
43+
fixupPhase
4344
'';
4445
passthru = {
4546
inherit python3Dependencies;
4647
};
4748
}
4849
);
4950

51+
# propagatedBuildInputs contain lua dependencies
52+
propagatedBuildInputs = lib.pipe pluginsToCombine [
53+
(builtins.catAttrs "plugin")
54+
(builtins.catAttrs "propagatedBuildInputs")
55+
builtins.concatLists
56+
lib.unique
57+
];
58+
finalCombinedPlugin = combinedPlugin.overrideAttrs { inherit propagatedBuildInputs; };
59+
5060
# Combined plugin configs
5161
combinedConfig = lib.pipe pluginsToCombine [
5262
(builtins.catAttrs "config")
@@ -55,6 +65,6 @@ let
5565
];
5666
in
5767
normalizePlugin {
58-
plugin = combinedPlugin;
68+
plugin = finalCombinedPlugin;
5969
config = combinedConfig;
6070
}

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
@@ -216,6 +227,35 @@ in
216227
];
217228
};
218229

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

0 commit comments

Comments
 (0)