1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-11-09 03:56:05 +01:00

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`.
This commit is contained in:
Matt Sturgeon 2025-09-10 00:36:43 +01:00 committed by Gaétan Lepage
parent 51edc33c97
commit 79533f91c1

View file

@ -92,21 +92,38 @@
maintainers, maintainers,
description, description,
url ? null, url ? null,
}@args: }:
{ options, ... }: { options, ... }:
let let
opts = lib.getAttrFromPath loc options; opts = lib.getAttrFromPath loc options;
url =
if args.url or null == null then # We merge the url from the plugin definition and the url from the
opts.package.default.meta.homepage or (throw "unable to get URL for `${lib.showOption loc}`.") # package's meta.homepage using the module system.
else # This validates things like conflicting definitions.
args.url; 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 in
{ {
meta = { meta = {
inherit maintainers; inherit maintainers;
nixvimInfo = { nixvimInfo = {
inherit description url; inherit description;
url = urls.mergedValue;
path = loc; path = loc;
}; };
}; };