modules/performance: handle plugin configs when combining plugins

This commit is contained in:
Stanislav Asunkin 2024-07-14 17:46:01 +03:00 committed by traxys
parent 27201addd7
commit d6bebcefa3
2 changed files with 89 additions and 36 deletions

View file

@ -80,7 +80,7 @@ in
let let
defaultPlugin = { defaultPlugin = {
plugin = null; plugin = null;
config = ""; config = null;
optional = false; optional = false;
}; };
in in
@ -129,8 +129,9 @@ in
deps = map (p: p.plugin.python3Dependencies or (_: [ ])) startPlugins; deps = map (p: p.plugin.python3Dependencies or (_: [ ])) startPlugins;
in in
ps: builtins.concatMap (f: f ps) deps; ps: builtins.concatMap (f: f ps) deps;
in
pkgs.vimUtils.toVimPlugin ( # Combined plugin
combinedPlugin = pkgs.vimUtils.toVimPlugin (
pkgs.buildEnv { pkgs.buildEnv {
name = "plugin-pack"; name = "plugin-pack";
paths = overriddenPlugins; paths = overriddenPlugins;
@ -146,8 +147,18 @@ in
} }
); );
# Combined plugin configs
combinedConfig = builtins.concatStringsSep "\n" (
builtins.concatMap (x: lib.optional (x.config != null && x.config != "") x.config) startPlugins
);
in
normalize {
plugin = combinedPlugin;
config = combinedConfig;
};
# Combined plugins # Combined plugins
combinedPlugins = [ (normalize pluginPack) ] ++ optPlugins; combinedPlugins = [ pluginPack ] ++ optPlugins;
# Plugins to use in finalPackage # Plugins to use in finalPackage
plugins = if config.performance.combinePlugins.enable then combinedPlugins else normalizedPlugins; plugins = if config.performance.combinePlugins.enable then combinedPlugins else normalizedPlugins;

View file

@ -1,4 +1,7 @@
{ pkgs, ... }: { pkgs, ... }:
let
pluginCount = pkg: type: builtins.length pkg.packpathDirs.myNeovimPackages.${type};
in
{ {
# Test basic functionality # Test basic functionality
default.module = default.module =
@ -25,7 +28,7 @@
''; '';
assertions = [ assertions = [
{ {
assertion = builtins.length config.finalPackage.packpathDirs.myNeovimPackages.start == 1; assertion = pluginCount config.finalPackage "start" == 1;
message = "More than one plugin is defined in packpathDirs, expected one plugin pack."; message = "More than one plugin is defined in packpathDirs, expected one plugin pack.";
} }
]; ];
@ -42,7 +45,7 @@
]; ];
assertions = [ assertions = [
{ {
assertion = builtins.length config.finalPackage.packpathDirs.myNeovimPackages.start >= 2; assertion = pluginCount config.finalPackage "start" >= 2;
message = "Only one plugin is defined in packpathDirs, expected at least two."; message = "Only one plugin is defined in packpathDirs, expected at least two.";
} }
]; ];
@ -69,7 +72,7 @@
''; '';
assertions = [ assertions = [
{ {
assertion = builtins.length config.finalPackage.packpathDirs.myNeovimPackages.start == 1; assertion = pluginCount config.finalPackage "start" == 1;
message = "More than one plugin is defined in packpathDirs."; message = "More than one plugin is defined in packpathDirs.";
} }
]; ];
@ -97,7 +100,7 @@
''; '';
assertions = [ assertions = [
{ {
assertion = builtins.length config.finalPackage.packpathDirs.myNeovimPackages.start == 1; assertion = pluginCount config.finalPackage "start" == 1;
message = "More than one plugin is defined in packpathDirs."; message = "More than one plugin is defined in packpathDirs.";
} }
]; ];
@ -124,7 +127,7 @@
''; '';
assertions = [ assertions = [
{ {
assertion = builtins.length config.finalPackage.packpathDirs.myNeovimPackages.start == 1; assertion = pluginCount config.finalPackage "start" == 1;
message = "More than one plugin is defined in packpathDirs."; message = "More than one plugin is defined in packpathDirs.";
} }
]; ];
@ -176,19 +179,58 @@
"plenary-nvim is duplicated" "plenary-nvim is duplicated"
) )
''; '';
assertions = assertions = [
let
packages = config.finalPackage.packpathDirs.myNeovimPackages;
in
[
{ {
assertion = builtins.length packages.start == 1; assertion = pluginCount config.finalPackage "start" == 1;
message = "More than one start plugin is defined in packpathDirs"; message = "More than one start plugin is defined in packpathDirs";
} }
{ {
assertion = builtins.length packages.opt == 2; assertion = pluginCount config.finalPackage "opt" == 2;
message = "Less than two opt plugins are defined in packpathDirs"; message = "Less than two opt plugins are defined in packpathDirs";
} }
]; ];
}; };
# Test that plugin configs are handled
configs.module =
{ config, ... }:
{
performance.combinePlugins.enable = true;
extraPlugins = with pkgs.vimPlugins; [
# A plugin without config
plenary-nvim
# Plugins with configs
{
plugin = nvim-treesitter;
config = "let g:treesitter_config = 1";
}
{
plugin = nvim-lspconfig;
config = "let g:lspconfig_config = 1";
}
# Optional plugin with config
{
plugin = telescope-nvim;
optional = true;
config = "let g:telescope_config = 1";
}
];
extraConfigLuaPost = ''
-- Plugins are loadable
require("plenary")
require("nvim-treesitter")
require("lspconfig")
-- Configs are evaluated
assert(vim.g.treesitter_config == 1, "nvim-treesitter config isn't evaluated")
assert(vim.g.lspconfig_config == 1, "nvim-lspconfig config isn't evaluated")
assert(vim.g.telescope_config == 1, "telescope-nvim config isn't evaluated")
'';
assertions = [
{
assertion = pluginCount config.finalPackage "start" == 1;
message = "More than one start plugin is defined in packpathDirs";
}
];
};
} }