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.
This commit is contained in:
Stanislav Asunkin 2024-07-17 22:26:06 +03:00 committed by GaetanLepage
parent 55ca9d235b
commit 9314cd46f0
3 changed files with 59 additions and 1 deletions

View file

@ -21,6 +21,9 @@ in
plugins = lib.mkEnableOption "plugins" // {
description = "Whether to byte compile lua plugins.";
};
nvimRuntime = lib.mkEnableOption "nvimRuntime" // {
description = "Whether to byte compile lua files in Nvim runtime.";
};
};
combinePlugins = {

View file

@ -244,7 +244,28 @@ in
++ (optional config.wrapRc ''--add-flags -u --add-flags "${init}"'')
);
wrappedNeovim = pkgs.wrapNeovimUnstable config.package (
package =
if config.performance.byteCompileLua.enable && config.performance.byteCompileLua.nvimRuntime then
# Using symlinkJoin to avoid rebuilding neovim
pkgs.symlinkJoin {
name = "neovim-byte-compiled-${lib.getVersion config.package}";
paths = [ config.package ];
# Required attributes from original neovim package
inherit (config.package) lua;
nativeBuildInputs = [ helpers.byteCompileLuaHook ];
postBuild = ''
# Replace Nvim's binary symlink with a regular file,
# or Nvim will use original runtime directory
rm $out/bin/nvim
cp ${config.package}/bin/nvim $out/bin/nvim
runHook postFixup
'';
}
else
config.package;
wrappedNeovim = pkgs.wrapNeovimUnstable package (
neovimConfig
// {
wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " " + extraWrapperArgs;

View file

@ -182,6 +182,40 @@ in
test_rtp_file("plugin/test2.lua", false)
'';
};
nvim-runtime = {
performance.byteCompileLua = {
enable = true;
nvimRuntime = true;
};
extraPlugins = [
# Python 3 dependencies
(pkgs.vimPlugins.nvim-lspconfig.overrideAttrs { passthru.python3Dependencies = ps: [ ps.pyyaml ]; })
];
extraConfigLuaPost = ''
${isByteCompiledFun}
-- vim namespace is working
vim.opt.tabstop = 2
vim.api.nvim_get_runtime_file("init.lua", false)
vim.lsp.get_clients()
vim.treesitter.language.get_filetypes("nix")
vim.iter({})
test_rtp_file("lua/vim/lsp.lua", true)
test_rtp_file("lua/vim/iter.lua", true)
test_rtp_file("lua/vim/treesitter/query.lua", true)
test_rtp_file("lua/vim/lsp/buf.lua", true)
test_rtp_file("plugin/editorconfig.lua", true)
test_rtp_file("plugin/tutor.vim", false)
test_rtp_file("ftplugin/vim.vim", false)
-- Python3 packages are importable
vim.cmd.py3("import yaml")
'';
};
}
//
# Two equal tests, one with combinePlugins.enable = true