meta: extend meta.nixvimInfo support treewide

Rather than supplying a `kind` and `name` pair, we now supply a raw
path.

This path could point to any nixvim option.
This commit is contained in:
Matt Sturgeon 2024-06-07 21:30:00 +01:00
parent b2a477260d
commit f34fda8d99
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
4 changed files with 28 additions and 23 deletions

View file

@ -67,17 +67,18 @@ let
filterAttrs (_: component: component.isOption && (isVisible component)) opts;
path = removeWhitespace (concatStringsSep "/" path);
moduleDoc =
if builtins.length path >= 2 && lib.hasAttrByPath path nixvimInfo then
let
info = lib.getAttrFromPath path nixvimInfo;
maintainers = lib.unique (options.config.meta.maintainers.${info.file} or [ ]);
maintainersNames = builtins.map (m: m.name) maintainers;
in
let
info = optionalAttrs (hasAttrByPath path nixvimInfo) (getAttrFromPath path nixvimInfo);
maintainers = lib.unique (options.config.meta.maintainers.${info.file} or [ ]);
maintainersNames = builtins.map (m: m.name) maintainers;
in
# Make sure this path has a valid info attrset
if info ? file && info ? description && info ? url then
"# ${lib.last path}\n\n"
+ (lib.optionalString (info.description != null) "${info.description}\n\n")
+ (lib.optionalString (info.url != null) "**Url:** [${info.url}](${info.url})\n\n")
+ (lib.optionalString (
builtins.length maintainers > 0
maintainers != [ ]
) "**Maintainers:** ${lib.concatStringsSep ", " maintainersNames}\n\n")
else
null;

View file

@ -26,20 +26,17 @@
with lib;
{
# Attribute may contain the following fields:
# - name: Name of the module
# - kind: Either colorschemes or plugins
# - path: Path to the module, e.g. [ "plugins" "<name>" ]
# - description: A short description of the plugin
# - url: Url for the plugin
#
# [kind name] will identify the plugin
#
# We need to use an attrs instead of a submodule to handle the merge.
options.meta.nixvimInfo = mkOption {
type = (types.nullOr types.attrs) // {
# This will create an attrset of the form:
# {
# "path"."to"."plugin" = { "<name>" = <info>; };
# }
#
# { path.to.plugin.name = <info>; }
#
#
# Where <info> is an attrset of the form:
# {
@ -52,12 +49,13 @@
lib.foldl'
(
acc: def:
lib.recursiveUpdate acc {
"${def.value.kind}"."${def.value.name}" = {
inherit (def.value) url description;
lib.recursiveUpdate acc (
setAttrByPath def.value.path {
inherit (def) file;
};
}
url = def.value.url or null;
description = def.value.description or null;
}
)
)
{
plugins = { };

View file

@ -65,8 +65,11 @@ rec {
meta = {
inherit maintainers;
nixvimInfo = {
inherit description name url;
kind = namespace;
inherit description url;
path = [
namespace
name
];
};
};

View file

@ -68,8 +68,11 @@ with lib;
meta = {
inherit maintainers;
nixvimInfo = {
inherit description name url;
kind = namespace;
inherit description url;
path = [
namespace
name
];
};
};
options.${namespace}.${name} = {