nixos, lib: implement relatedPackages option
This allows one to specify "related packages" in NixOS that get rendered into the configuration.nix(5) man page. The interface philosophy is pretty much stolen from TeX bibliography. See the next several commits for examples.
This commit is contained in:
parent
a7d75ab648
commit
660806066a
|
@ -14,6 +14,7 @@ rec {
|
||||||
, defaultText ? null # Textual representation of the default, for in the manual.
|
, defaultText ? null # Textual representation of the default, for in the manual.
|
||||||
, example ? null # Example value used in the manual.
|
, example ? null # Example value used in the manual.
|
||||||
, description ? null # String describing the option.
|
, description ? null # String describing the option.
|
||||||
|
, relatedPackages ? null # Related packages used in the manual (see `genRelatedPackages` in ../nixos/doc/manual/default.nix).
|
||||||
, type ? null # Option type, providing type-checking and value merging.
|
, type ? null # Option type, providing type-checking and value merging.
|
||||||
, apply ? null # Function that converts the option value to something else.
|
, apply ? null # Function that converts the option value to something else.
|
||||||
, internal ? null # Whether the option is for NixOS developers only.
|
, internal ? null # Whether the option is for NixOS developers only.
|
||||||
|
@ -76,7 +77,6 @@ rec {
|
||||||
getValues = map (x: x.value);
|
getValues = map (x: x.value);
|
||||||
getFiles = map (x: x.file);
|
getFiles = map (x: x.file);
|
||||||
|
|
||||||
|
|
||||||
# Generate documentation template from the list of option declaration like
|
# Generate documentation template from the list of option declaration like
|
||||||
# the set generated with filterOptionSets.
|
# the set generated with filterOptionSets.
|
||||||
optionAttrSetToDocList = optionAttrSetToDocList' [];
|
optionAttrSetToDocList = optionAttrSetToDocList' [];
|
||||||
|
@ -93,9 +93,10 @@ rec {
|
||||||
readOnly = opt.readOnly or false;
|
readOnly = opt.readOnly or false;
|
||||||
type = opt.type.description or null;
|
type = opt.type.description or null;
|
||||||
}
|
}
|
||||||
// (if opt ? example then { example = scrubOptionValue opt.example; } else {})
|
// optionalAttrs (opt ? example) { example = scrubOptionValue opt.example; }
|
||||||
// (if opt ? default then { default = scrubOptionValue opt.default; } else {})
|
// optionalAttrs (opt ? default) { default = scrubOptionValue opt.default; }
|
||||||
// (if opt ? defaultText then { default = opt.defaultText; } else {});
|
// optionalAttrs (opt ? defaultText) { default = opt.defaultText; }
|
||||||
|
// optionalAttrs (opt ? relatedPackages && opt.relatedPackages != null) { inherit (opt) relatedPackages; };
|
||||||
|
|
||||||
subOptions =
|
subOptions =
|
||||||
let ss = opt.type.getSubOptions opt.loc;
|
let ss = opt.type.getSubOptions opt.loc;
|
||||||
|
|
|
@ -15,13 +15,43 @@ let
|
||||||
else if lib.isFunction x then "<function>"
|
else if lib.isFunction x then "<function>"
|
||||||
else x;
|
else x;
|
||||||
|
|
||||||
# Clean up declaration sites to not refer to the NixOS source tree.
|
# Generate DocBook documentation for a list of packages. This is
|
||||||
|
# what `relatedPackages` option of `mkOption` from
|
||||||
|
# ../../../lib/options.nix influences.
|
||||||
|
#
|
||||||
|
# Each element of `relatedPackages` can be either
|
||||||
|
# - a string: that will be interpreted as an attribute name from `pkgs`,
|
||||||
|
# - a list: that will be interpreted as an attribute path from `pkgs`,
|
||||||
|
# - an attrset: that can specify `name`, `path`, `package`, `comment`
|
||||||
|
# (either of `name`, `path` is required, the rest are optional).
|
||||||
|
genRelatedPackages = packages:
|
||||||
|
let
|
||||||
|
unpack = p: if lib.isString p then { name = p; }
|
||||||
|
else if lib.isList p then { path = p; }
|
||||||
|
else p;
|
||||||
|
describe = args:
|
||||||
|
let
|
||||||
|
name = args.name or (lib.concatStringsSep "." args.path);
|
||||||
|
path = args.path or [ args.name ];
|
||||||
|
package = args.package or (lib.attrByPath path (throw "Invalid package attribute path `${toString path}'") pkgs);
|
||||||
|
in "<listitem>"
|
||||||
|
+ "<para><literal>pkgs.${name} (${package.meta.name})</literal>"
|
||||||
|
+ lib.optionalString (!package.meta.evaluates) " <emphasis>[UNAVAILABLE]</emphasis>"
|
||||||
|
+ ": ${package.meta.description or "???"}.</para>"
|
||||||
|
+ lib.optionalString (args ? comment) "\n<para>${args.comment}</para>"
|
||||||
|
# Lots of `longDescription's break DocBook, so we just wrap them into <programlisting>
|
||||||
|
+ lib.optionalString (package.meta ? longDescription) "\n<programlisting>${package.meta.longDescription}</programlisting>"
|
||||||
|
+ "</listitem>";
|
||||||
|
in "<itemizedlist>${lib.concatStringsSep "\n" (map (p: describe (unpack p)) packages)}</itemizedlist>";
|
||||||
|
|
||||||
optionsListDesc = lib.flip map optionsListVisible (opt: opt // {
|
optionsListDesc = lib.flip map optionsListVisible (opt: opt // {
|
||||||
|
# Clean up declaration sites to not refer to the NixOS source tree.
|
||||||
declarations = map stripAnyPrefixes opt.declarations;
|
declarations = map stripAnyPrefixes opt.declarations;
|
||||||
}
|
}
|
||||||
// lib.optionalAttrs (opt ? example) { example = substFunction opt.example; }
|
// lib.optionalAttrs (opt ? example) { example = substFunction opt.example; }
|
||||||
// lib.optionalAttrs (opt ? default) { default = substFunction opt.default; }
|
// lib.optionalAttrs (opt ? default) { default = substFunction opt.default; }
|
||||||
// lib.optionalAttrs (opt ? type) { type = substFunction opt.type; });
|
// lib.optionalAttrs (opt ? type) { type = substFunction opt.type; }
|
||||||
|
// lib.optionalAttrs (opt ? relatedPackages) { relatedPackages = genRelatedPackages opt.relatedPackages; });
|
||||||
|
|
||||||
# We need to strip references to /nix/store/* from options,
|
# We need to strip references to /nix/store/* from options,
|
||||||
# including any `extraSources` if some modules came from elsewhere,
|
# including any `extraSources` if some modules came from elsewhere,
|
||||||
|
|
|
@ -70,6 +70,15 @@
|
||||||
</para>
|
</para>
|
||||||
</xsl:if>
|
</xsl:if>
|
||||||
|
|
||||||
|
<xsl:if test="attr[@name = 'relatedPackages']">
|
||||||
|
<para>
|
||||||
|
<emphasis>Related packages:</emphasis>
|
||||||
|
<xsl:text> </xsl:text>
|
||||||
|
<xsl:value-of disable-output-escaping="yes"
|
||||||
|
select="attr[@name = 'relatedPackages']/string/@value" />
|
||||||
|
</para>
|
||||||
|
</xsl:if>
|
||||||
|
|
||||||
<xsl:if test="count(attr[@name = 'declarations']/list/*) != 0">
|
<xsl:if test="count(attr[@name = 'declarations']/list/*) != 0">
|
||||||
<para>
|
<para>
|
||||||
<emphasis>Declared by:</emphasis>
|
<emphasis>Declared by:</emphasis>
|
||||||
|
|
Loading…
Reference in New Issue