From 79533f91c1c43d4f4c3dffbe1c6a48124c02a565 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 10 Sep 2025 00:36:43 +0100 Subject: [PATCH] lib/plugins: use the module system to merge URLs This asserts that we don't accidentally end up with conflicting definitions. Such conflicts must be made explicit, e.g. using `mkForce` or `mkDefault`. --- lib/plugins/utils.nix | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/plugins/utils.nix b/lib/plugins/utils.nix index f281b89c..84f30f80 100644 --- a/lib/plugins/utils.nix +++ b/lib/plugins/utils.nix @@ -92,21 +92,38 @@ 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; + + # We merge the url from the plugin definition and the url from the + # package's meta.homepage using the module system. + # This validates things like conflicting definitions. + urls = lib.modules.mergeDefinitions (loc ++ [ "url" ]) lib.types.str [ + { + value = lib.mkIf (url != null) url; + file = builtins.head opts.package.declarations; + } + { + value = lib.mkIf (opts.package ? default.meta.homepage) opts.package.default.meta.homepage; + file = + let + pos = builtins.unsafeGetAttrPos "homepage" (opts.package.default.meta or { }); + in + if pos == null then + opts.package.defaultText.text or "package" + else + pos.file + ":" + toString pos.line; + } + ]; in { meta = { inherit maintainers; nixvimInfo = { - inherit description url; + inherit description; + url = urls.mergedValue; path = loc; }; };