doc: make ./doc-support/lib-function-docs.nix callPackage style

Move `libsets` over to it, since it's the only user.

Format with `nixfmt` since we're changing it so dramatically.
This commit is contained in:
Philip Taron
2024-07-26 10:50:26 -07:00
parent 849cf13725
commit 87b8931d74
2 changed files with 108 additions and 34 deletions

View File

@@ -1,34 +1,13 @@
{ pkgs ? (import ./.. { }), nixpkgs ? { }}: { pkgs ? (import ./.. { }), nixpkgs ? { }}:
let let
inherit (pkgs) lib; inherit (pkgs) lib callPackage;
inherit (lib) hasPrefix removePrefix; inherit (lib) hasPrefix removePrefix;
fs = lib.fileset; fs = lib.fileset;
common = import ./common.nix; common = import ./common.nix;
lib-docs = import ./doc-support/lib-function-docs.nix { lib-docs = callPackage ./doc-support/lib-function-docs.nix {
inherit pkgs nixpkgs; inherit nixpkgs;
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 = "fixedPoints"; baseName = "fixed-points"; description = "explicit recursion functions"; }
{ name = "lists"; description = "list manipulation functions"; }
{ name = "debug"; description = "debugging functions"; }
{ name = "options"; description = "NixOS / nixpkgs option handling"; }
{ name = "path"; description = "path functions"; }
{ name = "filesystem"; description = "filesystem functions"; }
{ name = "fileset"; description = "file set functions"; }
{ name = "sources"; description = "source filtering functions"; }
{ name = "cli"; description = "command-line serialization functions"; }
{ name = "generators"; description = "functions that create file formats from nix data structures"; }
{ name = "gvariant"; description = "GVariant formatted string serialization functions"; }
{ name = "customisation"; description = "Functions to customise (derivation-related) functions, derivatons, or attribute sets"; }
{ name = "meta"; description = "functions for derivation metadata"; }
{ name = "derivations"; description = "miscellaneous derivation-specific functions"; }
];
}; };
epub = pkgs.runCommand "manual.epub" { epub = pkgs.runCommand "manual.epub" {

View File

@@ -1,23 +1,111 @@
# Generates the documentation for library functions via nixdoc. # Generates the documentation for library functions via nixdoc.
{ pkgs, nixpkgs, libsets }: {
lib,
stdenvNoCC,
nixdoc,
nix,
nixpkgs ? { },
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 = "fixedPoints";
baseName = "fixed-points";
description = "explicit recursion functions";
}
{
name = "lists";
description = "list manipulation functions";
}
{
name = "debug";
description = "debugging functions";
}
{
name = "options";
description = "NixOS / nixpkgs option handling";
}
{
name = "path";
description = "path functions";
}
{
name = "filesystem";
description = "filesystem functions";
}
{
name = "fileset";
description = "file set functions";
}
{
name = "sources";
description = "source filtering functions";
}
{
name = "cli";
description = "command-line serialization functions";
}
{
name = "generators";
description = "functions that create file formats from nix data structures";
}
{
name = "gvariant";
description = "GVariant formatted string serialization functions";
}
{
name = "customisation";
description = "Functions to customise (derivation-related) functions, derivatons, or attribute sets";
}
{
name = "meta";
description = "functions for derivation metadata";
}
{
name = "derivations";
description = "miscellaneous derivation-specific functions";
}
],
}:
with pkgs; stdenvNoCC.mkDerivation {
stdenv.mkDerivation {
name = "nixpkgs-lib-docs"; name = "nixpkgs-lib-docs";
src = pkgs.lib.fileset.toSource {
src = lib.fileset.toSource {
root = ../..; root = ../..;
fileset = ../../lib; fileset = ../../lib;
}; };
buildInputs = [ nixdoc nix ]; buildInputs = [
nixdoc
nix
];
installPhase = '' installPhase = ''
export NIX_STATE_DIR=$(mktemp -d) export NIX_STATE_DIR=$(mktemp -d)
nix-instantiate --eval --strict --json ${./lib-function-locations.nix} \ nix-instantiate --eval --strict --json ${./lib-function-locations.nix} \
--arg nixpkgsPath "./." \ --arg nixpkgsPath "./." \
--argstr revision ${nixpkgs.rev or "master"} \ --argstr revision ${nixpkgs.rev or "master"} \
--argstr libsetsJSON ${pkgs.lib.escapeShellArg (builtins.toJSON libsets)} \ --argstr libsetsJSON ${lib.escapeShellArg (builtins.toJSON libsets)} \
> locations.json > locations.json
function docgen { function docgen {
@@ -39,9 +127,16 @@ stdenv.mkDerivation {
```{=include=} sections auto-id-prefix=auto-generated ```{=include=} sections auto-id-prefix=auto-generated
EOF EOF
${lib.concatMapStrings ({ name, baseName ? name, description }: '' ${lib.concatMapStrings (
{
name,
baseName ? name,
description,
}:
''
docgen ${name} ${baseName} ${lib.escapeShellArg description} docgen ${name} ${baseName} ${lib.escapeShellArg description}
'') libsets} ''
) libsets}
echo '```' >> "$out/index.md" echo '```' >> "$out/index.md"
''; '';