nix-community.nixvim/plugins/pluginmanagers/packer.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

196 lines
5.6 KiB
Nix
Raw Permalink Normal View History

{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
cfg = config.plugins.packer;
in
{
2021-03-18 14:03:17 +00:00
options = {
plugins.packer = {
2023-01-22 03:32:08 +00:00
enable = mkEnableOption "packer.nvim";
2021-03-18 14:03:17 +00:00
2024-08-29 14:18:59 -05:00
package = lib.mkPackageOption pkgs [
"vimPlugins"
"packer-nvim"
] { };
gitPackage = lib.mkPackageOption pkgs "git" {
nullable = true;
2024-08-29 11:22:41 -05:00
};
plugins =
with types;
let
pluginType = either str (submodule {
options = {
name = mkOption {
type = str;
description = "Name of the plugin to install";
};
disable = helpers.mkNullOrOption bool "Mark plugin as inactive";
as = helpers.mkNullOrOption str "Specifies an alias under which to install the plugin";
installer = helpers.defaultNullOpts.mkLuaFn "nil" "A custom installer";
updater = helpers.defaultNullOpts.mkLuaFn "nil" "A custom updater";
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-09-27 08:07:20 +01:00
rawLua
(listOf (either str rawLua))
]) "Post-install hook";
2024-05-05 19:39:35 +02:00
2024-09-27 08:07:20 +01:00
requires = helpers.mkNullOrOption (eitherRecursive str listOfPlugins) "Plugin dependencies";
2024-05-05 19:39:35 +02:00
rocks = helpers.mkNullOrOption (either str (listOf (either str attrs))) "Luarocks dependencies";
2024-05-05 19:39:35 +02:00
2024-09-27 08:07:20 +01:00
config = helpers.mkNullOrOption (either str rawLua) "Code to run after this plugin is loaded";
2024-05-05 19:39:35 +02:00
2024-09-27 08:07:20 +01:00
setup = helpers.mkNullOrOption (either str rawLua) "Code to be run before this plugin is loaded";
2024-05-05 19:39:35 +02:00
cmd = helpers.mkNullOrOption (either str (listOf str)) "Commands which load this plugin";
2024-05-05 19:39:35 +02:00
ft = helpers.mkNullOrOption (either str (listOf str)) "Filetypes which load this plugin";
2024-05-05 19:39:35 +02:00
keys = helpers.mkNullOrOption (either str (listOf str)) "Keymaps which load this plugin";
2024-05-05 19:39:35 +02:00
event = helpers.mkNullOrOption (either str (listOf str)) "Autocommand events which load this plugin";
2024-05-05 19:39:35 +02:00
fn = helpers.mkNullOrOption (either str (listOf str)) "Functions which load this plugin";
2024-05-05 19:39:35 +02:00
cond = helpers.mkNullOrOption (oneOf [
str
2024-09-27 08:07:20 +01:00
rawLua
(listOf (either str rawLua))
]) "Conditional test to load this plugin";
2024-05-05 19:39:35 +02:00
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";
default = [ ];
example = ''
[
"penlight"
"lua-resty-http"
"lpeg"
]
'';
2021-03-18 14:03:17 +00:00
};
};
};
config = mkIf cfg.enable {
2024-08-29 14:18:59 -05:00
extraPlugins = [ cfg.package ];
2024-08-29 11:22:41 -05:00
extraPackages = [ cfg.gitPackage ];
2024-05-05 19:39:35 +02:00
extraConfigLua =
let
luaRockPluginToLua =
luaRockPlugin:
if isAttrs luaRockPlugin then
mapAttrs' (k: v: {
name = if k == "name" then "__unkeyed" else k;
value = v;
}) luaRockPlugin
else
luaRockPlugin;
luaRockListToLua = map luaRockPluginToLua;
2024-05-05 19:39:35 +02:00
pluginToLua =
plugin:
if isAttrs plugin then
{
"__unkeyed" = plugin.name;
2024-05-05 19:39:35 +02:00
inherit (plugin)
disable
as
installer
updater
after
rtp
opt
branch
tag
commit
lock
run
;
2024-05-05 19:39:35 +02:00
requires = helpers.ifNonNull' plugin.requires (
if isList plugin.requires then (pluginListToLua plugin.requires) else plugin.requires
);
2024-05-05 19:39:35 +02:00
rocks = helpers.ifNonNull' plugin.rocks (
if isList plugin.rocks then luaRockListToLua plugin.rocks else plugin.rocks
);
2024-05-05 19:39:35 +02:00
inherit (plugin)
config
setup
cmd
ft
keys
event
fn
cond
module
;
}
else
plugin;
2024-05-05 19:39:35 +02:00
pluginListToLua = map pluginToLua;
2024-05-05 19:39:35 +02:00
plugins = pluginListToLua cfg.plugins;
2024-05-05 19:39:35 +02:00
packedPlugins = if length plugins == 1 then head plugins else plugins;
2024-05-05 19:39:35 +02:00
luaRockPlugins = luaRockListToLua cfg.rockPlugins;
luaRocksString = optionalString (
cfg.rockPlugins != [ ]
) "use_rocks ${helpers.toLuaObject luaRockPlugins}";
in
mkIf (cfg.plugins != [ ]) ''
2021-03-18 14:03:17 +00:00
require('packer').startup(function()
use ${helpers.toLuaObject packedPlugins}
${luaRocksString}
2021-03-18 14:03:17 +00:00
end)
'';
};
}