From 110e33bc27348e0039fbddbe060a219a996c778d Mon Sep 17 00:00:00 2001 From: FUFSoB Date: Mon, 18 May 2026 18:25:08 +0500 Subject: [PATCH] fix: tun not working --- modules/proxy-suite/config.nix | 13 +++++++++++-- nix/checks.nix | 9 ++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/proxy-suite/config.nix b/modules/proxy-suite/config.nix index 5cbecaa..f41009b 100644 --- a/modules/proxy-suite/config.nix +++ b/modules/proxy-suite/config.nix @@ -138,7 +138,12 @@ let rules = rules.routingRules; final = if singBoxCfg.proxyByDefault then "proxy" else "direct"; } - // lib.optionalAttrs (enableTun && tunAutoRoute) { auto_detect_interface = true; }; + // lib.optionalAttrs (enableTun && tunAutoRoute) { + # sing-box recommends this with auto_route to keep its own outbound + # connections pinned to the host's default NIC instead of looping back + # into the TUN interface. + auto_detect_interface = true; + }; } // lib.optionalAttrs enableClashApi clashApiBlock; @@ -156,7 +161,11 @@ let tunAutoRoute = true; tunAutoRedirect = true; tunStrictRoute = true; - forceLocalDnsViaProxy = true; + # Keep the bootstrap resolver on the direct path. Sending the "local" DNS + # transport through outbound tag "proxy" causes a resolver loop in global + # TUN mode because outbound hostname resolution and urltest probe lookups + # recurse back into the same proxy path. + forceLocalDnsViaProxy = false; enableClashApi = false; }; diff --git a/nix/checks.nix b/nix/checks.nix index 142945b..171a0f2 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -1459,6 +1459,7 @@ let in assert inbound.iproute2_table_index == 2022; assert inbound.iproute2_rule_index == 9000; + assert tunDefaultConfig.route.auto_detect_interface == true; true ) ( @@ -1470,7 +1471,8 @@ let assert pkgs.lib.hasInfix ''delete table inet sing-box'' tunCleanupScript; assert pkgs.lib.hasInfix ''rule del table 2022'' tunCleanupScript; assert pkgs.lib.hasInfix ''route flush table 2022'' tunCleanupScript; - assert pkgs.lib.hasInfix "link del dev 'singtun0'" tunCleanupScript; + assert pkgs.lib.hasInfix "link del dev" tunCleanupScript; + assert pkgs.lib.hasInfix "singtun0" tunCleanupScript; true ) ( @@ -1571,7 +1573,7 @@ let let localDns = dnsServerByTag tunDefaultConfig "local"; in - assert localDns.detour == "proxy"; + assert !(localDns ? detour); true ) ( @@ -2068,7 +2070,8 @@ let assert perAppRoutingTunFixture.config.systemd.services ? "proxy-suite-per-app-tun-user@"; assert perAppRoutingTunFixture.config.systemd.user.services ? "proxy-suite-per-app-tun-anchor"; assert perAppRoutingTunServiceConfig.ExecStartPre == perAppRoutingTunServiceConfig.ExecStopPost; - assert pkgs.lib.hasInfix "link del dev 'psperapptun0'" perAppRoutingTunCleanupScript; + assert pkgs.lib.hasInfix "link del dev" perAppRoutingTunCleanupScript; + assert pkgs.lib.hasInfix "psperapptun0" perAppRoutingTunCleanupScript; assert pkgs.lib.hasInfix "rule del fwmark 16 table 101" perAppRoutingTunCleanupScript; true )