fix: more fixes
This commit is contained in:
23 files changed
+207
-146
No files matched your search
@@ -22,7 +22,7 @@ let
|
||||
options = {
|
||||
outbound = mkOption {
|
||||
type = types.str;
|
||||
description = ''Outbound tag, or "proxy", "direct", "block". With selection = "first" every proxy tag means "proxy".'';
|
||||
description = ''Outbound tag, or "proxy", "direct", "block".'';
|
||||
example = "vps-de";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -67,13 +67,6 @@ let
|
||||
settings.address = "example.com";
|
||||
};
|
||||
|
||||
json = mkOption {
|
||||
type = types.nullOr types.attrs;
|
||||
default = null;
|
||||
visible = false;
|
||||
description = "Deprecated alias for singBoxJson.";
|
||||
};
|
||||
|
||||
backend = mkOption {
|
||||
type = types.enum [
|
||||
"auto"
|
||||
@@ -88,7 +81,7 @@ let
|
||||
example = "xray";
|
||||
};
|
||||
|
||||
# Destinations sent to this outbound (selection "selector" or "urltest").
|
||||
# Destinations sent to this outbound, whatever the selection.
|
||||
routing = routingFields;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -30,14 +30,10 @@ let
|
||||
else
|
||||
"proxy";
|
||||
|
||||
# In "first" mode the start script renames the first outbound to "proxy",
|
||||
# so any per-outbound routing tag that isn't direct/block/proxy must map
|
||||
# to "proxy" instead of the original tag (which won't exist in sing-box).
|
||||
# Pure XRay's urltest prefixes every outbound for its balancer.
|
||||
resolveTag =
|
||||
tag:
|
||||
if derived.collapseNamedOutbounds && !builtins.elem tag derived.builtinTags then
|
||||
"proxy"
|
||||
else if
|
||||
if
|
||||
derived.pureXrayEnabled
|
||||
&& derived.selectionMode == "urltest"
|
||||
&& !builtins.elem tag derived.builtinTags
|
||||
|
||||
@@ -244,16 +244,15 @@ let
|
||||
ob.url
|
||||
ob.singBoxJson
|
||||
ob.xrayJson
|
||||
ob.json
|
||||
]
|
||||
"proxy-suite: outbound '${ob.tag}': set exactly one of urlFile, url, singBoxJson, xrayJson, or json"
|
||||
"proxy-suite: outbound '${ob.tag}': set exactly one of urlFile, url, singBoxJson, or xrayJson"
|
||||
)
|
||||
(mkAssertion (
|
||||
!singBoxEnabled || hybridEnabled || ob.xrayJson == null
|
||||
) "proxy-suite: outbound '${ob.tag}': xrayJson requires proxy.backend = xray or hybrid")
|
||||
(mkAssertion (
|
||||
!xrayEnabled || hybridEnabled || (ob.singBoxJson == null && ob.json == null)
|
||||
) "proxy-suite: outbound '${ob.tag}': singBoxJson/json require proxy.backend = sing-box or hybrid")
|
||||
!xrayEnabled || hybridEnabled || ob.singBoxJson == null
|
||||
) "proxy-suite: outbound '${ob.tag}': singBoxJson requires proxy.backend = sing-box or hybrid")
|
||||
(mkAssertion (
|
||||
!(ob.backend == "xray") || xrayEnabled
|
||||
) "proxy-suite: outbound '${ob.tag}': backend = \"xray\" requires proxy.backend = xray or hybrid")
|
||||
@@ -284,7 +283,7 @@ let
|
||||
# A pinned outbound is rendered by the XRay renderer inside the inbound
|
||||
# service, so a sing-box-only definition cannot serve as one.
|
||||
singBoxOnlyPinnedTags = map (ob: ob.tag) (
|
||||
builtins.filter (ob: ob.singBoxJson != null || ob.json != null) derived.proxyInboundViaOutbounds
|
||||
builtins.filter (ob: ob.singBoxJson != null) derived.proxyInboundViaOutbounds
|
||||
);
|
||||
|
||||
proxyInboundAssertions = [
|
||||
|
||||
@@ -16,7 +16,8 @@ if pureXrayEnabled then
|
||||
{balancerTag:"proxy"}
|
||||
end;
|
||||
def xray_rewrite_proxy_rule($single_tag):
|
||||
if $single_tag != "" and (.balancerTag? // "") == "proxy" then
|
||||
# "proxy" is a balancer in urltest and no outbound at all in "first": either way, the one exit.
|
||||
if $single_tag != "" and ((.balancerTag? // .outboundTag? // "") == "proxy") then
|
||||
.outboundTag = $single_tag | del(.balancerTag)
|
||||
else
|
||||
.
|
||||
|
||||
@@ -19,46 +19,39 @@ lib.optionalString hybridEnabled ''
|
||||
OUTBOUNDS_JSON=$(${jq} --argjson ob "$ob" '. + [$ob]' <<< "$OUTBOUNDS_JSON")
|
||||
}
|
||||
|
||||
_proxy_suite_next_xray_sidecar_port() {
|
||||
local port="$XRAY_SIDECAR_NEXT_PORT"
|
||||
XRAY_SIDECAR_NEXT_PORT=$((XRAY_SIDECAR_NEXT_PORT + 1))
|
||||
printf '%s\n' "$port"
|
||||
# $1 a JSON array of XRay outbounds, each tagged. One jq pass for the lot: each gets a
|
||||
# loopback SOCKS inbound on the sidecar and stands in sing-box as a hop to it.
|
||||
_proxy_suite_add_xray_sidecar_obs() {
|
||||
local batch
|
||||
batch=$(${jq} -c \
|
||||
--argjson base "$XRAY_SIDECAR_NEXT_PORT" \
|
||||
--argjson mark ${toString xraySidecarRoutingMark} '
|
||||
to_entries | map(
|
||||
($base + .key) as $port
|
||||
| ("proxy-suite-xray-" + ($port | tostring)) as $auth
|
||||
| .value.tag as $tag
|
||||
| {outbound: (.value
|
||||
| .streamSettings.sockopt.mark = $mark
|
||||
| .streamSettings.sockopt.domainStrategy = (.streamSettings.sockopt.domainStrategy // "UseIP")),
|
||||
inbound: {tag: ($tag + "-inbound"), listen: "127.0.0.1", port: $port, protocol: "socks",
|
||||
settings: {auth: "password", udp: true, accounts: [{user: $auth, pass: $auth}]}},
|
||||
rule: {type: "field", inboundTag: [$tag + "-inbound"], outboundTag: $tag},
|
||||
hop: ({type: "socks", tag: $tag, server: "127.0.0.1", server_port: $port, version: "5",
|
||||
username: $auth, password: $auth}${
|
||||
lib.optionalString (routingMark != null) " + {routing_mark: ${toString routingMark}}"
|
||||
})})
|
||||
| {outbounds: map(.outbound), inbounds: map(.inbound), rules: map(.rule), hops: map(.hop)}
|
||||
' <<< "$1")
|
||||
XRAY_SIDECAR_NEXT_PORT=$((XRAY_SIDECAR_NEXT_PORT + $(${jq} '.outbounds | length' <<< "$batch")))
|
||||
XRAY_OUTBOUNDS_JSON=$(${jq} -c --argjson b "$batch" '. + $b.outbounds' <<< "$XRAY_OUTBOUNDS_JSON")
|
||||
XRAY_INBOUNDS_JSON=$(${jq} -c --argjson b "$batch" '. + $b.inbounds' <<< "$XRAY_INBOUNDS_JSON")
|
||||
XRAY_ROUTE_RULES_JSON=$(${jq} -c --argjson b "$batch" '. + $b.rules' <<< "$XRAY_ROUTE_RULES_JSON")
|
||||
OUTBOUNDS_JSON=$(${jq} -c --argjson b "$batch" '. + $b.hops' <<< "$OUTBOUNDS_JSON")
|
||||
}
|
||||
|
||||
# $1 one XRay outbound, $2 its tag.
|
||||
_proxy_suite_add_xray_sidecar_ob() {
|
||||
local ob="$1" tag="$2" port auth inbound_tag sing_ob inbound route_rule
|
||||
port="$(_proxy_suite_next_xray_sidecar_port)"
|
||||
auth="proxy-suite-xray-$port"
|
||||
inbound_tag="$tag-inbound"
|
||||
ob=$(${jq} \
|
||||
--arg tag "$tag" \
|
||||
--argjson mark ${toString xraySidecarRoutingMark} \
|
||||
'.tag = $tag
|
||||
| .streamSettings = (.streamSettings // {})
|
||||
| .streamSettings.sockopt = (.streamSettings.sockopt // {})
|
||||
| .streamSettings.sockopt.mark = $mark
|
||||
| .streamSettings.sockopt.domainStrategy = (.streamSettings.sockopt.domainStrategy // "UseIP")' \
|
||||
<<< "$ob")
|
||||
XRAY_OUTBOUNDS_JSON=$(${jq} --argjson ob "$ob" '. + [$ob]' <<< "$XRAY_OUTBOUNDS_JSON")
|
||||
inbound=$(${jq} -n \
|
||||
--arg tag "$inbound_tag" \
|
||||
--arg auth "$auth" \
|
||||
--argjson port "$port" \
|
||||
'{tag:$tag,listen:"127.0.0.1",port:$port,protocol:"socks",settings:{auth:"password",udp:true,accounts:[{user:$auth,pass:$auth}]}}')
|
||||
XRAY_INBOUNDS_JSON=$(${jq} --argjson inbound "$inbound" '. + [$inbound]' <<< "$XRAY_INBOUNDS_JSON")
|
||||
route_rule=$(${jq} -n \
|
||||
--arg inbound "$inbound_tag" \
|
||||
--arg outbound "$tag" \
|
||||
'{type:"field",inboundTag:[$inbound],outboundTag:$outbound}')
|
||||
XRAY_ROUTE_RULES_JSON=$(${jq} --argjson rule "$route_rule" '. + [$rule]' <<< "$XRAY_ROUTE_RULES_JSON")
|
||||
sing_ob=$(${jq} -n \
|
||||
--arg tag "$tag" \
|
||||
--arg auth "$auth" \
|
||||
--argjson port "$port" \
|
||||
'{type:"socks",tag:$tag,server:"127.0.0.1",server_port:$port,version:"5",username:$auth,password:$auth${
|
||||
lib.optionalString (routingMark != null) ",routing_mark:${toString routingMark}"
|
||||
}}')
|
||||
OUTBOUNDS_JSON=$(${jq} --argjson ob "$sing_ob" '. + [$ob]' <<< "$OUTBOUNDS_JSON")
|
||||
_proxy_suite_add_xray_sidecar_obs "$(${jq} -c --arg tag "$2" '[.tag = $tag]' <<< "$1")"
|
||||
}
|
||||
|
||||
_proxy_suite_write_xray_sidecar_config() {
|
||||
|
||||
@@ -39,13 +39,7 @@ let
|
||||
rawOutboundJson =
|
||||
ob: tag: routingMark:
|
||||
let
|
||||
backendRaw =
|
||||
if pureXrayEnabled then
|
||||
ob.xrayJson
|
||||
else if ob.singBoxJson != null then
|
||||
ob.singBoxJson
|
||||
else
|
||||
ob.json;
|
||||
backendRaw = if pureXrayEnabled then ob.xrayJson else ob.singBoxJson;
|
||||
markAttrs =
|
||||
if routingMark == null then
|
||||
{ }
|
||||
@@ -218,16 +212,7 @@ let
|
||||
|
||||
mkOutboundBlock =
|
||||
ob: routingMark: tag:
|
||||
let
|
||||
backendRaw =
|
||||
if pureXrayEnabled then
|
||||
ob.xrayJson
|
||||
else if ob.singBoxJson != null then
|
||||
ob.singBoxJson
|
||||
else
|
||||
ob.json;
|
||||
in
|
||||
if backendRaw != null then
|
||||
if (if pureXrayEnabled then ob.xrayJson else ob.singBoxJson) != null then
|
||||
let
|
||||
outboundJson = builtins.toJSON (rawOutboundJson ob tag routingMark);
|
||||
jsonFile = pkgs.writeText "proxy-suite-core" outboundJson;
|
||||
@@ -249,26 +234,14 @@ let
|
||||
|
||||
singBoxRawOutboundJson =
|
||||
ob: tag: routingMark:
|
||||
let
|
||||
backendRaw = if ob.singBoxJson != null then ob.singBoxJson else ob.json;
|
||||
markAttrs = lib.optionalAttrs (routingMark != null) { routing_mark = routingMark; };
|
||||
in
|
||||
backendRaw // { inherit tag; } // markAttrs;
|
||||
|
||||
xrayRawOutboundJson =
|
||||
ob: tag:
|
||||
lib.recursiveUpdate (ob.xrayJson // { inherit tag; }) {
|
||||
streamSettings.sockopt = {
|
||||
mark = xraySidecarRoutingMark;
|
||||
domainStrategy = "UseIP";
|
||||
};
|
||||
};
|
||||
ob.singBoxJson // { inherit tag; } // lib.optionalAttrs (routingMark != null) { routing_mark = routingMark; };
|
||||
|
||||
mkHybridOutboundBlock =
|
||||
ob: routingMark: tag:
|
||||
if ob.xrayJson != null then
|
||||
let
|
||||
outboundJson = builtins.toJSON (xrayRawOutboundJson ob tag);
|
||||
# The sidecar helper adds the tag, its mark, and UseIP unless one is set.
|
||||
outboundJson = builtins.toJSON ob.xrayJson;
|
||||
jsonFile = pkgs.writeText "proxy-suite-core" outboundJson;
|
||||
in
|
||||
''
|
||||
@@ -277,7 +250,7 @@ let
|
||||
_proxy_suite_add_xray_sidecar_ob "$OB_JSON" ${lib.escapeShellArg tag}
|
||||
_proxy_suite_record_tag_source ${lib.escapeShellArg tag} static
|
||||
''
|
||||
else if ob.singBoxJson != null || ob.json != null then
|
||||
else if ob.singBoxJson != null then
|
||||
let
|
||||
outboundJson = builtins.toJSON (singBoxRawOutboundJson ob tag routingMark);
|
||||
jsonFile = pkgs.writeText "proxy-suite-core" outboundJson;
|
||||
@@ -598,10 +571,14 @@ let
|
||||
if [ -z "$PROXY_TAG" ]; then
|
||||
PROXY_TAG=$(${jq} -r '.[0]' <<< "$SELECTABLE_TAGS_JSON")
|
||||
fi
|
||||
OUTBOUNDS_JSON=$(${jq} --arg t "$PROXY_TAG" \
|
||||
'map(if .tag == $t then .tag = "proxy" else . end
|
||||
| if .detour == $t then .detour = "proxy" else . end
|
||||
| if .streamSettings.sockopt.dialerProxy? == $t then .streamSettings.sockopt.dialerProxy = "proxy" else . end)' <<< "$OUTBOUNDS_JSON")
|
||||
# Every tag stays, so rules naming another outbound still reach it; "proxy"
|
||||
# only stands for the pick.
|
||||
${
|
||||
if pureXrayEnabled then
|
||||
''XRAY_SINGLE_PROXY_TAG="$PROXY_TAG"''
|
||||
else
|
||||
''OUTBOUNDS_JSON=$(${jq} --arg t "$PROXY_TAG" '[{type:"selector",tag:"proxy",outbounds:[$t],default:$t}] + .' <<< "$OUTBOUNDS_JSON")''
|
||||
}
|
||||
''
|
||||
else if selectionMode == "selector" then
|
||||
''
|
||||
|
||||
@@ -116,10 +116,7 @@ let
|
||||
''
|
||||
SUB_SING_BOX_JSON=$(${jq} -c '.singBox' "$cache")
|
||||
${markBlock}OUTBOUNDS_JSON=$(${jq} --argjson sub "$SUB_SING_BOX_JSON" '. + $sub' <<< "$OUTBOUNDS_JSON")
|
||||
while IFS= read -r SUB_XRAY_OB; do
|
||||
SUB_XRAY_TAG="$(${jq} -r '.tag' <<< "$SUB_XRAY_OB")"
|
||||
_proxy_suite_add_xray_sidecar_ob "$SUB_XRAY_OB" "$SUB_XRAY_TAG"
|
||||
done < <(${jq} -c '.xray[]' "$cache")
|
||||
_proxy_suite_add_xray_sidecar_obs "$(${jq} -c '.xray' "$cache")"
|
||||
''
|
||||
else
|
||||
''
|
||||
|
||||
@@ -235,11 +235,11 @@ let
|
||||
|
||||
${lib.optionalString enableOutboundTest ''
|
||||
# proxy-ctl proxy outbounds test. Servers for its ping, keyed by the user's tag:
|
||||
# the wrapper may have renamed one outbound "proxy" or prefixed them all, and a
|
||||
# XRay's urltest wrapper prefixes them all, and a
|
||||
# hybrid XRay outbound is a sing-box socks hop whose real server is the sidecar's.
|
||||
# A loopback hop (the WARP tunnel, XRay's SSH listener) has no server worth timing.
|
||||
ENDPOINTS_TMP="$RUNTIME_DIR/outbound-endpoints.json.tmp"
|
||||
${jq} -c --argjson sidecar "''${XRAY_OUTBOUNDS_JSON:-[]}" --arg collapsed "''${PROXY_TAG:-}" '
|
||||
${jq} -c --argjson sidecar "''${XRAY_OUTBOUNDS_JSON:-[]}" '
|
||||
def endpoint:
|
||||
if .server then {server, port: .server_port}
|
||||
elif .settings.address then {server: .settings.address, port: .settings.port}
|
||||
@@ -249,7 +249,7 @@ let
|
||||
def udp: (.type // .protocol) as $t | (["hysteria", "hysteria2", "tuic"] | index($t) != null) or .quic? == true;
|
||||
($sidecar | map({key: .tag, value: .}) | from_entries) as $real
|
||||
| [.[] | select(.type != "selector" and .type != "urltest")
|
||||
| (.tag | ltrimstr("proxy-suite-ob-") | if . == "proxy" then $collapsed else . end) as $tag
|
||||
| (.tag | ltrimstr("proxy-suite-ob-")) as $tag
|
||||
| ($real[.tag] // .) | select(endpoint != null and (endpoint.server | test("^(127\\.|::1$|localhost$)") | not))
|
||||
| {key: $tag, value: (endpoint + {network: (if udp then "udp" else "tcp" end)})}]
|
||||
| from_entries
|
||||
@@ -269,11 +269,11 @@ let
|
||||
# proxy-ctl's share links: the URL each outbound was given, and its backend JSON.
|
||||
# Credentials: root and the userControl group only.
|
||||
SHARE_TMP="$RUNTIME_DIR/outbound-share.json.tmp"
|
||||
(umask 077 && ${jq} -c --argjson sidecar "''${XRAY_OUTBOUNDS_JSON:-[]}" --arg collapsed "''${PROXY_TAG:-}" \
|
||||
(umask 077 && ${jq} -c --argjson sidecar "''${XRAY_OUTBOUNDS_JSON:-[]}" \
|
||||
--argjson urls "$OUTBOUND_URLS_JSON" --argjson subs "$SUBSCRIPTION_URLS_JSON" '
|
||||
($sidecar | map({key: .tag, value: .}) | from_entries) as $real
|
||||
| {outbounds: ([.[] | select(.type != "selector" and .type != "urltest")
|
||||
| (.tag | ltrimstr("proxy-suite-ob-") | if . == "proxy" then $collapsed else . end) as $tag
|
||||
| (.tag | ltrimstr("proxy-suite-ob-")) as $tag
|
||||
| {key: $tag, value: {url: $urls[$tag], outbound: (($real[$tag] // $real[.tag] // .) | .tag = $tag)}}]
|
||||
| from_entries),
|
||||
subscriptions: $subs}
|
||||
@@ -291,10 +291,10 @@ let
|
||||
listen: "127.0.0.1", listen_port: ${toString outboundTestPort}}]' <<< "$PROBE_INBOUNDS_JSON")
|
||||
PROBE_PIN_RULES_JSON=$(${jq} -c \
|
||||
'. + [{inbound: ["proxy-suite-test-in"], outbound: "proxy-suite-test"}]' <<< "$PROBE_PIN_RULES_JSON")
|
||||
${jq} -n --argjson tags "$EXIT_TAGS_JSON" --arg collapsed "''${PROXY_TAG:-}" \
|
||||
${jq} -n --argjson tags "$EXIT_TAGS_JSON" \
|
||||
--arg url ${lib.escapeShellArg proxyCfg.urlTest.url} '
|
||||
{port: ${toString outboundTestPort}, selector: "proxy-suite-test", url: $url,
|
||||
outbounds: ($tags | map({key: (if . == "proxy" then $collapsed else . end), value: .}) | from_entries)}
|
||||
outbounds: ($tags | map({key: ., value: .}) | from_entries)}
|
||||
' > "$RUNTIME_DIR/outbound-test.json"
|
||||
# Tags and a loopback port only.
|
||||
chmod 644 "$RUNTIME_DIR/outbound-test.json"
|
||||
|
||||
Reference in new issue
Block a user