1# Generates the documentation for library functions via nixdoc.
2# To build this derivation, run `nix-build -A nixpkgs-manual.lib-docs`
3{
4 lib,
5 stdenvNoCC,
6 nixdoc,
7 nix,
8 nixpkgs ? { },
9 libsets ? [
10 {
11 name = "asserts";
12 description = "assertion functions";
13 }
14 {
15 name = "attrsets";
16 description = "attribute set functions";
17 }
18 {
19 name = "strings";
20 description = "string manipulation functions";
21 }
22 {
23 name = "versions";
24 description = "version string functions";
25 }
26 {
27 name = "trivial";
28 description = "miscellaneous functions";
29 }
30 {
31 name = "fixedPoints";
32 baseName = "fixed-points";
33 description = "explicit recursion functions";
34 }
35 {
36 name = "lists";
37 description = "list manipulation functions";
38 }
39 {
40 name = "debug";
41 description = "debugging functions";
42 }
43 {
44 name = "options";
45 description = "NixOS / nixpkgs option handling";
46 }
47 {
48 name = "path";
49 description = "path functions";
50 }
51 {
52 name = "filesystem";
53 description = "filesystem functions";
54 }
55 {
56 name = "fileset";
57 description = "file set functions";
58 }
59 {
60 name = "sources";
61 description = "source filtering functions";
62 }
63 {
64 name = "cli";
65 description = "command-line serialization functions";
66 }
67 {
68 name = "generators";
69 description = "functions that create file formats from nix data structures";
70 }
71 {
72 name = "gvariant";
73 description = "GVariant formatted string serialization functions";
74 }
75 {
76 name = "customisation";
77 description = "Functions to customise (derivation-related) functions, derivatons, or attribute sets";
78 }
79 {
80 name = "meta";
81 description = "functions for derivation metadata";
82 }
83 {
84 name = "derivations";
85 description = "miscellaneous derivation-specific functions";
86 }
87 ],
88}:
89
90stdenvNoCC.mkDerivation {
91 name = "nixpkgs-lib-docs";
92
93 src = lib.fileset.toSource {
94 root = ../..;
95 fileset = ../../lib;
96 };
97
98 buildInputs = [
99 nixdoc
100 nix
101 ];
102
103 installPhase = ''
104 export NIX_STATE_DIR=$(mktemp -d)
105 nix-instantiate --eval --strict --json ${./lib-function-locations.nix} \
106 --arg nixpkgsPath "./." \
107 --argstr revision ${nixpkgs.rev or "master"} \
108 --argstr libsetsJSON ${lib.escapeShellArg (builtins.toJSON libsets)} \
109 > locations.json
110
111 function docgen {
112 name=$1
113 baseName=$2
114 description=$3
115 # TODO: wrap lib.$name in <literal>, make nixdoc not escape it
116 if [[ -e "lib/$baseName.nix" ]]; then
117 nixdoc -c "$name" -d "lib.$name: $description" -l locations.json -f "lib/$baseName.nix" > "$out/$name.md"
118 else
119 nixdoc -c "$name" -d "lib.$name: $description" -l locations.json -f "lib/$baseName/default.nix" > "$out/$name.md"
120 fi
121 echo "$out/$name.md" >> "$out/index.md"
122 }
123
124 mkdir -p "$out"
125
126 cat > "$out/index.md" << 'EOF'
127 ```{=include=} sections auto-id-prefix=auto-generated
128 EOF
129
130 ${lib.concatMapStrings (
131 {
132 name,
133 baseName ? name,
134 description,
135 }:
136 ''
137 docgen ${name} ${baseName} ${lib.escapeShellArg description}
138 ''
139 ) libsets}
140
141 echo '```' >> "$out/index.md"
142 '';
143}