Skip to content

Commit 5a142a3

Browse files
committed
plugins/lazy.nvim: make pluginType freeform
1 parent 3b50eae commit 5a142a3

File tree

2 files changed

+49
-33
lines changed

2 files changed

+49
-33
lines changed

plugins/pluginmanagers/lazy.nix

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ in
4747
with types;
4848
let
4949
pluginType = either package (submodule {
50+
freeformType = types.attrsOf types.anything;
5051
options = {
5152
dir = helpers.mkNullOrOption str "A directory pointing to a local plugin";
5253

@@ -162,40 +163,47 @@ in
162163
plugin:
163164
let
164165
keyExists = keyToCheck: attrSet: lib.elem keyToCheck (lib.attrNames attrSet);
166+
converted =
167+
if isDerivation plugin then
168+
{ dir = "${lazyPath}/${lib.getName plugin}"; }
169+
else
170+
let
171+
handledPluginOptions = {
172+
"__unkeyed" = plugin.name;
173+
174+
inherit (plugin)
175+
cmd
176+
cond
177+
config
178+
dev
179+
enabled
180+
event
181+
ft
182+
init
183+
keys
184+
lazy
185+
main
186+
module
187+
name
188+
optional
189+
opts
190+
priority
191+
submodules
192+
;
193+
194+
dependencies = helpers.ifNonNull' plugin.dependencies (
195+
if isList plugin.dependencies then (pluginListToLua plugin.dependencies) else plugin.dependencies
196+
);
197+
198+
dir =
199+
if plugin ? dir && plugin.dir != null then plugin.dir else "${lazyPath}/${lib.getName plugin.pkg}";
200+
};
201+
freeformPluginOptions = lib.removeAttrs plugin ((lib.attrNames handledPluginOptions) ++ [ "pkg" ]);
202+
combinedPluginOptions = freeformPluginOptions // handledPluginOptions;
203+
in
204+
combinedPluginOptions;
165205
in
166-
if isDerivation plugin then
167-
{ dir = "${lazyPath}/${lib.getName plugin}"; }
168-
else
169-
{
170-
"__unkeyed" = plugin.name;
171-
172-
inherit (plugin)
173-
cmd
174-
cond
175-
config
176-
dev
177-
enabled
178-
event
179-
ft
180-
init
181-
keys
182-
lazy
183-
main
184-
module
185-
name
186-
optional
187-
opts
188-
priority
189-
submodules
190-
;
191-
192-
dependencies = helpers.ifNonNull' plugin.dependencies (
193-
if isList plugin.dependencies then (pluginListToLua plugin.dependencies) else plugin.dependencies
194-
);
195-
196-
dir =
197-
if plugin ? dir && plugin.dir != null then plugin.dir else "${lazyPath}/${lib.getName plugin.pkg}";
198-
};
206+
converted;
199207

200208
pluginListToLua = map pluginToLua;
201209

tests/test-sources/plugins/pluginmanagers/lazy.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
plugins = [
2929
vim-closer
3030

31+
# Test freeform
32+
{
33+
pkg = vim-dispatch;
34+
# The below is not actually a property in the `lazy.nvim` plugin spec
35+
# but is purely to test freeform capabilities of the `pluginType`.
36+
blah = "test";
37+
}
38+
3139
# Load on specific commands
3240
{
3341
pkg = vim-dispatch;

0 commit comments

Comments
 (0)