nixos/make-options-doc: turn relatedPackages into links

link to search.nixos.org instead of pulling package metadata out of pkgs. this
lets us cache docs of a few more modules and provides easier access to package
info from the HTML manual, but makes the manpage slightly less useful since
package description are no longer rendered.
This commit is contained in:
pennae 2021-12-18 19:21:21 +01:00
parent b92a47c87c
commit 1301bdb185
8 changed files with 18 additions and 32 deletions

View file

@ -55,10 +55,15 @@ let
# ../../../lib/options.nix influences. # ../../../lib/options.nix influences.
# #
# Each element of `relatedPackages` can be either # Each element of `relatedPackages` can be either
# - a string: that will be interpreted as an attribute name from `pkgs`, # - a string: that will be interpreted as an attribute name from `pkgs` and turned into a link
# - a list: that will be interpreted as an attribute path from `pkgs`, # to search.nixos.org,
# - an attrset: that can specify `name`, `path`, `package`, `comment` # - a list: that will be interpreted as an attribute path from `pkgs` and turned into a link
# to search.nixos.org,
# - an attrset: that can specify `name`, `path`, `comment`
# (either of `name`, `path` is required, the rest are optional). # (either of `name`, `path` is required, the rest are optional).
#
# NOTE: No checks against `pkgs` are made to ensure that the referenced package actually exists.
# Such checks are not compatible with option docs caching.
genRelatedPackages = packages: optName: genRelatedPackages = packages: optName:
let let
unpack = p: if lib.isString p then { name = p; } unpack = p: if lib.isString p then { name = p; }
@ -68,16 +73,16 @@ let
let let
title = args.title or null; title = args.title or null;
name = args.name or (lib.concatStringsSep "." args.path); name = args.name or (lib.concatStringsSep "." args.path);
path = args.path or [ args.name ]; in ''
package = args.package or (lib.attrByPath path (throw "Invalid package attribute path `${toString path}' found while evaluating `relatedPackages' of option `${optName}'") pkgs); <listitem>
in "<listitem>" <para>
+ "<para><literal>${lib.optionalString (title != null) "${title} aka "}pkgs.${name} (${package.meta.name})</literal>" <link xlink:href="https://search.nixos.org/packages?show=${name}&amp;sort=relevance&amp;query=${name}">
+ lib.optionalString (!package.meta.available) " <emphasis>[UNAVAILABLE]</emphasis>" <literal>${lib.optionalString (title != null) "${title} aka "}pkgs.${name}</literal>
+ ": ${package.meta.description or "???"}.</para>" </link>
+ lib.optionalString (args ? comment) "\n<para>${args.comment}</para>" </para>
# Lots of `longDescription's break DocBook, so we just wrap them into <programlisting> ${lib.optionalString (args ? comment) "<para>${args.comment}</para>"}
+ lib.optionalString (package.meta ? longDescription) "\n<programlisting>${package.meta.longDescription}</programlisting>" </listitem>
+ "</listitem>"; '';
in "<itemizedlist>${lib.concatStringsSep "\n" (map (p: describe (unpack p)) packages)}</itemizedlist>"; in "<itemizedlist>${lib.concatStringsSep "\n" (map (p: describe (unpack p)) packages)}</itemizedlist>";
# Remove invisible and internal options. # Remove invisible and internal options.

View file

@ -101,7 +101,4 @@ in
environment.systemPackages = packages; environment.systemPackages = packages;
}; };
# uses relatedPackages
meta.buildDocsInSandbox = false;
} }

View file

@ -7,8 +7,6 @@ let
in { in {
meta.maintainers = [ maintainers.etu ]; meta.maintainers = [ maintainers.etu ];
# uses relatedPackages
meta.buildDocsInSandbox = false;
###### interface ###### interface
options = { options = {

View file

@ -185,7 +185,4 @@ in {
imports = [ imports = [
(lib.mkRenamedOptionModule [ "programs" "tmux" "extraTmuxConf" ] [ "programs" "tmux" "extraConfig" ]) (lib.mkRenamedOptionModule [ "programs" "tmux" "extraTmuxConf" ] [ "programs" "tmux" "extraConfig" ])
]; ];
# uses relatedPackages
meta.buildDocsInSandbox = false;
} }

View file

@ -221,7 +221,4 @@ in {
boot.extraModprobeConfig = "options thinkpad_acpi experimental=1 fan_control=1"; boot.extraModprobeConfig = "options thinkpad_acpi experimental=1 fan_control=1";
}; };
# uses relatedPackages
meta.buildDocsInSandbox = false;
} }

View file

@ -228,6 +228,4 @@ in
}; };
meta.maintainers = with maintainers; [ rnhmjoj ]; meta.maintainers = with maintainers; [ rnhmjoj ];
# uses relatedPackages
meta.buildDocsInSandbox = false;
} }

View file

@ -932,6 +932,4 @@ in {
]); ]);
meta.doc = ./nextcloud.xml; meta.doc = ./nextcloud.xml;
# uses relatedPackages
meta.buildDocsInSandbox = false;
} }

View file

@ -450,8 +450,4 @@ in
}; };
}; };
# uses relatedPackages
meta.buildDocsInSandbox = false;
} }