neovim-flake/lib/types/plugins.nix

96 lines
2.4 KiB
Nix
Raw Normal View History

2024-04-08 02:28:49 +02:00
{
inputs,
lib,
...
}: let
inherit (lib.options) mkOption;
inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair;
inherit (lib.strings) hasPrefix removePrefix isString;
inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr;
# Get the names of all flake inputs that start with the given prefix.
fromInputs = inputs: prefix:
mapAttrs' (n: v: nameValuePair (removePrefix prefix n) {src = v;}) (filterAttrs (n: _: hasPrefix prefix n) inputs);
pluginsFromInputs = attrNames (fromInputs inputs "plugin-");
# Get the names of all flake inputs that start with the given prefix.
2023-02-06 19:57:35 +01:00
# You can either use the name of the plugin or a package.
2024-04-08 02:28:49 +02:00
pluginType = nullOr (
either
package
(enum (pluginsFromInputs ++ ["nvim-treesitter" "flutter-tools-patched" "vim-repeat"]))
);
2024-04-08 02:28:49 +02:00
pluginsType = listOf pluginType;
2024-04-08 02:28:49 +02:00
extraPluginType = submodule {
options = {
package = mkOption {
type = pluginType;
description = "Plugin Package.";
};
2024-02-17 01:19:38 +01:00
2024-04-08 02:28:49 +02:00
after = mkOption {
type = listOf str;
default = [];
description = "Setup this plugin after the following ones.";
};
2024-02-17 01:19:38 +01:00
2024-04-08 02:28:49 +02:00
setup = mkOption {
type = lines;
default = "";
description = "Lua code to run during setup.";
example = "require('aerial').setup {}";
};
};
2024-04-08 02:28:49 +02:00
};
2023-02-06 19:57:35 +01:00
in {
inherit extraPluginType;
2023-02-06 19:57:35 +01:00
pluginsOpt = {
description,
default ? [],
}:
mkOption {
inherit description default;
type = pluginsType;
};
2024-03-16 10:29:07 +01:00
luaInline = lib.mkOptionType {
name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x || builtins.isString x;
2024-03-03 12:47:58 +01:00
merge = loc: defs: let
val =
if isString loc
2024-03-16 10:29:07 +01:00
then lib.generators.mkLuaInline loc
2024-03-03 12:47:58 +01:00
else loc;
in
lib.mergeOneOption val defs;
};
2024-04-08 02:28:49 +02: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 {
description = "Option table to pass into the setup function of " + pluginName;
default = {};
2024-04-08 02:28:49 +02:00
type = submodule {
freeformType = attrsOf anything;
options = opts;
};
};
2023-02-06 19:57:35 +01:00
}