fix: bug fixes

This commit is contained in:
fufsob committed 2026-09-16 08:43:53 +00:00
1 parent 9cdd6dada7
commit 027dc7b1a9
31 files changed
+626 -121

No files matched your search

@@ -102,6 +102,18 @@ let
if ${curl} -sf -X PUT "${clashApi}/proxies/proxy" \
-H "Content-Type: application/json" \
-d "$(${jq} -cn --arg name "$tag" '{name:$name}')" >/dev/null 2>&1; then
# A live switch skips the restart that rewrites the inventory, and the pin
# is only ever read from there: without this the outbound reads as merely
# current, and the front ends offer no unpin until the next restart.
if [ -f "${outboundInventoryFile}" ]; then
INVENTORY_TMP=$(mktemp "${outboundInventoryFile}.XXXXXX")
if ${jq} --arg t "$tag" '.pinned = $t' "${outboundInventoryFile}" > "$INVENTORY_TMP"; then
chmod 644 "$INVENTORY_TMP"
mv -f "$INVENTORY_TMP" "${outboundInventoryFile}"
else
rm -f "$INVENTORY_TMP"
fi
fi
${restartActiveBlock tunConsumers}
exit 0
fi
+35
View File
@@ -275,4 +275,39 @@ lib.mkMerge [
systemd.timers = mkNamedUnits timerEntries;
}
# A certificate or key XRay cannot read is copied in at start (proxy-inbounds-scripts.nix),
# and a copy never sees a renewal: restart the inbounds when a declared one changes.
# ponytail: files named only inside xrayJson are not watched; declare tls.* for those.
(
let
certFiles = lib.unique (
lib.concatMap (
l:
lib.filter (f: f != null) [
l.tls.certificateFile
l.tls.keyFile
]
) (builtins.attrValues cfg.inbounds.listeners)
);
in
lib.mkIf (cfg.enable && proxyInboundsEnabled && certFiles != [ ]) {
systemd.paths.proxy-suite-inbounds-certs = {
description = "proxy-suite - watch the inbounds' TLS certificates for renewals";
wantedBy = [ "paths.target" ];
pathConfig.PathChanged = certFiles;
};
systemd.services.proxy-suite-inbounds-certs = {
description = "proxy-suite - restart the inbounds onto a renewed certificate";
serviceConfig.Type = "oneshot";
script = ''
# XRay reloads the files it reads itself; only copies go stale.
[ -d /run/proxy-suite-inbounds/tls ] || exit 0
# A renewal writes the chain and the key one after the other.
sleep 10
${pkgs.systemd}/bin/systemctl try-restart proxy-suite-inbounds.service
'';
};
}
)
]
@@ -200,13 +200,14 @@ let
'';
# Adds XRay's counters to the daily totals, read and reset in one call, and notes who
# is online.
# ponytail: a restart of the inbounds loses what was counted since the last run, at
# most one timer interval; collect from ExecStop if that matters.
# is online. Run by a timer, and by the inbounds' ExecStop, so a restart loses nothing.
collectInboundStats = pkgs.writeShellScript "proxy-suite-inbounds" ''
set -euo pipefail
file=${lib.escapeShellArg constants.inboundStatsFile}
api=--server=127.0.0.1:${toString constants.inboundStatsApiPort}
# A timer run and a stop can overlap: each reads and resets part, and both rewrite the file.
exec 9> "$file.lock"
${pkgs.util-linux}/bin/flock 9
if ! reading=$(${xray} api statsquery "$api" -pattern "" -reset 2> /dev/null); then
echo "the inbounds' stats API is not answering; nothing collected"
exit 0
+12 -5
View File
@@ -40,7 +40,10 @@ let
xraySidecarBasePorts
;
autoProxyRender = import ../autoproxy-render.nix { inherit pkgs; };
autoProxyRender = import ../autoproxy-render.nix {
inherit pkgs;
inherit (constants) serviceUser;
};
runBackend = constants.runAsServiceUser pkgs constants.backendCaps;
userControlGroup = lib.escapeShellArg userControlCfg.group;
chgrp = "${pkgs.coreutils}/bin/chgrp";
@@ -171,9 +174,13 @@ let
${hybridRuntimeHelpersBlock routingMark xraySidecarBasePort xrayDnsBridgePort}
${subscriptionCacheHelpersBlock}
${lib.optionalString enableLocalProxyAuth ''
umask 077
LOCAL_PROXY_PASSWORD="$(cat "${localProxyAuthPasswordSource}")"
${writeProxychainsConfigBlock}
# The umask stays in the subshell: left set, it also narrowed everything
# written below, and autoProxy's state.json is group-readable by design.
(
umask 077
${writeProxychainsConfigBlock}
)
''}
${lib.optionalString xrayEnabled ''
if [ -r "${xrayLoglevelFile}" ]; then
@@ -210,7 +217,7 @@ let
AUTOPROXY_RULES_JSON='[]'
${lib.optionalString enableAutoProxy ''
AUTOPROXY_DIR=${lib.escapeShellArg autoProxyStateDir}
# 0751: sing-box, running as ${constants.serviceUser}, reads the rule-sets inside;
# 0751: sing-box, running as ${constants.serviceUser}, reaches the rules/ inside;
# 0771 with userControl's autoProxy scope, whose group queues learn requests there.
install -d -m ${if userControlAllows "autoProxy" then "0771" else "0751"} "$AUTOPROXY_DIR"
[ -s "$AUTOPROXY_DIR/state.json" ] || echo '{"domains":{},"hosts":{},"exits":{},"backlog":{}}' > "$AUTOPROXY_DIR/state.json"
@@ -225,7 +232,7 @@ let
| to_entries
| map({i: .key, tag: .value, port: ($base + .key),
rule_set: ("autoproxy-" + (.key | tostring)),
path: ($dir + "/rs-" + (.key | tostring) + ".json")})
path: ($dir + "/rules/rs-" + (.key | tostring) + ".json")})
' <<< "$EXIT_TAGS_JSON")
printf '%s\n' "$PROBE_EXITS_JSON" > "$RUNTIME_DIR/probe-exits.json"
# proxy-ctl reads it unprivileged; it holds tags and loopback ports only.
+9 -3
View File
@@ -105,7 +105,12 @@ let
wantedBy = [ "multi-user.target" ];
execStart = scripts.startInbounds;
runtimeDirectory = serviceNames.inbounds;
extraServiceConfig = xrayAssetEnv;
# The collector's file.
stateDirectory = "proxy-suite";
# While XRay still runs: what it counted since the last timer run.
extraServiceConfig = xrayAssetEnv // {
ExecStop = scripts.collectInboundStats;
};
};
}
{
@@ -246,8 +251,9 @@ let
enable = proxyEnabled;
name = "proxy-suite-outbound-pin@";
value = mkOneshotService {
description = "Pin the proxy-suite outbound to %i";
execStart = "${scripts.pinOutboundScript} %i";
# %I: proxy-ctl systemd-escapes the tag, so "ssh-proxy" arrives as ssh\x2dproxy.
description = "Pin the proxy-suite outbound to %I";
execStart = "${scripts.pinOutboundScript} %I";
stateDirectory = "proxy-suite";
extraServiceConfig.RemainAfterExit = false;
};