Skip to content

Commit 1a5f1b4

Browse files
committed
lib/plugins: introduce mkMetaModule
1 parent e908e34 commit 1a5f1b4

File tree

3 files changed

+47
-20
lines changed

3 files changed

+47
-20
lines changed

lib/plugins/mk-neovim-plugin.nix

+9-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
name,
77
maintainers,
8-
url ? throw "default",
8+
url ? null,
99
imports ? [ ],
1010
description ? null,
1111
# deprecations
@@ -62,15 +62,6 @@ let
6262
luaConfigAtLocation = utils.mkConfigAt configLocation cfg.luaConfig.content;
6363
in
6464
{
65-
meta = {
66-
inherit maintainers;
67-
nixvimInfo = {
68-
inherit description;
69-
url = args.url or opts.package.default.meta.homepage;
70-
path = loc;
71-
};
72-
};
73-
7465
options = lib.setAttrByPath loc (
7566
{
7667
enable = lib.mkEnableOption packPathName;
@@ -168,6 +159,14 @@ in
168159
++ [
169160
module
170161
(utils.mkPluginPackageModule { inherit loc packPathName package; })
162+
(utils.mkMetaModule {
163+
inherit
164+
loc
165+
maintainers
166+
description
167+
url
168+
;
169+
})
171170
]
172171
++ lib.optional deprecateExtraOptions (
173172
lib.mkRenamedOptionModule (loc ++ [ "extraOptions" ]) settingsPath

lib/plugins/mk-vim-plugin.nix

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
}:
55
{
66
name,
7-
url ? throw "default",
7+
url ? null,
88
maintainers,
99
imports ? [ ],
1010
description ? null,
@@ -55,15 +55,6 @@ let
5555
opts = lib.getAttrFromPath loc options;
5656
in
5757
{
58-
meta = {
59-
inherit maintainers;
60-
nixvimInfo = {
61-
inherit description;
62-
url = args.url or opts.package.default.meta.homepage;
63-
path = loc;
64-
};
65-
};
66-
6758
options = lib.setAttrByPath loc (
6859
{
6960
enable = lib.mkEnableOption packPathName;
@@ -100,6 +91,14 @@ in
10091
++ [
10192
module
10293
(lib.nixvim.plugins.utils.mkPluginPackageModule { inherit loc packPathName package; })
94+
(lib.nixvim.plugins.utils.mkMetaModule {
95+
inherit
96+
loc
97+
maintainers
98+
description
99+
url
100+
;
101+
})
103102
]
104103
++ lib.optional (deprecateExtraConfig && createSettingsOption) (
105104
lib.mkRenamedOptionModule (loc ++ [ "extraConfig" ]) settingsPath

lib/plugins/utils.nix

+29
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,33 @@
8282
];
8383
};
8484
};
85+
86+
/**
87+
Produce a module that defines a plugin's metadata.
88+
*/
89+
mkMetaModule =
90+
{
91+
loc,
92+
maintainers,
93+
description,
94+
url ? null,
95+
}@args:
96+
{ options, ... }:
97+
let
98+
opts = lib.getAttrFromPath loc options;
99+
url =
100+
if args.url or null == null then
101+
opts.package.default.meta.homepage or (throw "unable to get URL for `${lib.showOption loc}`.")
102+
else
103+
args.url;
104+
in
105+
{
106+
meta = {
107+
inherit maintainers;
108+
nixvimInfo = {
109+
inherit description url;
110+
path = loc;
111+
};
112+
};
113+
};
85114
}

0 commit comments

Comments
 (0)