diff options
author | Arseniy Seroka <jagajaga@users.noreply.github.com> | 2017-12-23 03:34:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-23 03:34:58 +0300 |
commit | 36e02645eba174dd6a76aaebc62b5095bb7005a9 (patch) | |
tree | 4d37dda40510984edef81b7d15567e8e6ece39a1 /nixos/doc | |
parent | d0bb0a2c538dbe84189da00848dd1f8d5e0deda3 (diff) | |
parent | 3be0e1bd728f2500f1e8543ebc121d3ba9dabb4d (diff) | |
download | nixlib-36e02645eba174dd6a76aaebc62b5095bb7005a9.tar nixlib-36e02645eba174dd6a76aaebc62b5095bb7005a9.tar.gz nixlib-36e02645eba174dd6a76aaebc62b5095bb7005a9.tar.bz2 nixlib-36e02645eba174dd6a76aaebc62b5095bb7005a9.tar.lz nixlib-36e02645eba174dd6a76aaebc62b5095bb7005a9.tar.xz nixlib-36e02645eba174dd6a76aaebc62b5095bb7005a9.tar.zst nixlib-36e02645eba174dd6a76aaebc62b5095bb7005a9.zip |
Merge pull request #32424 from oxij/nixos/related-packages
nixos: doc: implement related packages in the manual
Diffstat (limited to 'nixos/doc')
-rw-r--r-- | nixos/doc/manual/default.nix | 34 | ||||
-rw-r--r-- | nixos/doc/manual/options-to-docbook.xsl | 9 |
2 files changed, 40 insertions, 3 deletions
diff --git a/nixos/doc/manual/default.nix b/nixos/doc/manual/default.nix index 9bc83be66104..95363c2458f5 100644 --- a/nixos/doc/manual/default.nix +++ b/nixos/doc/manual/default.nix @@ -15,13 +15,27 @@ let else if builtins.isFunction x then "<function>" else x; - # Clean up declaration sites to not refer to the NixOS source tree. + # Generate DocBook documentation for a list of packages + genRelatedPackages = packages: + let + unpack = p: if lib.isString p then { name = p; } else p; + describe = { name, package ? pkgs.${name}, comment ? "" }: + "<listitem>" + + "<para><option>pkgs.${name}</option> (${package.name}): ${package.meta.description or "???"}.</para>" + + lib.optionalString (comment != "") "\n<para>${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>"; + optionsList' = lib.flip map optionsList (opt: opt // { + # Clean up declaration sites to not refer to the NixOS source tree. declarations = map stripAnyPrefixes opt.declarations; } // lib.optionalAttrs (opt ? example) { example = substFunction opt.example; } // 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, # including any `extraSources` if some modules came from elsewhere, @@ -32,8 +46,22 @@ let prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources); stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix) prefixesToStrip; + # Custom "less" that pushes up all the things ending in ".enable*" + # and ".package" + optionListLess = a: b: + let + splt = lib.splitString "."; + ise = lib.hasPrefix "enable"; + isp = lib.hasPrefix "package"; + cmp = lib.splitByAndCompare ise lib.compare + (lib.splitByAndCompare isp lib.compare lib.compare); + in lib.compareLists cmp (splt a) (splt b) < 0; + + # Customly sort option list for the man page. + optionsList'' = lib.sort (a: b: optionListLess a.name b.name) optionsList'; + # Convert the list of options into an XML file. - optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList'); + optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList''); optionsDocBook = runCommand "options-db.xml" {} '' optionsXML=${optionsXML} diff --git a/nixos/doc/manual/options-to-docbook.xsl b/nixos/doc/manual/options-to-docbook.xsl index 5387546b5982..7b45b233ab2a 100644 --- a/nixos/doc/manual/options-to-docbook.xsl +++ b/nixos/doc/manual/options-to-docbook.xsl @@ -70,6 +70,15 @@ </para> </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"> <para> <emphasis>Declared by:</emphasis> |