Skip to content

Commit 3caca7c

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 196762d commit 3caca7c

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
@@ -17,6 +17,9 @@ in
1717
plugins = lib.mkEnableOption "plugins" // {
1818
description = "Whether to byte compile lua plugins.";
1919
};
20+
nvimRuntime = lib.mkEnableOption "nvimRuntime" // {
21+
description = "Whether to byte compile lua files in Nvim runtime.";
22+
};
2023
};
2124

2225
combinePlugins = {

modules/top-level/output.nix

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

257-
wrappedNeovim = pkgs.wrapNeovimUnstable config.package (
257+
package =
258+
if config.performance.byteCompileLua.enable && config.performance.byteCompileLua.nvimRuntime then
259+
# Using symlinkJoin to avoid rebuilding neovim
260+
pkgs.symlinkJoin {
261+
name = "neovim-byte-compiled-${lib.getVersion config.package}";
262+
paths = [ config.package ];
263+
# Required attributes from original neovim package
264+
inherit (config.package) lua;
265+
nativeBuildInputs = [ helpers.byteCompileLuaHook ];
266+
postBuild = ''
267+
# Replace Nvim's binary symlink with a regular file,
268+
# or Nvim will use original runtime directory
269+
rm $out/bin/nvim
270+
cp ${config.package}/bin/nvim $out/bin/nvim
271+
272+
runHook postFixup
273+
'';
274+
}
275+
else
276+
config.package;
277+
278+
wrappedNeovim = pkgs.wrapNeovimUnstable package (
258279
neovimConfig
259280
// {
260281
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
@@ -177,6 +177,40 @@ in
177177
test_rtp_file("plugin/test2.lua", false)
178178
'';
179179
};
180+
181+
nvim-runtime = {
182+
performance.byteCompileLua = {
183+
enable = true;
184+
nvimRuntime = true;
185+
};
186+
187+
extraPlugins = [
188+
# Python 3 dependencies
189+
(pkgs.vimPlugins.nvim-lspconfig.overrideAttrs { passthru.python3Dependencies = ps: [ ps.pyyaml ]; })
190+
];
191+
192+
extraConfigLuaPost = ''
193+
${isByteCompiledFun}
194+
195+
-- vim namespace is working
196+
vim.opt.tabstop = 2
197+
vim.api.nvim_get_runtime_file("init.lua", false)
198+
vim.lsp.get_clients()
199+
vim.treesitter.language.get_filetypes("nix")
200+
vim.iter({})
201+
202+
test_rtp_file("lua/vim/lsp.lua", true)
203+
test_rtp_file("lua/vim/iter.lua", true)
204+
test_rtp_file("lua/vim/treesitter/query.lua", true)
205+
test_rtp_file("lua/vim/lsp/buf.lua", true)
206+
test_rtp_file("plugin/editorconfig.lua", true)
207+
test_rtp_file("plugin/tutor.vim", false)
208+
test_rtp_file("ftplugin/vim.vim", false)
209+
210+
-- Python3 packages are importable
211+
vim.cmd.py3("import yaml")
212+
'';
213+
};
180214
}
181215
//
182216
# Two equal tests, one with combinePlugins.enable = true

0 commit comments

Comments
 (0)