Skip to content

Commit

Permalink
modules/performance: add ability to byte compile nvim runtime directory
Browse files Browse the repository at this point in the history
This commit adds `performance.byteCompileLua.nvimRuntime` toggle that,
if enabled, byte compiles all lua files in Nvim runtime directory.
  • Loading branch information
stasjok committed Jul 26, 2024
1 parent ef04f61 commit 0ba8d21
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions modules/performance.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
23 changes: 22 additions & 1 deletion modules/top-level/output.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 34 additions & 0 deletions tests/test-sources/modules/performance/byte-compile-lua.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ba8d21

Please sign in to comment.