Skip to content

Commit 0bae1ff

Browse files
committed
modules/performance: add ability to byte compile nvim runtime directory
This commit adds `performance.byteCompileLua.nvimRuntime` toggle that, if enabled, byte compiles all lua files in Nvim runtime directory.
1 parent d9ba37a commit 0bae1ff

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

modules/performance.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ in
2121
plugins = lib.mkEnableOption "plugins" // {
2222
description = "Whether to byte compile lua plugins.";
2323
};
24+
nvimRuntime = lib.mkEnableOption "nvimRuntime" // {
25+
description = "Whether to byte compile lua files in Nvim runtime.";
26+
};
2427
};
2528

2629
combinePlugins = {

modules/top-level/output.nix

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,28 @@ in
244244
++ (optional config.wrapRc ''--add-flags -u --add-flags "${init}"'')
245245
);
246246

247-
wrappedNeovim = pkgs.wrapNeovimUnstable config.package (
247+
package =
248+
if config.performance.byteCompileLua.enable && config.performance.byteCompileLua.nvimRuntime then
249+
# Using symlinkJoin to avoid rebuilding neovim
250+
pkgs.symlinkJoin {
251+
name = "neovim-byte-compiled-${lib.getVersion config.package}";
252+
paths = [ config.package ];
253+
# Required attributes from original neovim package
254+
inherit (config.package) lua;
255+
nativeBuildInputs = [ helpers.byteCompileLuaHook ];
256+
postBuild = ''
257+
# Replace Nvim's binary symlink with a regular file,
258+
# or Nvim will use original runtime directory
259+
rm $out/bin/nvim
260+
cp ${config.package}/bin/nvim $out/bin/nvim
261+
262+
runHook postFixup
263+
'';
264+
}
265+
else
266+
config.package;
267+
268+
wrappedNeovim = pkgs.wrapNeovimUnstable package (
248269
neovimConfig
249270
// {
250271
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " " + extraWrapperArgs;

tests/test-sources/modules/performance/byte-compile-lua.nix

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,40 @@ in
182182
test_rtp_file("plugin/test2.lua", false)
183183
'';
184184
};
185+
186+
nvim-runtime = {
187+
performance.byteCompileLua = {
188+
enable = true;
189+
nvimRuntime = true;
190+
};
191+
192+
extraPlugins = [
193+
# Python 3 dependencies
194+
(pkgs.vimPlugins.nvim-lspconfig.overrideAttrs { passthru.python3Dependencies = ps: [ ps.pyyaml ]; })
195+
];
196+
197+
extraConfigLuaPost = ''
198+
${isByteCompiledFun}
199+
200+
-- vim namespace is working
201+
vim.opt.tabstop = 2
202+
vim.api.nvim_get_runtime_file("init.lua", false)
203+
vim.lsp.get_clients()
204+
vim.treesitter.language.get_filetypes("nix")
205+
vim.iter({})
206+
207+
test_rtp_file("lua/vim/lsp.lua", true)
208+
test_rtp_file("lua/vim/iter.lua", true)
209+
test_rtp_file("lua/vim/treesitter/query.lua", true)
210+
test_rtp_file("lua/vim/lsp/buf.lua", true)
211+
test_rtp_file("plugin/editorconfig.lua", true)
212+
test_rtp_file("plugin/tutor.vim", false)
213+
test_rtp_file("ftplugin/vim.vim", false)
214+
215+
-- Python3 packages are importable
216+
vim.cmd.py3("import yaml")
217+
'';
218+
};
185219
}
186220
//
187221
# Two equal tests, one with combinePlugins.enable = true

0 commit comments

Comments
 (0)