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

+1 -1
View File
@@ -36,7 +36,7 @@ let
generatedOptionsDoc
generatedReadmeDoc
;
inherit (checkLib) rg;
inherit (checkLib) rg evalProxySuite;
readmeDocSource = builtins.readFile ../nix/readme-doc.nix;
tgWsProxyModuleSource = builtins.readFile ../modules/proxy-suite/tg-ws-proxy.nix;
controlModuleSource = builtins.readFile ../modules/proxy-suite/service/control.nix;
+107
View File
@@ -1,6 +1,7 @@
{
pkgs,
rg,
evalProxySuite,
generatedOptionsDoc,
generatedReadmeDoc,
readmeDocSource,
@@ -57,6 +58,112 @@ in
touch "$out"
'';
# The usage guides are hand-written; what can go stale in them is checked here. Every
# ```nix block that sets services.proxy-suite (in the guides and the README) must
# evaluate, with no proxy-suite assertion or warning; a block fenced ```nix no-check is
# skipped. Every relative link must reach a file, and its #anchor an <a id> there.
usage-docs =
let
inherit (pkgs) lib;
usageDir = ../../docs/usage;
guides = builtins.filter (lib.hasSuffix ".md") (builtins.attrNames (builtins.readDir usageDir));
readmeText = builtins.readFile ../../README.md;
guideText = name: builtins.readFile (usageDir + "/${name}");
snippets =
text:
builtins.filter (lib.hasInfix "services.proxy-suite") (
map (chunk: builtins.head (lib.splitString "\n```" chunk)) (
builtins.tail (lib.splitString "```nix\n" text)
)
);
# Every visible option's value, so a wrong type fails too. Packages are skipped:
# forcing one evaluates its whole build graph. Removed options throw when read.
plain =
value:
if lib.isDerivation value then
null
else if builtins.isAttrs value then
lib.mapAttrs (_: plain) value
else if builtins.isList value then
map plain value
else
value;
visibleValues =
opts: cfg:
lib.mapAttrs (
name: opt: if lib.isOption opt then plain cfg.${name} else visibleValues opt cfg.${name}
) (lib.filterAttrs (name: opt: name != "_module" && (opt.visible or true) != false) opts);
snippetProblems =
where: snippet:
let
module = import (
builtins.toFile "snippet.nix" ''
{ config, lib, pkgs, ... }:
{
system.stateVersion = "26.05";
${snippet}
}
''
);
eval = evalProxySuite [ module ];
inherit (eval) config;
failed = map (a: a.message) (builtins.filter (a: !a.assertion) config.assertions);
own = builtins.filter (lib.hasPrefix "proxy-suite:") (failed ++ config.warnings);
in
builtins.addErrorContext "while evaluating ${where}" (
builtins.deepSeq (visibleValues eval.options.services.proxy-suite config.services.proxy-suite) (
map (message: "${where}: ${message}") own
)
);
textProblems =
file: text:
lib.concatLists (
lib.imap1 (index: snippetProblems "${file}, nix block ${toString index}") (snippets text)
);
# [text](target) and [text](target#anchor), except absolute URLs.
links =
text:
builtins.filter (link: !lib.hasInfix "://" (builtins.head link)) (
builtins.filter builtins.isList (builtins.split "]\\(([^)#]*)(#[^)]*)?\\)" text)
);
linkProblems =
name:
lib.concatMap (
link:
let
target = builtins.head link;
anchor = builtins.elemAt link 1;
path = if target == "" then usageDir + "/${name}" else usageDir + "/${target}";
where = "docs/usage/${name}: ${target}${if anchor == null then "" else anchor}";
in
if !builtins.pathExists path then
[ "${where}: no such file" ]
else if
anchor != null && !lib.hasInfix "<a id=\"${lib.removePrefix "#" anchor}\">" (builtins.readFile path)
then
[ "${where}: no such anchor" ]
else
[ ]
) (links (guideText name));
problems =
textProblems "README.md" readmeText
++ lib.concatMap (
name: textProblems "docs/usage/${name}" (guideText name) ++ linkProblems name
) guides;
in
pkgs.runCommand "proxy-suite-usage-docs-check" { } (
if problems == [ ] then
''touch "$out"''
else
''
printf '%s\n' ${lib.escapeShellArgs problems} >&2
exit 1
''
);
# The tree as `nix fmt` leaves it.
nix-format =
pkgs.runCommand "proxy-suite-nix-format-check" { nativeBuildInputs = [ pkgs.nixfmt ]; }
+63
View File
@@ -46,6 +46,69 @@ let
in
import ./options-doc/render-options-markdown.nix {
inherit pkgs optionDocs;
# The index lists the groups in this order.
groupSummaries = [
{
name = "proxy";
summary = "The local proxy: outbounds, subscriptions, selection, routing, DNS, TUN and TProxy.";
}
{
name = "killSwitch";
summary = "Block traffic outside the global tunnel.";
}
{
name = "perAppRouting";
summary = "Route single apps through proxychains, a per-app TUN or TProxy, or zapret.";
}
{
name = "zapret";
summary = "DPI bypass without a proxy: zapret-discord-youtube or zapret2.";
}
{
name = "amneziaWg";
summary = "AmneziaWG client profiles, as a global VPN or as outbounds.";
}
{
name = "warp";
summary = "Cloudflare WARP, as an outbound or an AmneziaWG profile.";
}
{
name = "tor";
summary = "Tor as an outbound, with bridges, and an onion service for the inbounds.";
}
{
name = "sshProxy";
summary = "An SSH SOCKS5 tunnel, optionally as an outbound.";
}
{
name = "tgWsProxy";
summary = "A Telegram MTProto proxy over WebSocket.";
}
{
name = "whitelistBypass";
summary = "Tunnels through video-call servers, past mobile internet whitelists.";
}
{
name = "inbounds";
summary = "Server side: listeners for remote clients, share links, subscriptions and stats.";
}
{
name = "geodata";
summary = "Geosite and geoip databases used by routing.";
}
{
name = "userControl";
summary = "Let a group use `proxy-ctl` without root.";
}
{
name = "gui";
summary = "The desktop app with a tray icon.";
}
{
name = "tui";
summary = "The `proxy-tui` terminal UI.";
}
];
defaultConfigText = lib.generators.toPretty { allowPrettyValues = true; } (
visibleConfig eval.options.services.proxy-suite eval.config.services.proxy-suite
);
+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.