Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc/lib-functions: remove warnings, add versions, cli #205643

Merged
merged 4 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions doc/doc-support/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@ let
inherit (pkgs) lib;
inherit (lib) hasPrefix removePrefix;

locationsXml = import ./lib-function-locations.nix { inherit pkgs nixpkgs; };
functionDocs = import ./lib-function-docs.nix { inherit locationsXml pkgs; };
libsets = [
{ name = "asserts"; description = "assertion functions"; }
{ name = "attrsets"; description = "attribute set functions"; }
{ name = "strings"; description = "string manipulation functions"; }
{ name = "versions"; description = "version string functions"; }
{ name = "trivial"; description = "miscellaneous functions"; }
{ name = "lists"; description = "list manipulation functions"; }
{ name = "debug"; description = "debugging functions"; }
{ name = "options"; description = "NixOS / nixpkgs option handling"; }
{ name = "filesystem"; description = "filesystem functions"; }
{ name = "sources"; description = "source filtering functions"; }
{ name = "cli"; description = "command-line serialization functions"; }
];

locationsXml = import ./lib-function-locations.nix { inherit pkgs nixpkgs libsets; };
functionDocs = import ./lib-function-docs.nix { inherit locationsXml pkgs libsets; };
version = pkgs.lib.version;

epub-xsl = pkgs.writeText "epub.xsl" ''
Expand Down
36 changes: 19 additions & 17 deletions doc/doc-support/lib-function-docs.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
# Generates the documentation for library functions via nixdoc. To add
# another library function file to this list, the include list in the
# file `doc/functions/library.xml` must also be updated.
ncfavier marked this conversation as resolved.
Show resolved Hide resolved
# Generates the documentation for library functions via nixdoc.

{ pkgs ? import ./.. {}, locationsXml }:
{ pkgs, locationsXml, libsets }:

with pkgs; stdenv.mkDerivation {
name = "nixpkgs-lib-docs";
src = ./../../lib;
src = ../../lib;

buildInputs = [ nixdoc ];
installPhase = ''
function docgen {
nixdoc -c "$1" -d "$2" -f "../lib/$1.nix" > "$out/$1.xml"
# TODO: wrap lib.$1 in <literal>, make nixdoc not escape it
nixdoc -c "$1" -d "lib.$1: $2" -f "$1.nix" > "$out/$1.xml"
echo "<xi:include href='$1.xml' />" >> "$out/index.xml"
}

mkdir -p $out
ln -s ${locationsXml} $out/locations.xml
mkdir -p "$out"

cat > "$out/index.xml" << 'EOF'
<?xml version="1.0" encoding="utf-8"?>
<root xmlns:xi="http://www.w3.org/2001/XInclude">
EOF

${lib.concatMapStrings ({ name, description }: ''
docgen ${name} ${lib.escapeShellArg description}
'') libsets}

docgen asserts 'Assert functions'
docgen attrsets 'Attribute-set functions'
docgen strings 'String manipulation functions'
docgen trivial 'Miscellaneous functions'
docgen lists 'List manipulation functions'
docgen debug 'Debugging functions'
docgen options 'NixOS / nixpkgs option handling'
docgen filesystem 'Filesystem functions'
docgen sources 'Source filtering functions'
echo "</root>" >> "$out/index.xml"

ln -s ${locationsXml} $out/locations.xml
'';
}
6 changes: 2 additions & 4 deletions doc/doc-support/lib-function-locations.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs ? (import ./.. { }), nixpkgs ? { }}:
{ pkgs, nixpkgs ? { }, libsets }:
let
revision = pkgs.lib.trivial.revisionWithDefault (nixpkgs.revision or "master");

Expand All @@ -16,9 +16,7 @@ let
subsetname = subsetname;
functions = libDefPos toplib.${subsetname};
})
(builtins.filter
(name: builtins.isAttrs toplib.${name})
(builtins.attrNames toplib));
(builtins.map (x: x.name) libsets);

nixpkgsLib = pkgs.lib;

Expand Down
1 change: 1 addition & 0 deletions doc/doc-support/parameters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<xsl:param name="html.script" select="'./highlightjs/highlight.pack.js ./highlightjs/loader.js'" />
<xsl:param name="xref.with.number.and.title" select="0" />
<xsl:param name="use.id.as.filename" select="1" />
<xsl:param name="generate.section.toc.level" select="1" />
<xsl:param name="toc.section.depth" select="0" />
<xsl:param name="admon.style" select="''" />
<xsl:param name="callout.graphics.extension" select="'.svg'" />
Expand Down
24 changes: 3 additions & 21 deletions doc/functions/library.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,7 @@
Nixpkgs provides a standard library at <varname>pkgs.lib</varname>, or through <code>import &lt;nixpkgs/lib&gt;</code>.
</para>

<!-- These docs are generated via nixdoc. To add another generated
library function file to this list, the file
`lib-function-docs.nix` must also be updated. -->

<xi:include href="./library/generated/asserts.xml" />

<xi:include href="./library/generated/attrsets.xml" />

<xi:include href="./library/generated/strings.xml" />

<xi:include href="./library/generated/trivial.xml" />

<xi:include href="./library/generated/lists.xml" />

<xi:include href="./library/generated/debug.xml" />

<xi:include href="./library/generated/options.xml" />

<xi:include href="./library/generated/filesystem.xml" />

<xi:include href="./library/generated/sources.xml" />
<!-- The index must have a root element to declare namespaces, but we
don't want to include it, so we select all of its children. -->
<xi:include href="./library/generated/index.xml" xpointer="xpointer(/root/*)" />
</section>