nix-community.nixvim/modules/top-level/plugins/combine-plugins.nix
Stanislav Asunkin 65d35db5ca 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.
2025-06-02 18:15:32 +03:00

49 lines
1.7 KiB
Nix

{
lib,
callPackage,
pathsToLink,
standalonePlugins,
}:
let
inherit (import ./utils.nix lib)
getAndNormalizeDeps
removeDeps
;
mkPluginPack = callPackage ./mk-plugin-pack.nix { inherit lib; };
in
/*
*combinePlugins* function
Take a list of combined plugins, combine the relevant ones and return the resulting list of plugins
*/
normalizedPlugins:
let
# Plugin list extended with dependencies
allPlugins =
let
pluginWithItsDeps = p: [ p ] ++ builtins.concatMap pluginWithItsDeps (getAndNormalizeDeps p);
in
lib.unique (builtins.concatMap pluginWithItsDeps normalizedPlugins);
# Separated start and opt plugins
partitionedOptStartPlugins = builtins.partition (p: p.optional) allPlugins;
startPlugins = partitionedOptStartPlugins.wrong;
# Remove opt plugin dependencies since they are already available in start plugins
optPlugins = removeDeps partitionedOptStartPlugins.right;
# Test if plugin shouldn't be included in plugin pack
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;
pluginsToCombine = partitionedStandaloneStartPlugins.wrong;
# Remove standalone plugin dependencies since they are already available in start plugins
standaloneStartPlugins = removeDeps partitionedStandaloneStartPlugins.right;
# Combine start plugins into a single pack
pluginPack = mkPluginPack { inherit pluginsToCombine pathsToLink; };
in
# Combined plugins
[ pluginPack ] ++ standaloneStartPlugins ++ optPlugins