From 87b8931d74d9e744a16a00503003a46584f03b4a Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 26 Jul 2024 10:50:26 -0700 Subject: [PATCH] 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. --- doc/default.nix | 27 +----- doc/doc-support/lib-function-docs.nix | 115 +++++++++++++++++++++++--- 2 files changed, 108 insertions(+), 34 deletions(-) diff --git a/doc/default.nix b/doc/default.nix index 6492d78601c8..fe6fd477348b 100644 --- a/doc/default.nix +++ b/doc/default.nix @@ -1,34 +1,13 @@ { pkgs ? (import ./.. { }), nixpkgs ? { }}: let - inherit (pkgs) lib; + inherit (pkgs) lib callPackage; inherit (lib) hasPrefix removePrefix; fs = lib.fileset; common = import ./common.nix; - lib-docs = import ./doc-support/lib-function-docs.nix { - inherit pkgs 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"; } - ]; + lib-docs = callPackage ./doc-support/lib-function-docs.nix { + inherit nixpkgs; }; epub = pkgs.runCommand "manual.epub" { diff --git a/doc/doc-support/lib-function-docs.nix b/doc/doc-support/lib-function-docs.nix index 9e1fdedd2cb9..b1c197ae1627 100644 --- a/doc/doc-support/lib-function-docs.nix +++ b/doc/doc-support/lib-function-docs.nix @@ -1,23 +1,111 @@ # 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; - -stdenv.mkDerivation { +stdenvNoCC.mkDerivation { name = "nixpkgs-lib-docs"; - src = pkgs.lib.fileset.toSource { + + src = lib.fileset.toSource { root = ../..; fileset = ../../lib; }; - buildInputs = [ nixdoc nix ]; + buildInputs = [ + nixdoc + nix + ]; + installPhase = '' export NIX_STATE_DIR=$(mktemp -d) nix-instantiate --eval --strict --json ${./lib-function-locations.nix} \ --arg nixpkgsPath "./." \ --argstr revision ${nixpkgs.rev or "master"} \ - --argstr libsetsJSON ${pkgs.lib.escapeShellArg (builtins.toJSON libsets)} \ + --argstr libsetsJSON ${lib.escapeShellArg (builtins.toJSON libsets)} \ > locations.json function docgen { @@ -39,9 +127,16 @@ stdenv.mkDerivation { ```{=include=} sections auto-id-prefix=auto-generated EOF - ${lib.concatMapStrings ({ name, baseName ? name, description }: '' - docgen ${name} ${baseName} ${lib.escapeShellArg description} - '') libsets} + ${lib.concatMapStrings ( + { + name, + baseName ? name, + description, + }: + '' + docgen ${name} ${baseName} ${lib.escapeShellArg description} + '' + ) libsets} echo '```' >> "$out/index.md" '';