other fixes

This commit is contained in:
FUFSoB committed 2026-05-18 11:03:10 +05:00
1 parent 70c0454446
commit 86e229ff4c
11 files changed
+339 -10

No files matched your search

+32
View File
@@ -9,6 +9,13 @@
let
t = cfg.tgWsProxy;
tgPkg = packages.tg-ws-proxy;
ip = "${pkgs.iproute2}/bin/ip";
transparentBypassEnabled =
t.bypassTransparentProxy
&& cfg.singBox.enable
&& (cfg.singBox.tun.enable || cfg.singBox.tproxy.enable);
bypassRulePriority = 8999;
dcArgs = lib.concatMapStrings
(id: " --dc-ip=${lib.escapeShellArg "${id}:${t.dcIps.${id}}"}")
@@ -24,6 +31,26 @@ let
"--secret=${lib.escapeShellArg t.secret}"
}${dcArgs}
'';
bypassUpScript = pkgs.writeShellScript "proxy-suite-tg-ws-proxy-bypass-up" ''
set -euo pipefail
add_bypass_rule() {
local family="$1"
while ${ip} "$family" rule del pref ${toString bypassRulePriority} fwmark ${toString t.routingMark} lookup main 2>/dev/null; do :; done
${ip} "$family" rule add pref ${toString bypassRulePriority} fwmark ${toString t.routingMark} lookup main 2>/dev/null || true
}
add_bypass_rule -4
add_bypass_rule -6
'';
bypassDownScript = pkgs.writeShellScript "proxy-suite-tg-ws-proxy-bypass-down" ''
set +e
while ${ip} -4 rule del pref ${toString bypassRulePriority} fwmark ${toString t.routingMark} lookup main 2>/dev/null; do :; done
while ${ip} -6 rule del pref ${toString bypassRulePriority} fwmark ${toString t.routingMark} lookup main 2>/dev/null; do :; done
'';
in
{
systemd.services.proxy-suite-tg-ws-proxy = {
@@ -35,6 +62,11 @@ in
LoadCredential = lib.optional (t.secretFile != null) "tg_ws_proxy_secret:${t.secretFile}";
Restart = "on-failure";
RestartSec = 5;
}
// lib.optionalAttrs transparentBypassEnabled {
ExecStartPre = bypassUpScript;
ExecStopPost = bypassDownScript;
SocketMark = toString t.routingMark;
};
};
}