diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6297fa9e..7b6fc03c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,6 +63,7 @@ A template plugin can be found in (plugins/TEMPLATE.nix)[https://github.com/nix- | **callSetup** | Indicating whether to call the setup function. Useful when `setup` function needs customizations. | No | `true` | | **colorscheme** | The name of the colorscheme. | No | `name` parameter | | **configLocation** | The option location where the lua configuration should be installed. Nested option locations can be represented as a list. The location can also be wrapped using `lib.mkBefore`, `lib.mkAfter`, or `lib.mkOrder`. | No | `"extraConfigLuaPre"` if `isColorscheme` then `extraConfigLuaPre`, otherwise `"extraConfigLua"` | +| **dependencies** | A list of [`dependencies`] to enable by default with this plugin. (List of strings) | No | `[]` | | **deprecateExtraOptions** | Indicating whether to deprecate the `extraOptions` attribute. Mainly used for old plugins. | No | `false` | | **description** | A brief description of the plugin. Can also be used for non-normative documentation, warnings, tips and tricks. | No | `null` | | **extraConfig** | Additional configuration for the plugin. Either an attrset, a function accepting `cfg`, or a function accepting `cfg` and `opts`. | No | `{}` | @@ -126,6 +127,7 @@ Such plugins are usually configured via vim globals, but often have no configura | **name** | The name of the Vim plugin. | Yes | N/A | | **url** | The URL of the plugin repository. | Yes | `package` parameter's `meta.homepage` | | **colorscheme** | The name of the colorscheme. | No | `name` parameter | +| **dependencies** | A list of [`dependencies`] to enable by default with this plugin. (List of strings) | No | `[]` | | **deprecateExtraConfig** | Flag to deprecate extra configuration. | No | `false` | | **description** | A description of the plugin. Can also be used for non-normative documentation, warnings, tips and tricks. | No | `null` | | **extraConfig** | Extra configuration for the plugin. Either an attrset, a function accepting `cfg`, or a function accepting `cfg` and `opts`. | No | `{}` | @@ -316,3 +318,4 @@ considerably. To use it, just install cachix and run `cachix use nix-community`. [`mkNeovimPlugin`]: #mkneovimplugin [Writing option examples]: #writing-option-examples [Declaring plugin options]: #declaring-plugin-options +[`dependencies`]: https://nix-community.github.io/nixvim/dependencies/bat.html diff --git a/lib/plugins/mk-neovim-plugin.nix b/lib/plugins/mk-neovim-plugin.nix index b1afd5e0..9fe94bc7 100644 --- a/lib/plugins/mk-neovim-plugin.nix +++ b/lib/plugins/mk-neovim-plugin.nix @@ -27,6 +27,8 @@ # - An option will be used as-is, but should be built using `lib.mkPackageOption` # Defaults to `name`, i.e. `pkgs.vimPlugins.${name}` package ? name, + # Which dependencies to enable by default + dependencies ? [ ], settingsOptions ? { }, settingsExample ? null, settingsDescription ? "Options provided to the `require('${moduleName}')${setup}` function.", @@ -105,6 +107,8 @@ let } )) + (lib.nixvim.plugins.utils.enableDependencies dependencies) + # When lazy loading is enabled for this plugin, route its configuration to the enabled provider (lib.mkIf cfg.lazyLoad.enable { assertions = [ diff --git a/lib/plugins/mk-vim-plugin.nix b/lib/plugins/mk-vim-plugin.nix index a0d71f79..5637e70e 100644 --- a/lib/plugins/mk-vim-plugin.nix +++ b/lib/plugins/mk-vim-plugin.nix @@ -22,6 +22,8 @@ # - An option will be used as-is, but should be built using `lib.mkPackageOption` # Defaults to `name`, i.e. `pkgs.vimPlugins.${name}` package ? name, + # Which dependencies to enable by default + dependencies ? [ ], settingsOptions ? { }, settingsExample ? null, globalPrefix ? "", @@ -78,6 +80,7 @@ let inherit extraConfig cfg opts; } )) + (lib.nixvim.plugins.utils.enableDependencies dependencies) ] ); }; diff --git a/lib/plugins/utils.nix b/lib/plugins/utils.nix index b687e60a..f281b89c 100644 --- a/lib/plugins/utils.nix +++ b/lib/plugins/utils.nix @@ -111,4 +111,18 @@ }; }; }; + + enableDependencies = depsToEnable: { + dependencies = + let + enableDepConditionally = dep: { + name = dep.name or dep; + value.enable = lib.mkIf (dep.enable or true) (lib.mkDefault true); + }; + in + lib.pipe depsToEnable [ + (builtins.map enableDepConditionally) + lib.listToAttrs + ]; + }; }