chore: refactoring (split)
This commit is contained in:
84 files changed
+9149
-7244
No files matched your search
+24
-205
@@ -25,20 +25,18 @@ let
|
||||
config:
|
||||
builtins.removeAttrs config [ "singBox" ]
|
||||
// {
|
||||
proxy =
|
||||
(config.proxy or { })
|
||||
// {
|
||||
singBox =
|
||||
((config.proxy or { }).singBox or { })
|
||||
// lib.optionalAttrs (((config.proxy or { }).singBox or { }) ? package) {
|
||||
package = singBoxPackagePlaceholder;
|
||||
};
|
||||
xray =
|
||||
((config.proxy or { }).xray or { })
|
||||
// lib.optionalAttrs (((config.proxy or { }).xray or { }) ? package) {
|
||||
package = xrayPackagePlaceholder;
|
||||
};
|
||||
};
|
||||
proxy = (config.proxy or { }) // {
|
||||
singBox =
|
||||
((config.proxy or { }).singBox or { })
|
||||
// lib.optionalAttrs (((config.proxy or { }).singBox or { }) ? package) {
|
||||
package = singBoxPackagePlaceholder;
|
||||
};
|
||||
xray =
|
||||
((config.proxy or { }).xray or { })
|
||||
// lib.optionalAttrs (((config.proxy or { }).xray or { }) ? package) {
|
||||
package = xrayPackagePlaceholder;
|
||||
};
|
||||
};
|
||||
};
|
||||
renderConfigText =
|
||||
config:
|
||||
@@ -51,9 +49,7 @@ let
|
||||
"pkgs.sing-box"
|
||||
"pkgs.xray"
|
||||
]
|
||||
(
|
||||
lib.generators.toPretty { } (sanitizeConfigForDocs config)
|
||||
);
|
||||
(lib.generators.toPretty { } (sanitizeConfigForDocs config));
|
||||
mkGeneratedExampleValue =
|
||||
option:
|
||||
if (option ? _type) && option._type == "option" then
|
||||
@@ -68,8 +64,9 @@ let
|
||||
else
|
||||
lib.mapAttrs (_: mkGeneratedExampleValue) (filterGeneratedOptions option);
|
||||
defaultConfigText = renderConfigText eval.config.services.proxy-suite;
|
||||
generatedExampleConfig =
|
||||
lib.mapAttrs (_: mkGeneratedExampleValue) (filterGeneratedOptions eval.options.services.proxy-suite);
|
||||
generatedExampleConfig = lib.mapAttrs (_: mkGeneratedExampleValue) (
|
||||
filterGeneratedOptions eval.options.services.proxy-suite
|
||||
);
|
||||
exampleConfigText = renderConfigText (builtins.removeAttrs generatedExampleConfig [ "singBox" ]);
|
||||
repoRoot = toString ../.;
|
||||
repoUrl = "https://github.com/FUFSoB/proxy-suite-flake/blob/main";
|
||||
@@ -98,189 +95,11 @@ let
|
||||
transformOptions = opt: opt // { declarations = map transformDeclaration opt.declarations; };
|
||||
};
|
||||
in
|
||||
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"
|
||||
|
||||
cat >"$preamble" <<'EOF'
|
||||
# proxy-suite options
|
||||
|
||||
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" '
|
||||
function slugify(text, slug) {
|
||||
slug = text
|
||||
gsub(/\\/, "", slug)
|
||||
slug = tolower(slug)
|
||||
gsub(/[^a-z0-9]+/, "-", slug)
|
||||
sub(/^-+/, "", slug)
|
||||
sub(/-+$/, "", slug)
|
||||
return slug
|
||||
}
|
||||
|
||||
/^## / {
|
||||
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"
|
||||
}
|
||||
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)
|
||||
|
||||
if (normalized ~ /^Complete /) {
|
||||
sampleCount++
|
||||
sampleTitle[sampleCount] = title
|
||||
sampleSlug[sampleCount] = slug
|
||||
next
|
||||
}
|
||||
|
||||
if (index(normalized, "services.proxy-suite") == 1) {
|
||||
optionRootSeen = 1
|
||||
slugByPath[normalized] = slug
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
{
|
||||
blanks++
|
||||
}
|
||||
' "$raw" >"$out"
|
||||
''
|
||||
import ./options-doc/render-options-markdown.nix {
|
||||
inherit
|
||||
pkgs
|
||||
optionDocs
|
||||
defaultConfigText
|
||||
exampleConfigText
|
||||
;
|
||||
}
|
||||
Reference in new issue
Block a user