Skip to content

lib/plugins: introduce mkMetaModule #2925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/plugins/mk-neovim-plugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
name,
maintainers,
url ? throw "default",
url ? null,
imports ? [ ],
description ? null,
# deprecations
Expand Down Expand Up @@ -62,15 +62,6 @@ let
luaConfigAtLocation = utils.mkConfigAt configLocation cfg.luaConfig.content;
in
{
meta = {
inherit maintainers;
nixvimInfo = {
inherit description;
url = args.url or opts.package.default.meta.homepage;
path = loc;
};
};

options = lib.setAttrByPath loc (
{
enable = lib.mkEnableOption packPathName;
Expand Down Expand Up @@ -168,6 +159,14 @@ in
++ [
module
(utils.mkPluginPackageModule { inherit loc packPathName package; })
(utils.mkMetaModule {
inherit
loc
maintainers
description
url
;
})
]
++ lib.optional deprecateExtraOptions (
lib.mkRenamedOptionModule (loc ++ [ "extraOptions" ]) settingsPath
Expand Down
19 changes: 9 additions & 10 deletions lib/plugins/mk-vim-plugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}:
{
name,
url ? throw "default",
url ? null,
maintainers,
imports ? [ ],
description ? null,
Expand Down Expand Up @@ -55,15 +55,6 @@ let
opts = lib.getAttrFromPath loc options;
in
{
meta = {
inherit maintainers;
nixvimInfo = {
inherit description;
url = args.url or opts.package.default.meta.homepage;
path = loc;
};
};

options = lib.setAttrByPath loc (
{
enable = lib.mkEnableOption packPathName;
Expand Down Expand Up @@ -100,6 +91,14 @@ in
++ [
module
(lib.nixvim.plugins.utils.mkPluginPackageModule { inherit loc packPathName package; })
(lib.nixvim.plugins.utils.mkMetaModule {
inherit
loc
maintainers
description
url
;
})
]
++ lib.optional (deprecateExtraConfig && createSettingsOption) (
lib.mkRenamedOptionModule (loc ++ [ "extraConfig" ]) settingsPath
Expand Down
29 changes: 29 additions & 0 deletions lib/plugins/utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,33 @@
];
};
};

/**
Produce a module that defines a plugin's metadata.
*/
mkMetaModule =
{
loc,
maintainers,
description,
url ? null,
}@args:
{ options, ... }:
let
opts = lib.getAttrFromPath loc options;
url =
if args.url or null == null then
opts.package.default.meta.homepage or (throw "unable to get URL for `${lib.showOption loc}`.")
else
args.url;
in
{
meta = {
inherit maintainers;
nixvimInfo = {
inherit description url;
path = loc;
};
};
};
}