refactor: move out large code blocks out of nix

This commit is contained in:
fufsob authored and FUFSoB committed 2026-10-04 11:54:04 +05:00
1 parent e8ace6523d
commit af5b3ff27a
47 files changed
+2220 -2070

No files matched your search

+10 -25
View File
@@ -10,31 +10,16 @@
ifPrivileged,
}:
pkgs.writeShellScript "proxy-suite-autoproxy" ''
set -euo pipefail
# $1 - probe-exits.json (index -> tag -> path), $2 - state.json
export PATH=${
pkgs.lib.makeBinPath [
let
fillTemplate = import ./lib/fill-template.nix;
in
pkgs.writeShellScript "proxy-suite-autoproxy" (
fillTemplate ./autoproxy-render.template.sh {
path = pkgs.lib.makeBinPath [
pkgs.coreutils
pkgs.jq
]
];
inherit serviceUser;
groupArg = ifPrivileged "-g ${serviceUser} ";
}
jq -c '.[]' "$1" | while IFS= read -r exit; do
tag=$(jq -r '.tag' <<<"$exit")
path=$(jq -r '.path' <<<"$exit")
# sing-box, running as ${serviceUser}, watches this directory to reload the
# files: that takes read on it, not just the search the state dir grants.
# Asserted on every render, since StateDirectory= re-owns the tree when the
# units' Group= changes.
install -d -m 0750 ${ifPrivileged "-g ${serviceUser} "}"$(dirname "$path")"
# Written aside and renamed into place: sing-box reloads on rename (as well
# as on in-place writes), and it never reads a half-written file.
jq -c --arg t "$tag" '
[(.domains // {}) | to_entries[] | select(.value.exit == $t) | .key] as $d
| {version: 1, rules: (if ($d | length) > 0 then [{domain_suffix: $d}] else [] end)}
' "$2" > "$path.tmp"
chmod 644 "$path.tmp"
mv -f "$path.tmp" "$path"
done
''
)