refactor: overhaul of options and features

Includes, but not limited to:
- zapret2 support
- declarative inbounds
- proxy-ctl revamp
- automatic proxy learning
This commit is contained in:
FUFSoB committed 2026-09-13 22:37:45 +05:00
1 parent b892384527
commit fdb2b08790
144 files changed
+13198 -14066

No files matched your search

+111 -158
View File
@@ -2,48 +2,21 @@
pkgs,
optionDocs,
defaultConfigText,
exampleConfigText,
}:
pkgs.runCommand "proxy-suite-options.md" { } ''
preamble="$TMPDIR/preamble.md"
sections="$TMPDIR/sections.md"
sections_with_anchors="$TMPDIR/sections-with-anchors.md"
section_index="$TMPDIR/sections-index.tsv"
toc="$TMPDIR/toc.md"
# One file per top-level option group, plus an index. The single 6k-line page was
# not navigable.
pkgs.runCommand "proxy-suite-options-doc" { } ''
mkdir -p "$out" "$TMPDIR/bodies"
all="$TMPDIR/all.md"
index_tsv="$TMPDIR/sections-index.tsv"
cat >"$preamble" <<'EOF'
# proxy-suite options
cat ${optionDocs.optionsCommonMark} >"$all"
This file is generated from the `services.proxy-suite` option descriptions in [`modules/proxy-suite/options/default.nix`](/modules/proxy-suite/options/default.nix).
Update module option docs there instead of editing this file by hand.
## Table of contents
EOF
cat >"$sections" <<'EOF'
## Complete default config
```nix
services.proxy-suite = ${defaultConfigText};
```
## Complete example config
This is generated by filling in all the options with example values (or defaults if no example is provided). This is not meant to be a recommended config, just a comprehensive example of how to set all the options.
```nix
services.proxy-suite = ${exampleConfigText};
```
EOF
cat ${optionDocs.optionsCommonMark} >>"$sections"
: >"$section_index"
: >"$sections_with_anchors"
awk -v section_index="$section_index" -v out="$sections_with_anchors" '
# Anchor every section and file it under its top-level group. Options directly
# under services.proxy-suite (only `enable`) stay on the index.
: >"$index_tsv"
awk -v outdir="$TMPDIR/bodies" -v index_tsv="$index_tsv" '
function slugify(text, slug) {
slug = text
gsub(/\\/, "", slug)
@@ -56,141 +29,121 @@ pkgs.runCommand "proxy-suite-options.md" { } ''
/^## / {
title = substr($0, 4)
base = slugify(title)
count = seen[base]
seen[base]++
slug = count == 0 ? base : base "-" count
print title "\t" slug >> section_index
print "<a id=\"" slug "\"></a>" >> out
}
{
print >> out
}
' "$sections"
: >"$toc"
awk -F '\t' -v toc="$toc" '
function addChild(parent, child, key) {
key = parent SUBSEP child
if (!(key in seenChild)) {
seenChild[key] = 1
childCount[parent]++
childOrder[parent, childCount[parent]] = child
}
}
function indent(depth, i, prefix) {
prefix = ""
for (i = 0; i < depth; i++) {
prefix = prefix " "
}
return prefix
}
function displayLabel(label) {
if (label == "*") {
return "item"
}
if (label ~ /^<.*>$/) {
return "`" label "`"
}
return label
}
function printNode(path, label, depth, i, child, childPath, text) {
text = displayLabel(label)
if (path in slugByPath) {
text = "[" text "](#" slugByPath[path] ")"
}
print indent(depth) "- " text >> toc
for (i = 1; i <= childCount[path]; i++) {
child = childOrder[path, i]
childPath = path "." child
printNode(childPath, child, depth + 1)
}
}
{
title = $1
slug = $2
normalized = title
gsub(/\\/, "", normalized)
count = split(normalized, parts, /\./)
group = (count <= 3) ? "index" : parts[3]
slug = slugify(title)
current = outdir "/" group ".md"
if (normalized ~ /^Complete /) {
sampleCount++
sampleTitle[sampleCount] = title
sampleSlug[sampleCount] = slug
next
print title "\t" slug "\t" group >> index_tsv
print "<a id=\"" slug "\"></a>" >> current
print $0 >> current
next
}
{ if (current != "") print >> current }
' "$all"
groups="$(cut -f3 "$index_tsv" | grep -v '^index$' | awk '!seen[$0]++')"
# Per-group table of contents, nested by option path.
mkToc() {
awk -F '\t' -v want="$1" '
function indent(depth, i, prefix) {
prefix = ""
for (i = 0; i < depth; i++) {
prefix = prefix " "
}
return prefix
}
if (index(normalized, "services.proxy-suite") == 1) {
optionRootSeen = 1
slugByPath[normalized] = slug
function displayLabel(label) {
if (label == "*") {
return "item"
}
if (label ~ /^<.*>$/) {
return "`" label "`"
}
return label
}
function addChild(parent, child, key) {
key = parent SUBSEP child
if (!(key in seenChild)) {
seenChild[key] = 1
childCount[parent]++
childOrder[parent, childCount[parent]] = child
}
}
function printNode(path, label, depth, i, child, childPath, text) {
text = displayLabel(label)
if (path in slugByPath) {
text = "[" text "](#" slugByPath[path] ")"
}
print indent(depth) "- " text
for (i = 1; i <= childCount[path]; i++) {
child = childOrder[path, i]
childPath = path "." child
printNode(childPath, child, depth + 1)
}
}
$3 == want {
normalized = $1
gsub(/\\/, "", normalized)
slugByPath[normalized] = $2
count = split(normalized, parts, /\./)
if (count < 3) {
next
}
parent = "services.proxy-suite"
for (i = 3; i <= count; i++) {
child = parts[i]
addChild(parent, child)
parent = parent "." child
}
next
}
otherCount++
otherTitle[otherCount] = title
otherSlug[otherCount] = slug
}
END {
if (sampleCount > 0) {
print "- Config samples" >> toc
for (i = 1; i <= sampleCount; i++) {
print " - [" sampleTitle[i] "](#" sampleSlug[i] ")" >> toc
}
}
if (optionRootSeen) {
print "- services.proxy-suite" >> toc
for (i = 1; i <= childCount["services.proxy-suite"]; i++) {
child = childOrder["services.proxy-suite", i]
printNode("services.proxy-suite." child, child, 1)
}
}
for (i = 1; i <= otherCount; i++) {
print "- [" otherTitle[i] "](#" otherSlug[i] ")" >> toc
}
}
' "$section_index"
raw="$TMPDIR/options.md.raw"
cat "$preamble" >"$raw"
cat "$toc" >>"$raw"
printf '\n' >>"$raw"
cat "$sections_with_anchors" >>"$raw"
awk '
NF {
for (i = 0; i < blanks; i++) {
print ""
}
blanks = 0
print
next
}
END { printNode("services.proxy-suite." want, want, 0) }
' "$index_tsv"
}
for group in $groups; do
{
blanks++
}
' "$raw" >"$out"
printf '# services.proxy-suite.%s\n\n' "$group"
printf 'Part of the [proxy-suite options reference](./index.md).\n\n'
printf '## Options\n\n'
mkToc "$group"
printf '\n'
cat "$TMPDIR/bodies/$group.md"
} >"$TMPDIR/$group.out"
done
{
printf '# proxy-suite options\n\n'
printf 'Generated from the `services.proxy-suite` option descriptions under\n'
printf '[`modules/proxy-suite/options/`](/modules/proxy-suite/options/).\n'
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"
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"
fi
} >"$TMPDIR/index.out"
# Collapse runs of blank lines, drop trailing ones.
for group in $groups index; do
awk 'NF { if (blank) print ""; blank = 0; print; next } { blank = 1 }' \
"$TMPDIR/$group.out" >"$out/$group.md"
done
''