2022-09-18 11:19:23 +01:00
|
|
|
{
|
2023-02-20 11:42:13 +01:00
|
|
|
lib,
|
2023-11-06 15:04:08 +01:00
|
|
|
helpers,
|
|
|
|
config,
|
|
|
|
pkgs,
|
2023-02-20 11:42:13 +01:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.plugins.packer;
|
|
|
|
in {
|
2021-03-18 14:03:17 +00:00
|
|
|
options = {
|
2022-09-18 11:19:23 +01:00
|
|
|
plugins.packer = {
|
2023-01-22 03:32:08 +00:00
|
|
|
enable = mkEnableOption "packer.nvim";
|
2021-03-18 14:03:17 +00:00
|
|
|
|
2023-03-12 18:23:23 +01:00
|
|
|
plugins = with types; let
|
|
|
|
pluginType =
|
|
|
|
either
|
|
|
|
str
|
|
|
|
(submodule {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Name of the plugin to install";
|
2023-02-20 11:42:13 +01:00
|
|
|
};
|
2023-03-12 18:23:23 +01:00
|
|
|
|
|
|
|
disable = helpers.mkNullOrOption bool "Mark plugin as inactive";
|
|
|
|
|
|
|
|
as =
|
|
|
|
helpers.mkNullOrOption str
|
|
|
|
"Specifies an alias under which to install the plugin";
|
|
|
|
|
2023-12-29 15:24:42 +01:00
|
|
|
installer = helpers.defaultNullOpts.mkLuaFn "nil" "A custom installer";
|
2023-03-12 18:23:23 +01:00
|
|
|
|
2023-12-29 15:24:42 +01:00
|
|
|
updater = helpers.defaultNullOpts.mkLuaFn "nil" "A custom updater";
|
2023-03-12 18:23:23 +01:00
|
|
|
|
|
|
|
after =
|
|
|
|
helpers.mkNullOrOption (either str (listOf str))
|
|
|
|
"Plugins to load after this plugin";
|
|
|
|
|
|
|
|
rtp =
|
|
|
|
helpers.mkNullOrOption str
|
|
|
|
"Specifies a subdirectory of the plugin to add to runtimepath";
|
|
|
|
|
|
|
|
opt = helpers.mkNullOrOption bool "Marks a plugin as optional";
|
|
|
|
|
|
|
|
branch = helpers.mkNullOrOption str "Git branch to use";
|
|
|
|
|
|
|
|
tag = helpers.mkNullOrOption str "Git tag to use";
|
|
|
|
|
|
|
|
commit = helpers.mkNullOrOption str "Git commit to use";
|
|
|
|
|
|
|
|
lock = helpers.mkNullOrOption bool "Skip this plugin in updates";
|
|
|
|
|
|
|
|
run =
|
|
|
|
helpers.mkNullOrOption
|
|
|
|
(oneOf [
|
|
|
|
str
|
2024-01-01 23:33:53 +01:00
|
|
|
helpers.nixvimTypes.rawLua
|
|
|
|
(listOf (either str helpers.nixvimTypes.rawLua))
|
2023-03-12 18:23:23 +01:00
|
|
|
])
|
|
|
|
"Post-install hook";
|
|
|
|
|
2024-02-03 19:04:09 +01:00
|
|
|
requires =
|
|
|
|
helpers.mkNullOrOption (helpers.nixvimTypes.eitherRecursive str listOfPlugins)
|
|
|
|
"Plugin dependencies";
|
2023-03-12 18:23:23 +01:00
|
|
|
|
|
|
|
rocks =
|
|
|
|
helpers.mkNullOrOption (either str (listOf (either str attrs)))
|
|
|
|
"Luarocks dependencies";
|
|
|
|
|
|
|
|
config =
|
2024-01-01 23:33:53 +01:00
|
|
|
helpers.mkNullOrOption (either str helpers.nixvimTypes.rawLua)
|
2023-03-12 18:23:23 +01:00
|
|
|
"Code to run after this plugin is loaded";
|
|
|
|
|
|
|
|
setup =
|
2024-01-01 23:33:53 +01:00
|
|
|
helpers.mkNullOrOption (either str helpers.nixvimTypes.rawLua)
|
2023-03-12 18:23:23 +01:00
|
|
|
"Code to be run before this plugin is loaded";
|
|
|
|
|
|
|
|
cmd =
|
|
|
|
helpers.mkNullOrOption (either str (listOf str))
|
|
|
|
"Commands which load this plugin";
|
|
|
|
|
|
|
|
ft =
|
|
|
|
helpers.mkNullOrOption (either str (listOf str))
|
|
|
|
"Filetypes which load this plugin";
|
|
|
|
|
|
|
|
keys =
|
|
|
|
helpers.mkNullOrOption (either str (listOf str))
|
|
|
|
"Keymaps which load this plugin";
|
|
|
|
|
|
|
|
event =
|
|
|
|
helpers.mkNullOrOption (either str (listOf str))
|
|
|
|
"Autocommand events which load this plugin";
|
|
|
|
|
|
|
|
fn =
|
|
|
|
helpers.mkNullOrOption (either str (listOf str))
|
|
|
|
"Functions which load this plugin";
|
|
|
|
|
|
|
|
cond =
|
|
|
|
helpers.mkNullOrOption
|
|
|
|
(oneOf [
|
|
|
|
str
|
2024-01-01 23:33:53 +01:00
|
|
|
helpers.nixvimTypes.rawLua
|
|
|
|
(listOf (either str helpers.nixvimTypes.rawLua))
|
2023-03-12 18:23:23 +01:00
|
|
|
])
|
|
|
|
"Conditional test to load this plugin";
|
|
|
|
|
|
|
|
module =
|
|
|
|
helpers.mkNullOrOption (either str (listOf str))
|
|
|
|
"Patterns of module names which load this plugin";
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
listOfPlugins = types.listOf pluginType;
|
|
|
|
in
|
|
|
|
mkOption {
|
|
|
|
type = listOfPlugins;
|
|
|
|
default = [];
|
|
|
|
description = "List of plugins";
|
|
|
|
};
|
|
|
|
|
|
|
|
rockPlugins = mkOption {
|
|
|
|
type = with types; listOf (either str attrs);
|
|
|
|
description = "List of lua rock plugins";
|
2023-02-20 11:42:13 +01:00
|
|
|
default = [];
|
2023-03-12 18:23:23 +01:00
|
|
|
example = ''
|
|
|
|
[
|
|
|
|
"penlight"
|
|
|
|
"lua-resty-http"
|
|
|
|
"lpeg"
|
|
|
|
]
|
|
|
|
'';
|
2021-03-18 14:03:17 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-02-20 11:42:13 +01:00
|
|
|
extraPlugins = [(pkgs.vimPlugins.packer-nvim.overrideAttrs (_: {pname = "packer.nvim";}))];
|
|
|
|
extraPackages = [pkgs.git];
|
2021-03-18 14:03:17 +00:00
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
extraConfigLua = let
|
2023-03-12 18:23:23 +01:00
|
|
|
luaRockPluginToLua = luaRockPlugin:
|
|
|
|
if isAttrs luaRockPlugin
|
|
|
|
then
|
|
|
|
mapAttrs'
|
|
|
|
(k: v: {
|
|
|
|
name =
|
|
|
|
if k == "name"
|
2023-10-09 08:50:21 -05:00
|
|
|
then "__unkeyed"
|
2023-03-12 18:23:23 +01:00
|
|
|
else k;
|
|
|
|
value = v;
|
|
|
|
})
|
|
|
|
luaRockPlugin
|
|
|
|
else luaRockPlugin;
|
|
|
|
luaRockListToLua = map luaRockPluginToLua;
|
|
|
|
|
|
|
|
pluginToLua = plugin:
|
|
|
|
if isAttrs plugin
|
|
|
|
then {
|
2023-10-09 08:50:21 -05:00
|
|
|
"__unkeyed" = plugin.name;
|
2023-03-12 18:23:23 +01:00
|
|
|
|
|
|
|
inherit
|
|
|
|
(plugin)
|
2023-12-29 15:24:42 +01:00
|
|
|
disable
|
|
|
|
as
|
|
|
|
installer
|
|
|
|
updater
|
2023-03-12 18:23:23 +01:00
|
|
|
after
|
|
|
|
rtp
|
|
|
|
opt
|
|
|
|
branch
|
|
|
|
tag
|
|
|
|
commit
|
|
|
|
lock
|
|
|
|
run
|
|
|
|
;
|
|
|
|
|
|
|
|
requires =
|
|
|
|
helpers.ifNonNull' plugin.requires
|
|
|
|
(
|
|
|
|
if isList plugin.requires
|
|
|
|
then (pluginListToLua plugin.requires)
|
|
|
|
else plugin.requires
|
|
|
|
);
|
|
|
|
|
|
|
|
rocks =
|
|
|
|
helpers.ifNonNull' plugin.rocks
|
|
|
|
(
|
|
|
|
if isList plugin.rocks
|
|
|
|
then luaRockListToLua plugin.rocks
|
|
|
|
else plugin.rocks
|
|
|
|
);
|
|
|
|
|
|
|
|
inherit
|
|
|
|
(plugin)
|
|
|
|
config
|
|
|
|
setup
|
|
|
|
cmd
|
|
|
|
ft
|
|
|
|
keys
|
|
|
|
event
|
|
|
|
fn
|
|
|
|
cond
|
|
|
|
module
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else plugin;
|
|
|
|
|
|
|
|
pluginListToLua = map pluginToLua;
|
|
|
|
|
|
|
|
plugins = pluginListToLua cfg.plugins;
|
|
|
|
|
2023-02-20 11:42:13 +01:00
|
|
|
packedPlugins =
|
|
|
|
if length plugins == 1
|
|
|
|
then head plugins
|
|
|
|
else plugins;
|
2023-03-12 18:23:23 +01:00
|
|
|
|
|
|
|
luaRockPlugins = luaRockListToLua cfg.rockPlugins;
|
2023-03-18 16:26:00 +01:00
|
|
|
luaRocksString =
|
|
|
|
optionalString (cfg.rockPlugins != [])
|
|
|
|
"use_rocks ${helpers.toLuaObject luaRockPlugins}";
|
2023-02-20 11:42:13 +01:00
|
|
|
in
|
|
|
|
mkIf (cfg.plugins != []) ''
|
2021-03-18 14:03:17 +00:00
|
|
|
require('packer').startup(function()
|
|
|
|
use ${helpers.toLuaObject packedPlugins}
|
2023-03-18 16:26:00 +01:00
|
|
|
${luaRocksString}
|
2021-03-18 14:03:17 +00:00
|
|
|
end)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|