docs: improve the wording, add targeted examples

This commit is contained in:
fufsob committed 2026-09-25 09:54:12 +00:00
1 parent 53fc86dd83
commit 63d9dffcae
61 files changed
+3422 -5861

No files matched your search

+108 -8
View File
@@ -2,16 +2,105 @@
pkgs,
optionDocs,
defaultConfigText,
groupSummaries,
}:
let
# Type, Default and Example as one short paragraph per option instead of three
# headed blocks each; short values inline, the rest as code after it.
compactFields = pkgs.writeText "compact-fields.py" ''
import re
import sys
from pathlib import Path
FIELD = re.compile(r"^\*(Type|Default|Example):\*$")
FENCE = re.compile(r"^`{3,}")
path = Path(sys.argv[1])
lines = path.read_text().split("\n")
out = []
option_type = None
para = []
i = 0
def flush():
# Hard line breaks, not a list: a list would merge with one that ends the
# description.
if para:
if out[-1] != "":
out.append("")
out.append("\\\n".join(para))
para.clear()
def flat(code):
# `[ "a" "b" ]` and `{ a = 1; }` read fine on one line; multi-line strings do not.
if any("'" * 2 in line or "`" in line for line in code):
return None
text = " ".join(line.strip() for line in code)
return text if len(text) <= 72 else None
while i < len(lines):
match = FIELD.match(lines[i])
if not match:
out.append(lines[i])
i += 1
continue
name = match.group(1)
i += 1
if lines[i] == "" and FENCE.match(lines[i + 1]):
fence = FENCE.match(lines[i + 1]).group(0)
end = lines.index(fence, i + 2)
code, text = lines[i + 2 : end], None
i = end + 1
else:
end = lines.index("", i)
code, text = None, " ".join(lines[i:end])
i = end
if name == "Type":
option_type = text
# mkEnableOption's example says nothing.
if not (name == "Example" and option_type == "boolean" and code == ["true"]):
label = f"**{name}:**"
if code is None:
para.append(f"{label} {text}")
elif flat(code) is not None:
para.append(f"{label} `{flat(code)}`")
else:
para.append(label)
flush()
out.extend(["", f"{fence}nix", *code, fence])
# Keep the fields of one option together.
after = i
while after < len(lines) and lines[after] == "":
after += 1
if after < len(lines) and FIELD.match(lines[after]):
i = after
else:
flush()
path.write_text("\n".join(out))
'';
summaryTsv = pkgs.writeText "group-summaries.tsv" (
pkgs.lib.concatMapStrings (group: "${group.name}\t${group.summary}\n") groupSummaries
);
in
# One file per top-level option group, plus an index. The single 6k-line page was
# not navigable.
pkgs.runCommand "proxy-suite-options-doc" { } ''
pkgs.runCommand "proxy-suite-options-doc" { nativeBuildInputs = [ pkgs.python3 ]; } ''
mkdir -p "$out" "$TMPDIR/bodies"
all="$TMPDIR/all.md"
index_tsv="$TMPDIR/sections-index.tsv"
cat ${optionDocs.optionsCommonMark} >"$all"
python ${compactFields} "$all"
summary() { awk -F '\t' -v want="$1" '$1 == want { print $2 }' ${summaryTsv}; }
# Anchor every section and file it under its top-level group. Options directly
# under services.proxy-suite (only `enable`) stay on the index.
@@ -108,9 +197,17 @@ pkgs.runCommand "proxy-suite-options-doc" { } ''
' "$index_tsv"
}
# Groups in the summary list's order, then any it misses.
ordered="$(
{ cut -f1 ${summaryTsv}; printf '%s\n' $groups; } \
| awk -v groups=" $(echo $groups) " 'index(groups, " " $0 " ") && !seen[$0]++'
)"
for group in $groups; do
{
printf '# services.proxy-suite.%s\n\n' "$group"
text="$(summary "$group")"
if [ -n "$text" ]; then printf '%s\n\n' "$text"; fi
printf 'Part of the [proxy-suite options reference](./index.md).\n\n'
printf '## Options\n\n'
mkToc "$group"
@@ -126,19 +223,22 @@ pkgs.runCommand "proxy-suite-options-doc" { } ''
printf 'Update the module option docs there instead of editing these files by hand.\n\n'
printf '## Option groups\n\n'
for group in $groups; do
printf -- '- [%s](./%s.md)\n' "$group" "$group"
printf '| Group | What it covers |\n|---|---|\n'
for group in $ordered; do
printf '| [%s](./%s.md) | %s |\n' "$group" "$group" "$(summary "$group")"
done
printf '\n'
printf '## Complete default config\n\n'
printf '```nix\n'
printf 'services.proxy-suite = %s;\n' ${pkgs.lib.escapeShellArg defaultConfigText}
printf '```\n\n'
if [ -f "$TMPDIR/bodies/index.md" ]; then
cat "$TMPDIR/bodies/index.md"
printf '\n'
fi
printf '## Complete default config\n\n'
printf '<details>\n<summary>Every option at its default</summary>\n\n'
printf '```nix\n'
printf 'services.proxy-suite = %s;\n' ${pkgs.lib.escapeShellArg defaultConfigText}
printf '```\n\n</details>\n'
} >"$TMPDIR/index.out"
# Collapse runs of blank lines, drop trailing ones.