modules/performance: ensure dependencies of lua packages also compiled

Previously only extraLuaPackages themselves were byte-compiled, not
theirs dependencies. This commit fixes that by compiling lua packages
recursively. It uses byte-compile-lua-lib.nix shared file.
Also this commit uses the shared stub lua libraries for extraLuaPackages
byte-compiling test.
This commit is contained in:
Stanislav Asunkin 2025-05-11 12:30:50 +03:00
parent 9474ce916a
commit 75f2c1b1f1
4 changed files with 23 additions and 20 deletions

View file

@ -172,9 +172,10 @@ in
config = config =
let let
# Optionally byte compile lua library # Optionally byte compile lua library
inherit (import ./plugins/byte-compile-lua-lib.nix { inherit lib pkgs; }) byteCompileLuaPackages;
extraLuaPackages = extraLuaPackages =
if config.performance.byteCompileLua.enable && config.performance.byteCompileLua.luaLib then if config.performance.byteCompileLua.enable && config.performance.byteCompileLua.luaLib then
ps: map builders.byteCompileLuaDrv (config.extraLuaPackages ps) ps: byteCompileLuaPackages (config.extraLuaPackages ps)
else else
config.extraLuaPackages; config.extraLuaPackages;

View file

@ -1,9 +1,4 @@
/* # Utilities for byte compiling of lua dependencies
Byte compiling of lua dependencies of normalized plugin list
Inputs: List of normalized plugins
Outputs: List of normalized plugins with all the propagatedBuildInputs byte-compiled
*/
{ lib, pkgs }: { lib, pkgs }:
let let
builders = lib.nixvim.builders.withPkgs pkgs; builders = lib.nixvim.builders.withPkgs pkgs;
@ -40,4 +35,14 @@ let
# Byte-compile derivation (but only if it's a lua module) and its dependencies # Byte-compile derivation (but only if it's a lua module) and its dependencies
byteCompile = drv: byteCompileDeps (mapLuaModule builders.byteCompileLuaDrv drv); byteCompile = drv: byteCompileDeps (mapLuaModule builders.byteCompileLuaDrv drv);
in in
mapNormalizedPlugins byteCompileDeps {
# byteCompilePluginDeps compiles propagatedBuildInputs recursively
# Inputs: List of normalized plugins
# Outputs: List of normalized plugins with all the propagatedBuildInputs byte-compiled
byteCompilePluginDeps = mapNormalizedPlugins byteCompileDeps;
# byteCompileLuaPackages compiles packages and its propagatedBuildInputs
# Inputs: List of lua packages
# Outputs: List of byte-compiled packages along with all the propagatedBuildInputs
byteCompileLuaPackages = map byteCompile;
}

View file

@ -35,7 +35,7 @@ in
byteCompilePlugins = import ./byte-compile-plugins.nix { inherit lib pkgs; }; byteCompilePlugins = import ./byte-compile-plugins.nix { inherit lib pkgs; };
shouldCompileLuaLib = byteCompileCfg.enable && byteCompileCfg.luaLib; shouldCompileLuaLib = byteCompileCfg.enable && byteCompileCfg.luaLib;
byteCompileLuaLib = import ./byte-compile-lua-lib.nix { inherit lib pkgs; }; inherit (import ./byte-compile-lua-lib.nix { inherit lib pkgs; }) byteCompilePluginDeps;
shouldCombinePlugins = config.performance.combinePlugins.enable; shouldCombinePlugins = config.performance.combinePlugins.enable;
combinePlugins = import ./combine-plugins.nix { combinePlugins = import ./combine-plugins.nix {
@ -50,7 +50,7 @@ in
lib.pipe config.extraPlugins ( lib.pipe config.extraPlugins (
[ normalizePlugins ] [ normalizePlugins ]
++ lib.optionals shouldCompilePlugins [ byteCompilePlugins ] ++ lib.optionals shouldCompilePlugins [ byteCompilePlugins ]
++ lib.optionals shouldCompileLuaLib [ byteCompileLuaLib ] ++ lib.optionals shouldCompileLuaLib [ byteCompilePluginDeps ]
++ lib.optionals shouldCombinePlugins [ combinePlugins ] ++ lib.optionals shouldCombinePlugins [ combinePlugins ]
); );
}; };

View file

@ -308,20 +308,17 @@ in
luaLib = true; luaLib = true;
}; };
extraLuaPackages = extraLuaPackages = _: pluginStubs.libPack;
ps: with ps; [
say
argparse
];
extraConfigLuaPost = '' extraConfigLuaPost = ''
${pluginStubs.libChecks}
${isByteCompiledFun} ${isByteCompiledFun}
-- Lua modules are importable and byte compiled -- Lua modules are byte-compiled
local say = require("say") ${lib.concatMapStringsSep "\n" (
test_lualib_file(say.set, true) name: "test_lualib_file(require('${name}').name, true)"
local argparse = require("argparse") ) pluginStubs.libNames}
test_lualib_file(argparse("test").parse, true)
''; '';
}; };