mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-24 12:45:24 +02:00
modules/performance: add an option to combine plugins to a single plugin pack
This commit is contained in:
parent
119f12db27
commit
fdb3950c59
4 changed files with 202 additions and 3 deletions
|
@ -19,6 +19,7 @@
|
|||
./lua-loader.nix
|
||||
./opts.nix
|
||||
./output.nix
|
||||
./performance.nix
|
||||
./plugins.nix
|
||||
];
|
||||
}
|
||||
|
|
54
modules/performance.nix
Normal file
54
modules/performance.nix
Normal file
|
@ -0,0 +1,54 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) types;
|
||||
in
|
||||
{
|
||||
options.performance = {
|
||||
combinePlugins = {
|
||||
enable = lib.mkEnableOption "combinePlugins" // {
|
||||
description = ''
|
||||
Whether to enable EXPERIMENTAL option to combine all plugins
|
||||
into a single plugin pack. It can significantly reduce startup time,
|
||||
but all your plugins must have unique filenames and doc tags.
|
||||
Any collision will result in a build failure.
|
||||
Only standard neovim runtime directories are linked to the combined plugin.
|
||||
If some of your plugins contain important files outside of standard
|
||||
directories, add these paths to `pathsToLink` option.
|
||||
'';
|
||||
};
|
||||
pathsToLink = lib.mkOption {
|
||||
type = with types; listOf str;
|
||||
default = [ ];
|
||||
example = [ "/data" ];
|
||||
description = "List of paths to link into a combined plugin pack.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config.performance = {
|
||||
# Set option value with default priority so that values are appended by default
|
||||
combinePlugins.pathsToLink = [
|
||||
# :h rtp
|
||||
"/autoload"
|
||||
"/colors"
|
||||
"/compiler"
|
||||
"/doc"
|
||||
"/ftplugin"
|
||||
"/indent"
|
||||
"/keymap"
|
||||
"/lang"
|
||||
"/lua"
|
||||
"/pack"
|
||||
"/parser"
|
||||
"/plugin"
|
||||
"/queries"
|
||||
"/rplugin"
|
||||
"/spell"
|
||||
"/syntax"
|
||||
"/tutor"
|
||||
"/after"
|
||||
# ftdetect
|
||||
"/ftdetect"
|
||||
];
|
||||
};
|
||||
}
|
|
@ -74,15 +74,54 @@ in
|
|||
|
||||
config =
|
||||
let
|
||||
# Plugin list extended with dependencies
|
||||
allPlugins =
|
||||
let
|
||||
pluginWithItsDeps = p: [ p ] ++ builtins.concatMap pluginWithItsDeps p.dependencies or [ ];
|
||||
in
|
||||
lib.unique (builtins.concatMap pluginWithItsDeps config.extraPlugins);
|
||||
|
||||
# All plugins with doc tags removed
|
||||
allPluginsOverridden = map (
|
||||
plugin:
|
||||
plugin.overrideAttrs (prev: {
|
||||
nativeBuildInputs = lib.remove pkgs.vimUtils.vimGenDocHook prev.nativeBuildInputs or [ ];
|
||||
configurePhase = builtins.concatStringsSep "\n" (
|
||||
builtins.filter (s: s != ":") [
|
||||
prev.configurePhase or ":"
|
||||
"rm -vf doc/tags"
|
||||
]
|
||||
);
|
||||
})
|
||||
) allPlugins;
|
||||
|
||||
# Combine all plugins into a single pack
|
||||
pluginPack = pkgs.vimUtils.toVimPlugin (
|
||||
pkgs.buildEnv {
|
||||
name = "plugin-pack";
|
||||
paths = allPluginsOverridden;
|
||||
inherit (config.performance.combinePlugins) pathsToLink;
|
||||
# Remove empty directories and activate vimGenDocHook
|
||||
postBuild = ''
|
||||
find $out -type d -empty -delete
|
||||
runHook preFixup
|
||||
'';
|
||||
}
|
||||
);
|
||||
|
||||
# Combined plugins
|
||||
combinedPlugins = [ pluginPack ];
|
||||
|
||||
# Plugins to use in finalPackage
|
||||
plugins = if config.performance.combinePlugins.enable then combinedPlugins else config.extraPlugins;
|
||||
|
||||
defaultPlugin = {
|
||||
plugin = null;
|
||||
config = "";
|
||||
optional = false;
|
||||
};
|
||||
|
||||
normalizedPlugins = map (
|
||||
x: defaultPlugin // (if x ? plugin then x else { plugin = x; })
|
||||
) config.extraPlugins;
|
||||
normalizedPlugins = map (x: defaultPlugin // (if x ? plugin then x else { plugin = x; })) plugins;
|
||||
|
||||
neovimConfig = pkgs.neovimUtils.makeNeovimConfig (
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue