From 65d35db5cac209cf5acd3dfd40aee98840cfc127 Mon Sep 17 00:00:00 2001 From: Stanislav Asunkin <1353637+stasjok@users.noreply.github.com> Date: Sun, 25 May 2025 16:14:07 +0300 Subject: [PATCH] modules/performance: fix specifying combinePlugin.standalonePlugins as packages when byte compilation enabled Previously, specifying plugins as packages in the `performance.combinePlugins.standalonePlugins` option did not work when the `performance.byteCompileLua` option was also enabled. This issue was due to several package transformations performed by the `byteCompileLua` which broke package comparison. There are at least three methods to fix the issue: - Change transformation order: combine plugins first, then byte-compile them. - Compare every possible transformation when determining if plugins are standalone. - Get the name of the package and use it for comparison. The first method did not work because the current `byteCompileLuaDrv` implementation does not support symlinks to directories. The second method appears too fragile. This commit implements the third method, as it requires minimal code changes and is straightforward. The downside is that it might exclude multiple packages with the same name, although this should be rare. --- modules/top-level/plugins/combine-plugins.nix | 5 +- .../modules/performance/combine-plugins.nix | 60 ++++++++++++------- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/modules/top-level/plugins/combine-plugins.nix b/modules/top-level/plugins/combine-plugins.nix index 90d4f034..2985046c 100644 --- a/modules/top-level/plugins/combine-plugins.nix +++ b/modules/top-level/plugins/combine-plugins.nix @@ -33,9 +33,8 @@ let optPlugins = removeDeps partitionedOptStartPlugins.right; # Test if plugin shouldn't be included in plugin pack - isStandalone = - p: - builtins.elem p.plugin standalonePlugins || builtins.elem (lib.getName p.plugin) standalonePlugins; + standaloneNames = map (p: if builtins.isString p then p else lib.getName p) standalonePlugins; + isStandalone = p: builtins.elem (lib.getName p.plugin) standaloneNames; # Separated standalone and combined start plugins partitionedStandaloneStartPlugins = builtins.partition isStandalone startPlugins; diff --git a/tests/test-sources/modules/performance/combine-plugins.nix b/tests/test-sources/modules/performance/combine-plugins.nix index 7d7d8c68..9de0c848 100644 --- a/tests/test-sources/modules/performance/combine-plugins.nix +++ b/tests/test-sources/modules/performance/combine-plugins.nix @@ -8,7 +8,7 @@ let let # 'build.extraFiles' must not be combined, so exclude it from counting plugins = builtins.filter ( - p: p != config.build.extraFiles + p: lib.getName p != lib.getName config.build.extraFiles ) config.build.nvimPackage.packpathDirs.myNeovimPackages.${type}; numPlugins = builtins.length plugins; in @@ -203,11 +203,30 @@ in ]; }; + # Test if plenary.filetype is working + plenary-nvim = { + performance.combinePlugins.enable = true; + extraPlugins = [ pkgs.vimPlugins.plenary-nvim ]; + extraConfigLuaPost = '' + -- Plenary filetype detection is usable + assert(require("plenary.filetype").detect(".bashrc") == "sh", "plenary.filetype is not working") + ''; + }; +} +// # Test that config.build.extraFiles is not combined - files-plugin = + # with or without byteCompileLua.enable = true + lib.genAttrs [ "files-plugin" "files-plugin-byte-compiled" ] ( + name: { config, ... }: { - performance.combinePlugins.enable = true; + performance = { + combinePlugins.enable = true; + byteCompileLua = lib.optionalAttrs (lib.hasSuffix "byte-compiled" name) { + enable = true; + plugins = true; + }; + }; extraPlugins = with pluginStubs; [ plugin1 plugin2 @@ -242,10 +261,13 @@ in assertions = [ (expectOneStartPlugin config) ]; - }; - + } + ) +// # Test that standalonePlugins option works - standalone-plugins = + # with or without byteCompileLua.enable = true + lib.genAttrs [ "standalone-plugins" "standalone-plugins-byte-compiled" ] ( + name: { config, ... }: let standalonePlugins = [ @@ -260,9 +282,15 @@ in ]; in { - performance.combinePlugins = { - enable = true; - inherit standalonePlugins; + performance = { + combinePlugins = { + enable = true; + inherit standalonePlugins; + }; + byteCompileLua = lib.optionalAttrs (lib.hasSuffix "byte-compiled" name) { + enable = true; + plugins = true; + }; }; extraPlugins = pluginStubs.pluginPack; extraConfigLuaPost = '' @@ -295,15 +323,5 @@ in # plugin-pack and 'standalonePlugins' (expectNPlugins config "start" (builtins.length standalonePlugins + 1)) ]; - }; - - # Test if plenary.filetype is working - plenary-nvim = { - performance.combinePlugins.enable = true; - extraPlugins = [ pkgs.vimPlugins.plenary-nvim ]; - extraConfigLuaPost = '' - -- Plenary filetype detection is usable - assert(require("plenary.filetype").detect(".bashrc") == "sh", "plenary.filetype is not working") - ''; - }; -} + } + )