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;