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

+7 -48
View File
@@ -10,6 +10,7 @@
}:
let
fillTemplate = import ../../modules/proxy-suite/lib/fill-template.nix;
fixtures = import ./xray-backend-runtime/fixtures.nix {
inherit checkLib;
inherit
@@ -43,55 +44,13 @@ let
;
xrayJqFilterRuntimeCheck =
pkgs.runCommand "proxy-suite-xray-jq-filter-runtime-check" { nativeBuildInputs = [ pkgs.jq ]; }
''
OBS='[{"protocol":"freedom","tag":"proxy-suite-ob-primary"},
{"protocol":"vless","tag":"proxy-suite-ob-edge","settings":{"vnext":[{"address":"edge.example.com","port":443}]}},
{"protocol":"trojan","tag":"proxy-suite-ob-ip","settings":{"servers":[{"address":"203.0.113.1","port":443}]}}]'
check_runtime() {
local name="$1"
local input="$2"
local output="$TMPDIR/$name.json"
jq \
--slurpfile obs <(printf "%s" "$OBS") \
--argjson auth_enabled false \
--arg user "" \
--arg password "" \
--argjson route_enabled true \
--argjson route_rules '[]' \
--arg route_final "proxy" \
--arg dns_final "remote" \
--argjson clear_dns_rules false \
--arg xray_loglevel "" \
--arg xray_single_proxy_tag "proxy-suite-ob-primary" \
--argjson xray_tun_dns_runtime true \
-f ${pkgs.lib.escapeShellArg xrayBackendJqFilterFile} \
"$input" > "$output"
jq -e \
'
type == "object"
and (.dns.servers | length) >= 3
and .dns.servers[0].tag == "fakedns"
and ([.routing.rules[] | select((.ruleTag? // "") == "dns-hijack")] | length) == 1
and ([.routing.rules[] | select((.ruleTag? // "") == "dns-upstream-direct")] | length) == 1
and ([.routing.rules[] | select((.ruleTag? // "") == "dns-upstream-remote")] | length) == 1
and ([.dns.servers[] | select(.domains?)] == [.dns.servers[] | select(.tag == "local" and (has("domains") | not))
| . + {domains: ["full:edge.example.com"], skipFallback: true}])
and ([.outbounds[] | select(.streamSettings.sockopt.interface?)] | length) == 0
and ([.outbounds[] | select(.protocol == "freedom" or .tag == "proxy-suite-ob-primary") | .streamSettings.sockopt.domainStrategy] | all(. == "UseIPv4v6"))
and ([.outbounds[] | select(.protocol == "dns") | .streamSettings.sockopt.domainStrategy?] | all(. == null))
and ([.inbounds[] | select(.tag == "tun-in") | .settings | has("dns") or has("autoOutboundsInterface")] | any | not)
and ((.routing | has("balancers")) | not)
and ((has("observatory")) | not)
' "$output" >/dev/null
(
fillTemplate ./xray-backend-runtime/jq-filter-runtime.template.sh {
jqFilter = pkgs.lib.escapeShellArg xrayBackendJqFilterFile;
tunConfig = pkgs.lib.escapeShellArg xrayTunConfigJson;
perAppTunConfig = pkgs.lib.escapeShellArg xrayPerAppTunConfigJson;
}
check_runtime global ${pkgs.lib.escapeShellArg xrayTunConfigJson}
check_runtime per-app ${pkgs.lib.escapeShellArg xrayPerAppTunConfigJson}
touch "$out"
'';
);
serviceShapeChecks = import ./xray-backend-runtime/service-shape.nix {
inherit