Skip to content

Commit b66559d

Browse files
committed
lib/plugins/mk{Neovim,Vim}Plugin: add dependencies parameter
1 parent 89c94d9 commit b66559d

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ A template plugin can be found in (plugins/TEMPLATE.nix)[https://github.com/nix-
6363
| **callSetup** | Indicating whether to call the setup function. Useful when `setup` function needs customizations. | No | `true` |
6464
| **colorscheme** | The name of the colorscheme. | No | `name` parameter |
6565
| **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"` |
66+
| **dependencies** | A list of [`dependencies`] to enable by default with this plugin. (List of strings) | No | `[]` |
6667
| **deprecateExtraOptions** | Indicating whether to deprecate the `extraOptions` attribute. Mainly used for old plugins. | No | `false` |
6768
| **description** | A brief description of the plugin. Can also be used for non-normative documentation, warnings, tips and tricks. | No | `null` |
6869
| **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
126127
| **name** | The name of the Vim plugin. | Yes | N/A |
127128
| **url** | The URL of the plugin repository. | Yes | `package` parameter's `meta.homepage` |
128129
| **colorscheme** | The name of the colorscheme. | No | `name` parameter |
130+
| **dependencies** | A list of [`dependencies`] to enable by default with this plugin. (List of strings) | No | `[]` |
129131
| **deprecateExtraConfig** | Flag to deprecate extra configuration. | No | `false` |
130132
| **description** | A description of the plugin. Can also be used for non-normative documentation, warnings, tips and tricks. | No | `null` |
131133
| **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`.
316318
[`mkNeovimPlugin`]: #mkneovimplugin
317319
[Writing option examples]: #writing-option-examples
318320
[Declaring plugin options]: #declaring-plugin-options
321+
[`dependencies`]: https://nix-community.github.io/nixvim/dependencies/bat.html

lib/plugins/mk-neovim-plugin.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
# - An option will be used as-is, but should be built using `lib.mkPackageOption`
2828
# Defaults to `name`, i.e. `pkgs.vimPlugins.${name}`
2929
package ? name,
30+
# Which dependencies to enable by default
31+
dependencies ? [ ],
3032
settingsOptions ? { },
3133
settingsExample ? null,
3234
settingsDescription ? "Options provided to the `require('${moduleName}')${setup}` function.",
@@ -105,6 +107,8 @@ let
105107
}
106108
))
107109

110+
(lib.nixvim.plugins.utils.enableDependencies dependencies)
111+
108112
# When lazy loading is enabled for this plugin, route its configuration to the enabled provider
109113
(lib.mkIf cfg.lazyLoad.enable {
110114
assertions = [

lib/plugins/mk-vim-plugin.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
# - An option will be used as-is, but should be built using `lib.mkPackageOption`
2323
# Defaults to `name`, i.e. `pkgs.vimPlugins.${name}`
2424
package ? name,
25+
# Which dependencies to enable by default
26+
dependencies ? [ ],
2527
settingsOptions ? { },
2628
settingsExample ? null,
2729
globalPrefix ? "",
@@ -78,6 +80,7 @@ let
7880
inherit extraConfig cfg opts;
7981
}
8082
))
83+
(lib.nixvim.plugins.utils.enableDependencies dependencies)
8184
]
8285
);
8386
};

lib/plugins/utils.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,18 @@
111111
};
112112
};
113113
};
114+
115+
enableDependencies = depsToEnable: {
116+
dependencies =
117+
let
118+
enableDepConditionally = dep: {
119+
name = dep.name or dep;
120+
value.enable = lib.mkIf (dep.enable or true) (lib.mkDefault true);
121+
};
122+
in
123+
lib.pipe depsToEnable [
124+
(builtins.map enableDepConditionally)
125+
lib.listToAttrs
126+
];
127+
};
114128
}

0 commit comments

Comments
 (0)