From 1a5f1b43930807e1faa30c6fba814f8f2cfa3c37 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Mon, 27 Jan 2025 18:55:45 +0000 Subject: [PATCH] lib/plugins: introduce `mkMetaModule` --- lib/plugins/mk-neovim-plugin.nix | 19 +++++++++---------- lib/plugins/mk-vim-plugin.nix | 19 +++++++++---------- lib/plugins/utils.nix | 29 +++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/lib/plugins/mk-neovim-plugin.nix b/lib/plugins/mk-neovim-plugin.nix index fe92e95346..b1afd5e02c 100644 --- a/lib/plugins/mk-neovim-plugin.nix +++ b/lib/plugins/mk-neovim-plugin.nix @@ -5,7 +5,7 @@ { name, maintainers, - url ? throw "default", + url ? null, imports ? [ ], description ? null, # deprecations @@ -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; @@ -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 diff --git a/lib/plugins/mk-vim-plugin.nix b/lib/plugins/mk-vim-plugin.nix index e5a66b197b..a0d71f794f 100644 --- a/lib/plugins/mk-vim-plugin.nix +++ b/lib/plugins/mk-vim-plugin.nix @@ -4,7 +4,7 @@ }: { name, - url ? throw "default", + url ? null, maintainers, imports ? [ ], description ? null, @@ -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; @@ -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 diff --git a/lib/plugins/utils.nix b/lib/plugins/utils.nix index 505739d4de..b687e60a1d 100644 --- a/lib/plugins/utils.nix +++ b/lib/plugins/utils.nix @@ -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; + }; + }; + }; }