mirror of
https://github.com/nix-community/nixvim.git
synced 2025-11-09 12:06: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:
parent
51edc33c97
commit
79533f91c1
1 changed files with 24 additions and 7 deletions
|
|
@ -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.
|
||||||
|
# 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
|
else
|
||||||
args.url;
|
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;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue