nvf/lib/types/plugins.nix

242 lines
5.9 KiB
Nix
Raw Normal View History

2024-04-08 00:28:49 +00:00
{
inputs,
lib,
...
}: let
inherit (lib.options) mkOption;
inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair;
inherit (lib.strings) hasPrefix removePrefix;
2024-08-01 20:33:51 +00:00
inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf bool;
2024-04-08 00:28:49 +00:00
# Get the names of all flake inputs that start with the given prefix.
2024-04-09 06:55:45 +00:00
fromInputs = {
inputs,
prefix,
}:
2024-04-08 00:28:49 +00:00
mapAttrs' (n: v: nameValuePair (removePrefix prefix n) {src = v;}) (filterAttrs (n: _: hasPrefix prefix n) inputs);
# Get the names of all flake inputs that start with the given prefix.
2024-04-09 06:55:45 +00:00
pluginInputNames = attrNames (fromInputs {
inherit inputs;
prefix = "plugin-";
});
2024-04-08 00:28:49 +00:00
2023-02-06 18:57:35 +00:00
# You can either use the name of the plugin or a package.
2024-04-08 00:28:49 +00:00
pluginType = nullOr (
either
package
2024-04-09 06:55:45 +00:00
(enum (pluginInputNames ++ ["nvim-treesitter" "flutter-tools-patched" "vim-repeat"]))
2024-04-08 00:28:49 +00:00
);
2024-04-08 00:28:49 +00:00
pluginsType = listOf pluginType;
2024-04-08 00:28:49 +00:00
extraPluginType = submodule {
options = {
package = mkOption {
type = pluginType;
description = "Plugin Package.";
};
2024-02-17 00:19:38 +00:00
2024-04-08 00:28:49 +00:00
after = mkOption {
type = listOf str;
default = [];
description = "Setup this plugin after the following ones.";
};
2024-02-17 00:19:38 +00:00
2024-04-08 00:28:49 +00:00
setup = mkOption {
type = lines;
default = "";
description = "Lua code to run during setup.";
example = "require('aerial').setup {}";
};
};
2024-04-08 00:28:49 +00:00
};
2024-06-25 15:47:33 +00:00
luaInline = lib.mkOptionType {
name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x;
};
2024-08-01 20:33:51 +00:00
lznKeysSpec = submodule {
options = {
desc = mkOption {
description = "Description of the key map";
type = nullOr str;
default = null;
};
noremap = mkOption {
description = "TBD";
type = bool;
default = false;
};
expr = mkOption {
description = "TBD";
type = bool;
default = false;
};
nowait = mkOption {
description = "TBD";
type = bool;
default = false;
};
ft = mkOption {
description = "TBD";
type = nullOr (listOf str);
default = null;
};
lhs = mkOption {
type = str;
description = "Key to bind to";
};
rhs = mkOption {
type = nullOr str;
default = null;
description = "Action to trigger";
};
mode = mkOption {
description = "Modes to bind in";
type = listOf str;
2024-08-02 11:10:20 +00:00
default = ["n" "x" "s" "o"];
2024-08-01 20:33:51 +00:00
};
};
};
2024-07-09 23:40:11 +00:00
lznPluginTableType = attrsOf lznPluginType;
2024-06-25 15:47:33 +00:00
lznPluginType = submodule {
options = {
## Should probably infer from the actual plugin somehow
## In general this is the name passed to packadd, so the dir name of the plugin
# name = mkOption {
# type= str;
# }
2024-07-24 10:52:47 +00:00
# Non-lz.n options
2024-07-09 23:40:11 +00:00
package = mkOption {
type = pluginType;
2024-07-24 10:52:47 +00:00
description = "Plugin package";
};
setupModule = mkOption {
type = nullOr str;
description = "Lua module to run setup function on.";
default = null;
2024-07-09 23:40:11 +00:00
};
2024-06-25 15:47:33 +00:00
2024-07-24 10:52:47 +00:00
setupOpts = mkOption {
type = submodule {freeformType = attrsOf anything;};
description = "Options to pass to the setup function";
default = {};
};
# lz.n options
2024-06-25 15:47:33 +00:00
before = mkOption {
type = nullOr str;
description = "Lua code to run before plugin is loaded. This will be wrapped in a function.";
2024-06-25 15:47:33 +00:00
default = null;
};
after = mkOption {
type = nullOr str;
description = "Lua code to run after plugin is loaded. This will be wrapped in a function.";
2024-06-25 15:47:33 +00:00
default = null;
};
event = mkOption {
description = "Lazy-load on event";
2024-07-09 23:40:11 +00:00
default = null;
2024-06-25 15:47:33 +00:00
type = let
event = submodule {
options = {
event = mkOption {
type = nullOr (either str (listOf str));
description = "Exact event name";
example = "BufEnter";
};
pattern = mkOption {
type = nullOr (either str (listOf str));
description = "Event pattern";
example = "BufEnter *.lua";
};
};
};
in
2024-07-09 23:40:11 +00:00
nullOr (oneOf [str (listOf str) event]);
2024-06-25 15:47:33 +00:00
};
cmd = mkOption {
description = "Lazy-load on command";
default = null;
type = nullOr (either str (listOf str));
};
ft = mkOption {
description = "Lazy-load on filetype";
default = null;
type = nullOr (either str (listOf str));
};
keys = mkOption {
description = "Lazy-load on key mapping";
default = null;
2024-08-03 14:38:42 +00:00
type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]);
example = ''
keys = [
{lhs = "<leader>s"; rhs = ":NvimTreeToggle<cr>"; desc = "Toggle NvimTree"}
]
'';
2024-06-25 15:47:33 +00:00
};
# TODO: enabled, beforeAll, colorscheme, priority, load
};
};
2023-02-06 18:57:35 +00:00
in {
2024-07-09 23:40:11 +00:00
inherit extraPluginType fromInputs pluginType luaInline lznPluginType lznPluginTableType;
2023-02-06 18:57:35 +00:00
pluginsOpt = {
description,
example,
2023-02-06 18:57:35 +00:00
default ? [],
}:
mkOption {
inherit example description default;
2023-02-06 18:57:35 +00:00
type = pluginsType;
};
2024-04-08 00:28:49 +00:00
/*
opts is a attrset of options, example:
```
mkPluginSetupOption "telescope" {
file_ignore_patterns = mkOption {
description = "...";
type = types.listOf types.str;
default = [];
};
layout_config.horizontal = mkOption {...};
}
```
*/
mkPluginSetupOption = pluginName: opts:
mkOption {
2024-04-20 12:24:00 +00:00
description = ''
Option table to pass into the setup function of ${pluginName}
2024-04-20 12:24:00 +00:00
You can pass in any additional options even if they're
not listed in the docs
2024-04-20 12:24:00 +00:00
'';
default = {};
2024-04-08 00:28:49 +00:00
type = submodule {
freeformType = attrsOf anything;
options = opts;
};
};
2023-02-06 18:57:35 +00:00
}