Skip to content

Commit 9cd6533

Browse files
committed
modules/performance: add ability to byte compile nvim runtime directory
1 parent da17a2e commit 9cd6533

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
@@ -260,7 +260,28 @@ in
260260
++ (optional config.wrapRc ''--add-flags -u --add-flags "${init}"'')
261261
);
262262

263-
wrappedNeovim = pkgs.wrapNeovimUnstable config.package (
263+
package =
264+
if config.performance.byteCompileLua.enable && config.performance.byteCompileLua.nvimRuntime then
265+
# Using symlinkJoin to avoid rebuilding neovim
266+
pkgs.symlinkJoin {
267+
name = "neovim-byte-compiled-${lib.getVersion config.package}";
268+
paths = [ config.package ];
269+
# Required attributes from original neovim package
270+
inherit (config.package) lua;
271+
nativeBuildInputs = [ helpers.byteCompileLuaHook ];
272+
postBuild = ''
273+
# Replace Nvim's binary symlink with a regular file,
274+
# or Nvim will use original runtime directory
275+
rm $out/bin/nvim
276+
cp ${config.package}/bin/nvim $out/bin/nvim
277+
278+
runHook postFixup
279+
'';
280+
}
281+
else
282+
config.package;
283+
284+
wrappedNeovim = pkgs.wrapNeovimUnstable package (
264285
neovimConfig
265286
// {
266287
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
@@ -158,6 +158,40 @@ in
158158
test_rtp_file("plugin/test2.lua", false)
159159
'';
160160
};
161+
162+
nvim-runtime = {
163+
performance.byteCompileLua = {
164+
enable = true;
165+
nvimRuntime = true;
166+
};
167+
168+
extraPlugins = [
169+
# Python 3 dependencies
170+
(pkgs.vimPlugins.nvim-lspconfig.overrideAttrs { passthru.python3Dependencies = ps: [ ps.pyyaml ]; })
171+
];
172+
173+
extraConfigLuaPost = ''
174+
${isByteCompiledFun}
175+
176+
-- vim namespace is working
177+
vim.opt.tabstop = 2
178+
vim.api.nvim_get_runtime_file("init.lua", false)
179+
vim.lsp.get_clients()
180+
vim.treesitter.language.get_filetypes("nix")
181+
vim.iter({})
182+
183+
test_rtp_file("lua/vim/lsp.lua", true)
184+
test_rtp_file("lua/vim/iter.lua", true)
185+
test_rtp_file("lua/vim/treesitter/query.lua", true)
186+
test_rtp_file("lua/vim/lsp/buf.lua", true)
187+
test_rtp_file("plugin/editorconfig.lua", true)
188+
test_rtp_file("plugin/tutor.vim", false)
189+
test_rtp_file("ftplugin/vim.vim", false)
190+
191+
-- Python3 packages are importable
192+
vim.cmd.py3("import yaml")
193+
'';
194+
};
161195
}
162196
//
163197
# Two equal tests, one with combinePlugins.enable = true

0 commit comments

Comments
 (0)