diff --git a/docs/options.md b/docs/options.md
index 7b65371..761cc0b 100644
--- a/docs/options.md
+++ b/docs/options.md
@@ -39,6 +39,7 @@ Update module option docs there instead of editing this file by hand.
- [listenAddress](#services-proxy-suite-proxy-listenaddress)
- [outbounds](#services-proxy-suite-proxy-outbounds)
- item
+ - [backend](#services-proxy-suite-proxy-outbounds-backend)
- routing
- [domains](#services-proxy-suite-proxy-outbounds-routing-domains)
- [geoips](#services-proxy-suite-proxy-outbounds-routing-geoips)
@@ -978,8 +979,10 @@ true
Whether to configure and run the proxy backend services\.
-This is disabled by default; enable it explicitly and choose exactly
-one backend with proxy\.singBox\.enable or proxy\.xray\.enable\.
+This is disabled by default; enable it explicitly and choose at least
+one backend with proxy\.singBox\.enable or proxy\.xray\.enable\. Enabling
+both runs sing-box as the frontend and XRay as a sidecar for outbounds
+that require XRay\.
@@ -1470,6 +1473,42 @@ list of (submodule)
+
+## services\.proxy-suite\.proxy\.outbounds\.\*\.backend
+
+
+
+Backend preference for this outbound when both SingBox and XRay are
+enabled\. “auto” uses SingBox when the URL or JSON can be represented
+there and falls back to XRay for XRay-only transports such as XHTTP
+or ECH\. Ignored by single-backend configurations\.
+
+
+
+*Type:*
+one of “auto”, “sing-box”, “xray”
+
+
+
+*Default:*
+
+```nix
+"auto"
+```
+
+
+
+*Example:*
+
+```nix
+"xray"
+```
+
+*Declared by:*
+ - [modules/proxy-suite/options/sing-box-outbounds\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options/sing-box-outbounds.nix)
+
+
+
## services\.proxy-suite\.proxy\.outbounds\.\*\.routing\.domains
@@ -4217,8 +4256,6 @@ null
## services\.proxy-suite\.tray\.enable
-
-
Whether to enable system tray indicator for proxy-suite\.
@@ -4284,6 +4321,8 @@ true
## services\.proxy-suite\.tray\.pollInterval
+
+
Tray status refresh interval in seconds\.
Lower values make UI state changes appear faster, while higher values
reduce background polling overhead\.
@@ -4453,6 +4492,7 @@ true
- [modules/proxy-suite/options/zapret\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options/zapret.nix)
+
## services\.proxy-suite\.zapret\.cidrExemption\.enable
@@ -5199,4 +5239,3 @@ true
*Declared by:*
- [modules/proxy-suite/options/zapret\.nix](https://github.com/FUFSoB/proxy-suite-flake/blob/main/modules/proxy-suite/options/zapret.nix)
-
diff --git a/modules/proxy-suite/config.nix b/modules/proxy-suite/config.nix
index 91f0b7f..b089d5e 100644
--- a/modules/proxy-suite/config.nix
+++ b/modules/proxy-suite/config.nix
@@ -13,6 +13,8 @@ let
proxyCfg
singBoxCfg
xrayEnabled
+ hybridEnabled
+ pureXrayEnabled
globalTun
globalTproxy
clashApiEnabled
@@ -88,6 +90,8 @@ let
forceLocalDnsViaProxy ? false,
useOutboundRoutingMark ? false,
enableClashApi ? clashApiEnabled,
+ enableXrayDnsBridge ? hybridEnabled,
+ xrayDnsBridgePort ? 18533,
}:
{
log.level = "warn";
@@ -97,7 +101,13 @@ let
};
inbounds =
- lib.optional enableMixed {
+ lib.optional enableXrayDnsBridge {
+ type = "direct";
+ tag = "xray-dns-in";
+ listen = "127.0.0.1";
+ listen_port = xrayDnsBridgePort;
+ }
+ ++ lib.optional enableMixed {
type = "mixed";
tag = "mixed-in";
listen = proxyCfg.listenAddress;
@@ -154,20 +164,14 @@ let
// lib.optionalAttrs enableClashApi clashApiBlock;
xrayDnsAddress =
- upstream:
- if upstream.type == "tcp" then
- "tcp://${upstream.address}"
- else
- upstream.address;
+ upstream: if upstream.type == "tcp" then "tcp://${upstream.address}" else upstream.address;
- mkXrayDnsServer =
- tag: upstream:
- {
- address = xrayDnsAddress upstream;
- inherit tag;
- port = upstream.port;
- queryStrategy = "UseIP";
- };
+ mkXrayDnsServer = tag: upstream: {
+ address = xrayDnsAddress upstream;
+ inherit tag;
+ port = upstream.port;
+ queryStrategy = "UseIP";
+ };
mkXraySniffing =
{
@@ -245,8 +249,9 @@ let
{ outboundTag = tag; }
);
- xrayRouteRules =
- rules.xrayRoutingRules ++ [ (xrayFinalRule (if proxyCfg.proxyByDefault then "proxy" else "direct")) ];
+ xrayRouteRules = rules.xrayRoutingRules ++ [
+ (xrayFinalRule (if proxyCfg.proxyByDefault then "proxy" else "direct"))
+ ];
xrayDirectOutbound =
useOutboundRoutingMark:
@@ -371,7 +376,9 @@ let
{
tag = "proxy";
selector = [ "proxy-suite-ob-" ];
- strategy = { type = "leastPing"; };
+ strategy = {
+ type = "leastPing";
+ };
}
];
};
@@ -389,6 +396,7 @@ let
enableMixed = true;
enableTProxy = true;
useOutboundRoutingMark = true;
+ xrayDnsBridgePort = 18533;
};
singBoxTunTemplate = mkSingBoxConfig {
@@ -401,6 +409,7 @@ let
tunStrictRoute = true;
forceLocalDnsViaProxy = false;
enableClashApi = false;
+ xrayDnsBridgePort = 18534;
};
singBoxPerAppTunTemplate = mkSingBoxConfig {
@@ -414,6 +423,7 @@ let
forceLocalDnsViaProxy = false;
useOutboundRoutingMark = globalTproxy.enable;
enableClashApi = false;
+ xrayDnsBridgePort = 18535;
};
xrayTproxyTemplate = mkXrayConfig {
@@ -442,10 +452,10 @@ let
enableTunFakeDns = true;
};
- tproxyTemplate = if xrayEnabled then xrayTproxyTemplate else singBoxTproxyTemplate;
- tunTemplate = if xrayEnabled then xrayTunTemplate else singBoxTunTemplate;
- perAppTunTemplate = if xrayEnabled then xrayPerAppTunTemplate else singBoxPerAppTunTemplate;
- routeModeRules = if xrayEnabled then rules.xrayRouteModeRules else rules.singBoxRouteModeRules;
+ tproxyTemplate = if pureXrayEnabled then xrayTproxyTemplate else singBoxTproxyTemplate;
+ tunTemplate = if pureXrayEnabled then xrayTunTemplate else singBoxTunTemplate;
+ perAppTunTemplate = if pureXrayEnabled then xrayPerAppTunTemplate else singBoxPerAppTunTemplate;
+ routeModeRules = if pureXrayEnabled then rules.xrayRouteModeRules else rules.singBoxRouteModeRules;
tproxyFile = pkgs.writeText "proxy-suite-tproxy-template.json" (builtins.toJSON tproxyTemplate);
tunFile = pkgs.writeText "proxy-suite-tun-template.json" (builtins.toJSON tunTemplate);
@@ -458,5 +468,10 @@ let
in
{
- inherit tproxyFile tunFile perAppTunFile routeModeRulesFile;
+ inherit
+ tproxyFile
+ tunFile
+ perAppTunFile
+ routeModeRulesFile
+ ;
}
diff --git a/modules/proxy-suite/derived.nix b/modules/proxy-suite/derived.nix
index 5cea743..de53482 100644
--- a/modules/proxy-suite/derived.nix
+++ b/modules/proxy-suite/derived.nix
@@ -5,22 +5,27 @@
let
proxyCfg = cfg.proxy;
- singBoxCfg =
- proxyCfg
- // {
- enable = proxyCfg.enable && proxyCfg.singBox.enable;
- package = proxyCfg.singBox.package;
- clashApiPort = proxyCfg.singBox.clashApiPort;
- urlTest = proxyCfg.urlTest // { tolerance = proxyCfg.singBox.urlTest.tolerance; };
+ singBoxCfg = proxyCfg // {
+ enable = proxyCfg.enable && proxyCfg.singBox.enable;
+ package = proxyCfg.singBox.package;
+ clashApiPort = proxyCfg.singBox.clashApiPort;
+ urlTest = proxyCfg.urlTest // {
+ tolerance = proxyCfg.singBox.urlTest.tolerance;
};
+ };
xrayCfg = proxyCfg.xray;
proxyEnabled = proxyCfg.enable;
singBoxEnabled = proxyCfg.enable && proxyCfg.singBox.enable;
xrayEnabled = proxyCfg.enable && proxyCfg.xray.enable;
+ hybridEnabled = singBoxEnabled && xrayEnabled;
+ pureSingBoxEnabled = singBoxEnabled && !xrayEnabled;
+ pureXrayEnabled = xrayEnabled && !singBoxEnabled;
activeBackend =
- if xrayEnabled then
+ if hybridEnabled then
+ "hybrid"
+ else if pureXrayEnabled then
"xray"
- else if singBoxEnabled then
+ else if pureSingBoxEnabled then
"sing-box"
else
null;
@@ -44,7 +49,7 @@ let
hasStaticOutbounds = proxyCfg.outbounds != [ ];
hasSubscriptions = proxyCfg.subscriptions != [ ];
collapseNamedOutbounds = selectionMode == "first";
- clashApiEnabled = singBoxEnabled && selectionMode != "first";
+ clashApiEnabled = (singBoxEnabled || hybridEnabled) && selectionMode != "first";
perAppZapretEnabled = perAppZapretCfg.enable;
userControlEnabled = userControlCfg.global.enable || userControlCfg.perApp.enable;
@@ -64,6 +69,9 @@ in
proxyEnabled
singBoxEnabled
xrayEnabled
+ hybridEnabled
+ pureSingBoxEnabled
+ pureXrayEnabled
activeBackend
perAppRoutingCfg
globalTun
diff --git a/modules/proxy-suite/options/sing-box.nix b/modules/proxy-suite/options/sing-box.nix
index 4cea891..76f053c 100644
--- a/modules/proxy-suite/options/sing-box.nix
+++ b/modules/proxy-suite/options/sing-box.nix
@@ -2,7 +2,12 @@
{ lib, pkgs, ... }:
let
- inherit (lib) literalExpression mkOption mkEnableOption types;
+ inherit (lib)
+ literalExpression
+ mkOption
+ mkEnableOption
+ types
+ ;
in
{
options.services.proxy-suite.proxy = {
@@ -11,8 +16,10 @@ in
default = false;
description = ''
Whether to configure and run the proxy backend services.
- This is disabled by default; enable it explicitly and choose exactly
- one backend with proxy.singBox.enable or proxy.xray.enable.
+ This is disabled by default; enable it explicitly and choose at least
+ one backend with proxy.singBox.enable or proxy.xray.enable. Enabling
+ both runs sing-box as the frontend and XRay as a sidecar for outbounds
+ that require XRay.
'';
};
diff --git a/modules/proxy-suite/options/types.nix b/modules/proxy-suite/options/types.nix
index dac31c1..354127a 100644
--- a/modules/proxy-suite/options/types.nix
+++ b/modules/proxy-suite/options/types.nix
@@ -159,6 +159,22 @@ let
example = "hy2://password@example.com:443?sni=example.com";
};
+ backend = mkOption {
+ type = types.enum [
+ "auto"
+ "sing-box"
+ "xray"
+ ];
+ default = "auto";
+ description = ''
+ Backend preference for this outbound when both SingBox and XRay are
+ enabled. "auto" uses SingBox when the URL or JSON can be represented
+ there and falls back to XRay for XRay-only transports such as XHTTP
+ or ECH. Ignored by single-backend configurations.
+ '';
+ example = "xray";
+ };
+
singBoxJson = mkOption {
type = types.nullOr types.attrs;
default = null;
diff --git a/modules/proxy-suite/rules.nix b/modules/proxy-suite/rules.nix
index 7adb83f..8ccdb0b 100644
--- a/modules/proxy-suite/rules.nix
+++ b/modules/proxy-suite/rules.nix
@@ -118,7 +118,11 @@ let
tag:
if derived.collapseNamedOutbounds && !builtins.elem tag derived.builtinTags then
"proxy"
- else if derived.xrayEnabled && derived.selectionMode == "urltest" && !builtins.elem tag derived.builtinTags then
+ else if
+ derived.pureXrayEnabled
+ && derived.selectionMode == "urltest"
+ && !builtins.elem tag derived.builtinTags
+ then
"proxy-suite-ob-${tag}"
else
tag;
@@ -190,12 +194,10 @@ let
{ action = "sniff"; }
];
- customRouteRules = map (
- rule: {
- category = customRuleCategory rule.outbound;
- entries = mkCustomRuleEntries rule;
- }
- ) customRules;
+ customRouteRules = map (rule: {
+ category = customRuleCategory rule.outbound;
+ entries = mkCustomRuleEntries rule;
+ }) customRules;
proxyPrimaryRules = lib.flatten [
(mkDomainRule "proxy" r.proxy.domains)
@@ -209,19 +211,21 @@ let
(mkRulesetRule "direct" (map (s: "geoip-${s}") direct.geoips))
];
- tgWsProxyRelayDirectRules = lib.optional (
- tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && tgWsProxyCfg.dcIps != { }
- ) {
- ip_cidr = lib.unique (builtins.attrValues tgWsProxyCfg.dcIps);
- outbound = "direct";
- };
+ tgWsProxyRelayDirectRules =
+ lib.optional
+ (tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && tgWsProxyCfg.dcIps != { })
+ {
+ ip_cidr = lib.unique (builtins.attrValues tgWsProxyCfg.dcIps);
+ outbound = "direct";
+ };
safetyDirectRules = [
{
ip_is_private = true;
outbound = "direct";
}
- ] ++ tgWsProxyRelayDirectRules;
+ ]
+ ++ tgWsProxyRelayDirectRules;
blockRules = lib.flatten [
(mkDomainRule "block" r.block.domains)
@@ -263,54 +267,68 @@ let
mkXrayRule =
ruleTag: fields: tag:
- ({
- type = "field";
- inherit ruleTag;
- }
- // fields
- // (xrayTarget tag));
+ (
+ {
+ type = "field";
+ inherit ruleTag;
+ }
+ // fields
+ // (xrayTarget tag)
+ );
xrayDomainRules =
ruleTag: tag: domains:
- lib.optional (domains != [ ]) (mkXrayRule ruleTag {
- domain = map (domain: "domain:${domain}") domains;
- } tag);
+ lib.optional (domains != [ ]) (
+ mkXrayRule ruleTag {
+ domain = map (domain: "domain:${domain}") domains;
+ } tag
+ );
xrayIPRules =
ruleTag: tag: ips:
- lib.optional (ips != [ ]) (mkXrayRule ruleTag {
- ip = ips;
- } tag);
+ lib.optional (ips != [ ]) (
+ mkXrayRule ruleTag {
+ ip = ips;
+ } tag
+ );
xrayGeositeRules =
ruleTag: tag: geosites:
- lib.optional (geosites != [ ]) (mkXrayRule ruleTag {
- domain = map (name: "geosite:${name}") geosites;
- } tag);
+ lib.optional (geosites != [ ]) (
+ mkXrayRule ruleTag {
+ domain = map (name: "geosite:${name}") geosites;
+ } tag
+ );
xrayGeoIPRules =
ruleTag: tag: geoips:
- lib.optional (geoips != [ ]) (mkXrayRule ruleTag {
- ip = map (name: "geoip:${name}") geoips;
- } tag);
+ lib.optional (geoips != [ ]) (
+ mkXrayRule ruleTag {
+ ip = map (name: "geoip:${name}") geoips;
+ } tag
+ );
xrayCustomRuleTag = category: kind: "custom-${category}-${kind}";
mkXrayCustomRuleEntries =
rule:
lib.flatten [
- (xrayDomainRules (xrayCustomRuleTag (customRuleCategory rule.outbound) "domain") rule.outbound rule.domains)
+ (xrayDomainRules (xrayCustomRuleTag (customRuleCategory rule.outbound) "domain") rule.outbound
+ rule.domains
+ )
(xrayIPRules (xrayCustomRuleTag (customRuleCategory rule.outbound) "ip") rule.outbound rule.ips)
- (xrayGeositeRules (xrayCustomRuleTag (customRuleCategory rule.outbound) "geosite") rule.outbound rule.geosites)
- (xrayGeoIPRules (xrayCustomRuleTag (customRuleCategory rule.outbound) "geoip") rule.outbound rule.geoips)
+ (xrayGeositeRules (xrayCustomRuleTag (customRuleCategory rule.outbound) "geosite") rule.outbound
+ rule.geosites
+ )
+ (xrayGeoIPRules (xrayCustomRuleTag (customRuleCategory rule.outbound) "geoip") rule.outbound
+ rule.geoips
+ )
];
- xrayCustomRouteRules = map (
- rule: {
- category = customRuleCategory rule.outbound;
- entries = mkXrayCustomRuleEntries rule;
- }
- ) customRules;
+ xrayCustomRouteRules = map (rule: {
+ category = customRuleCategory rule.outbound;
+ entries = mkXrayCustomRuleEntries rule;
+ }) customRules;
xrayProxyPrimaryRules = lib.flatten [
(xrayDomainRules "proxy-domain" "proxy" r.proxy.domains)
@@ -326,9 +344,13 @@ let
xraySafetyDirectRules = [
(mkXrayRule "direct-private" { ip = [ "geoip:private" ]; } "direct")
- ] ++ lib.optional (
- tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && tgWsProxyCfg.dcIps != { }
- ) (mkXrayRule "direct-tg-relay" { ip = lib.unique (builtins.attrValues tgWsProxyCfg.dcIps); } "direct");
+ ]
+ ++
+ lib.optional
+ (tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && tgWsProxyCfg.dcIps != { })
+ (
+ mkXrayRule "direct-tg-relay" { ip = lib.unique (builtins.attrValues tgWsProxyCfg.dcIps); } "direct"
+ );
xrayBlockRules = lib.flatten [
(xrayDomainRules "block-domain" "block" r.block.domains)
diff --git a/modules/proxy-suite/service-assertions.nix b/modules/proxy-suite/service-assertions.nix
index 5f6824e..452b3e4 100644
--- a/modules/proxy-suite/service-assertions.nix
+++ b/modules/proxy-suite/service-assertions.nix
@@ -32,6 +32,8 @@ let
proxyEnabled
singBoxEnabled
xrayEnabled
+ hybridEnabled
+ pureXrayEnabled
perAppRoutingCfg
globalTun
globalTproxy
@@ -49,9 +51,9 @@ let
(requireAvailable proxyCfg.xray.enable proxyEnabled
"proxy-suite: proxy.xray.enable requires proxy.enable = true"
)
- (mkAssertion (
- !proxyEnabled || (proxyCfg.singBox.enable != proxyCfg.xray.enable)
- ) "proxy-suite: exactly one of proxy.singBox.enable or proxy.xray.enable must be true when proxy.enable = true")
+ (mkAssertion (!proxyEnabled || proxyCfg.singBox.enable || proxyCfg.xray.enable)
+ "proxy-suite: at least one of proxy.singBox.enable or proxy.xray.enable must be true when proxy.enable = true"
+ )
(requireAvailable proxyEnabled (
proxyCfg.outbounds != [ ] || proxyCfg.subscriptions != [ ]
) "proxy-suite: at least one outbound or subscription is required when proxy.enable = true")
@@ -66,11 +68,12 @@ let
"proxy-suite: routing.rules reference unknown outbound tag(s): ${lib.concatStringsSep ", " invalidRoutingTargets}"
)
(mkAssertion (
- !(xrayEnabled && proxyCfg.selection == "selector")
+ !(pureXrayEnabled && proxyCfg.selection == "selector")
) "proxy-suite: proxy.selection = \"selector\" is only available with proxy.singBox.enable = true")
- (mkAssertion (
- !(xrayEnabled && (proxyCfg.dns.local.type == "tls" || proxyCfg.dns.remote.type == "tls"))
- ) "proxy-suite: proxy.dns.*.type = \"tls\" is not supported with proxy.xray.enable = true; use udp/tcp DNS for XRay")
+ (mkAssertion
+ (!(pureXrayEnabled && (proxyCfg.dns.local.type == "tls" || proxyCfg.dns.remote.type == "tls")))
+ "proxy-suite: proxy.dns.*.type = \"tls\" is not supported with proxy.xray.enable = true; use udp/tcp DNS for XRay"
+ )
(requireEnabled globalTun.enable proxyEnabled
"proxy-suite: proxy.tun.enable requires proxy.enable = true"
)
@@ -250,7 +253,8 @@ let
message = "proxy-suite: tgWsProxy.routingMark must differ from proxy.tun.perApp.fwmark";
}
{
- condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && perAppRoutingTproxy.enable;
+ condition =
+ tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && perAppRoutingTproxy.enable;
left = tgWsProxyCfg.routingMark;
right = perAppRoutingTproxy.fwmark;
message = "proxy-suite: tgWsProxy.routingMark must differ from proxy.tproxy.perApp.fwmark";
@@ -268,68 +272,70 @@ let
134217728
];
- positiveNumberAssertions = map (item: mkAssertion (!item.condition || item.value > 0) item.message) [
- {
- condition = globalTun.enable;
- value = globalTun.mtu;
- message = "proxy-suite: proxy.tun.mtu must be greater than zero";
- }
- {
- condition = perAppRoutingTun.enable;
- value = perAppRoutingTun.mtu;
- message = "proxy-suite: proxy.tun.perApp.mtu must be greater than zero";
- }
- {
- condition = globalTproxy.enable;
- value = globalTproxy.fwmark;
- message = "proxy-suite: proxy.tproxy.fwmark must be greater than zero";
- }
- {
- condition = globalTproxy.enable;
- value = globalTproxy.proxyMark;
- message = "proxy-suite: proxy.tproxy.proxyMark must be greater than zero";
- }
- {
- condition = globalTproxy.enable;
- value = globalTproxy.routeTable;
- message = "proxy-suite: proxy.tproxy.routeTable must be greater than zero";
- }
- {
- condition = perAppRoutingTun.enable;
- value = perAppRoutingTun.fwmark;
- message = "proxy-suite: proxy.tun.perApp.fwmark must be greater than zero";
- }
- {
- condition = perAppRoutingTun.enable;
- value = perAppRoutingTun.routeTable;
- message = "proxy-suite: proxy.tun.perApp.routeTable must be greater than zero";
- }
- {
- condition = perAppRoutingTproxy.enable;
- value = perAppRoutingTproxy.fwmark;
- message = "proxy-suite: proxy.tproxy.perApp.fwmark must be greater than zero";
- }
- {
- condition = perAppRoutingTproxy.enable;
- value = perAppRoutingTproxy.routeTable;
- message = "proxy-suite: proxy.tproxy.perApp.routeTable must be greater than zero";
- }
- {
- condition = perAppZapretCfg.enable;
- value = perAppZapretCfg.filterMark;
- message = "proxy-suite: zapret.perApp.filterMark must be greater than zero";
- }
- {
- condition = perAppZapretCfg.enable;
- value = perAppZapretCfg.qnum;
- message = "proxy-suite: zapret.perApp.qnum must be greater than zero";
- }
- {
- condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy;
- value = tgWsProxyCfg.routingMark;
- message = "proxy-suite: tgWsProxy.routingMark must be greater than zero";
- }
- ];
+ positiveNumberAssertions =
+ map (item: mkAssertion (!item.condition || item.value > 0) item.message)
+ [
+ {
+ condition = globalTun.enable;
+ value = globalTun.mtu;
+ message = "proxy-suite: proxy.tun.mtu must be greater than zero";
+ }
+ {
+ condition = perAppRoutingTun.enable;
+ value = perAppRoutingTun.mtu;
+ message = "proxy-suite: proxy.tun.perApp.mtu must be greater than zero";
+ }
+ {
+ condition = globalTproxy.enable;
+ value = globalTproxy.fwmark;
+ message = "proxy-suite: proxy.tproxy.fwmark must be greater than zero";
+ }
+ {
+ condition = globalTproxy.enable;
+ value = globalTproxy.proxyMark;
+ message = "proxy-suite: proxy.tproxy.proxyMark must be greater than zero";
+ }
+ {
+ condition = globalTproxy.enable;
+ value = globalTproxy.routeTable;
+ message = "proxy-suite: proxy.tproxy.routeTable must be greater than zero";
+ }
+ {
+ condition = perAppRoutingTun.enable;
+ value = perAppRoutingTun.fwmark;
+ message = "proxy-suite: proxy.tun.perApp.fwmark must be greater than zero";
+ }
+ {
+ condition = perAppRoutingTun.enable;
+ value = perAppRoutingTun.routeTable;
+ message = "proxy-suite: proxy.tun.perApp.routeTable must be greater than zero";
+ }
+ {
+ condition = perAppRoutingTproxy.enable;
+ value = perAppRoutingTproxy.fwmark;
+ message = "proxy-suite: proxy.tproxy.perApp.fwmark must be greater than zero";
+ }
+ {
+ condition = perAppRoutingTproxy.enable;
+ value = perAppRoutingTproxy.routeTable;
+ message = "proxy-suite: proxy.tproxy.perApp.routeTable must be greater than zero";
+ }
+ {
+ condition = perAppZapretCfg.enable;
+ value = perAppZapretCfg.filterMark;
+ message = "proxy-suite: zapret.perApp.filterMark must be greater than zero";
+ }
+ {
+ condition = perAppZapretCfg.enable;
+ value = perAppZapretCfg.qnum;
+ message = "proxy-suite: zapret.perApp.qnum must be greater than zero";
+ }
+ {
+ condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy;
+ value = tgWsProxyCfg.routingMark;
+ message = "proxy-suite: tgWsProxy.routingMark must be greater than zero";
+ }
+ ];
localProxyAuthCfg = proxyCfg.auth;
localProxyAuthUsed =
@@ -404,19 +410,28 @@ let
];
outboundAssertions = lib.concatMap (ob: [
- (exactlyOneOf proxyEnabled [
- ob.urlFile
- ob.url
- ob.singBoxJson
- ob.xrayJson
- ob.json
- ] "proxy-suite: outbound '${ob.tag}': set exactly one of urlFile, url, singBoxJson, xrayJson, or json")
- (mkAssertion (!singBoxEnabled || ob.xrayJson == null)
- "proxy-suite: outbound '${ob.tag}': xrayJson is only available with proxy.xray.enable = true"
+ (exactlyOneOf proxyEnabled
+ [
+ ob.urlFile
+ ob.url
+ ob.singBoxJson
+ ob.xrayJson
+ ob.json
+ ]
+ "proxy-suite: outbound '${ob.tag}': set exactly one of urlFile, url, singBoxJson, xrayJson, or json"
)
- (mkAssertion (!xrayEnabled || (ob.singBoxJson == null && ob.json == null))
+ (mkAssertion (
+ !singBoxEnabled || hybridEnabled || ob.xrayJson == null
+ ) "proxy-suite: outbound '${ob.tag}': xrayJson is only available with proxy.xray.enable = true")
+ (mkAssertion (!xrayEnabled || hybridEnabled || (ob.singBoxJson == null && ob.json == null))
"proxy-suite: outbound '${ob.tag}': singBoxJson/json are only available with proxy.singBox.enable = true"
)
+ (mkAssertion (
+ !(ob.backend == "xray") || xrayEnabled
+ ) "proxy-suite: outbound '${ob.tag}': backend = \"xray\" requires proxy.xray.enable = true")
+ (mkAssertion (
+ !(ob.backend == "sing-box") || singBoxEnabled
+ ) "proxy-suite: outbound '${ob.tag}': backend = \"sing-box\" requires proxy.singBox.enable = true")
]) proxyCfg.outbounds;
subscriptionAssertions = lib.concatMap (sub: [
diff --git a/modules/proxy-suite/service/context.nix b/modules/proxy-suite/service/context.nix
index cd9f0ec..cce0b04 100644
--- a/modules/proxy-suite/service/context.nix
+++ b/modules/proxy-suite/service/context.nix
@@ -24,6 +24,8 @@ let
proxyEnabled
singBoxEnabled
xrayEnabled
+ hybridEnabled
+ pureXrayEnabled
activeBackend
perAppRoutingCfg
globalTun
@@ -71,6 +73,8 @@ let
proxyEnabled
singBoxEnabled
xrayEnabled
+ hybridEnabled
+ pureXrayEnabled
activeBackend
perAppRoutingCfg
userControlCfg
@@ -88,7 +92,12 @@ let
buildOutboundPy
fetchSubscriptionPy
;
- inherit tproxyFile tunFile perAppTunFile routeModeRulesFile;
+ inherit
+ tproxyFile
+ tunFile
+ perAppTunFile
+ routeModeRulesFile
+ ;
};
perAppRouting = import ./per-app-routing.nix {
@@ -144,6 +153,8 @@ in
proxyEnabled
singBoxEnabled
xrayEnabled
+ hybridEnabled
+ pureXrayEnabled
activeBackend
perAppRoutingCfg
globalTun
diff --git a/modules/proxy-suite/service/default.nix b/modules/proxy-suite/service/default.nix
index b46f1f9..b316425 100644
--- a/modules/proxy-suite/service/default.nix
+++ b/modules/proxy-suite/service/default.nix
@@ -58,6 +58,8 @@ let
proxyCfg
proxyEnabled
xrayEnabled
+ hybridEnabled
+ pureXrayEnabled
activeBackend
perAppRoutingCfg
globalTun
@@ -236,7 +238,14 @@ let
enable = proxyEnabled;
name = serviceNames.socks;
value = mkRestartingService {
- description = "${if xrayEnabled then "XRay" else "sing-box"} proxy client (SOCKS + TProxy-ready)";
+ description = "${
+ if pureXrayEnabled then
+ "XRay"
+ else if hybridEnabled then
+ "sing-box + XRay sidecar"
+ else
+ "sing-box"
+ } proxy client (SOCKS + TProxy-ready)";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
@@ -268,14 +277,21 @@ let
enable = proxyEnabled && globalTun.enable;
name = serviceNames.tun;
value = mkRestartingService {
- description = "${if xrayEnabled then "XRay" else "sing-box"} TUN proxy client";
+ description = "${
+ if pureXrayEnabled then
+ "XRay"
+ else if hybridEnabled then
+ "sing-box + XRay sidecar"
+ else
+ "sing-box"
+ } TUN proxy client";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = lib.optionals globalTun.autostart [ "multi-user.target" ];
conflicts = [ "${serviceNames.tproxy}.service" ];
execStartPre = tunCleanupScript;
execStart = scripts.startTun;
- execStartPost = if xrayEnabled then xrayTunUpScript else null;
+ execStartPost = if pureXrayEnabled then xrayTunUpScript else null;
execStopPost = tunCleanupScript;
runtimeDirectory = serviceNames.tun;
stateDirectory = "proxy-suite";
diff --git a/modules/proxy-suite/service/scripts.nix b/modules/proxy-suite/service/scripts.nix
index 3c28ad9..89d8ca9 100644
--- a/modules/proxy-suite/service/scripts.nix
+++ b/modules/proxy-suite/service/scripts.nix
@@ -7,6 +7,8 @@
proxyEnabled,
singBoxEnabled,
xrayEnabled,
+ hybridEnabled,
+ pureXrayEnabled,
activeBackend,
perAppRoutingCfg,
userControlCfg,
@@ -31,8 +33,9 @@ let
globalTproxy = proxyCfg.tproxy;
systemctl = "${pkgs.systemd}/bin/systemctl";
backend = if activeBackend == null then "sing-box" else activeBackend;
- backendArg = "--backend ${backend}";
- backendBin = if xrayEnabled then xray else singBox;
+ mainBackend = if pureXrayEnabled then "xray" else "sing-box";
+ backendArg = "--backend ${mainBackend}";
+ backendBin = if pureXrayEnabled then xray else singBox;
localProxyAuth = proxyCfg.auth;
localProxyAuthEnabled =
localProxyAuth.username != null
@@ -48,6 +51,7 @@ let
routeModeStateFile = "/run/proxy-suite/route-mode";
xrayLoglevelFile = "/run/proxy-suite/xray-loglevel";
runtimeProxychainsConfig = "/run/proxy-suite-socks/proxychains.conf";
+ xraySidecarRoutingMark = globalTproxy.proxyMark;
mkSubscriptionCacheFile = sub: "${subscriptionCacheDir}/${sub.tag}.json";
@@ -97,7 +101,7 @@ let
routingMark:
if routingMark == null then
""
- else if xrayEnabled then
+ else if pureXrayEnabled then
" | .streamSettings.sockopt.mark = ${toString routingMark}"
else
" | .routing_mark = ${toString routingMark}";
@@ -106,7 +110,7 @@ let
ob: tag: routingMark:
let
backendRaw =
- if xrayEnabled then
+ if pureXrayEnabled then
ob.xrayJson
else if ob.singBoxJson != null then
ob.singBoxJson
@@ -115,22 +119,21 @@ let
markAttrs =
if routingMark == null then
{ }
- else if xrayEnabled then
+ else if pureXrayEnabled then
{ streamSettings.sockopt.mark = routingMark; }
else
{ routing_mark = routingMark; };
- taggedRaw = backendRaw // { inherit tag; };
+ taggedRaw = backendRaw // {
+ inherit tag;
+ };
in
- if xrayEnabled then
- lib.recursiveUpdate taggedRaw markAttrs
- else
- taggedRaw // markAttrs;
+ if pureXrayEnabled then lib.recursiveUpdate taggedRaw markAttrs else taggedRaw // markAttrs;
mkOutboundBlock =
ob: routingMark: tag:
let
backendRaw =
- if xrayEnabled then
+ if pureXrayEnabled then
ob.xrayJson
else if ob.singBoxJson != null then
ob.singBoxJson
@@ -150,18 +153,103 @@ let
else
let
urlSource =
- if ob.urlFile != null then
- ob.urlFile
- else
- pkgs.writeText "proxy-suite-url-${ob.tag}" ob.url;
+ if ob.urlFile != null then ob.urlFile else pkgs.writeText "proxy-suite-url-${ob.tag}" ob.url;
in
''
# outbound: ${tag}
URL=$(cat "${urlSource}")
- OB_JSON=$(printf '%s' "$URL" | PYTHONPATH="${parserScriptsPythonPath}" ${python3} ${buildOutboundPy} ${backendArg} --tag ${lib.escapeShellArg tag}${lib.optionalString (routingMark != null) " --routing-mark ${toString routingMark}"})
+ OB_JSON=$(printf '%s' "$URL" | PYTHONPATH="${parserScriptsPythonPath}" ${python3} ${buildOutboundPy} ${backendArg} --tag ${lib.escapeShellArg tag}${
+ lib.optionalString (routingMark != null) " --routing-mark ${toString routingMark}"
+ })
OUTBOUNDS_JSON=$(${jq} --argjson ob "$OB_JSON" '. + [$ob]' <<< "$OUTBOUNDS_JSON")
'';
+ 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";
+ };
+ };
+
+ mkHybridOutboundBlock =
+ ob: routingMark: tag:
+ if ob.xrayJson != null then
+ let
+ outboundJson = builtins.toJSON (xrayRawOutboundJson ob tag);
+ jsonFile = pkgs.writeText "proxy-suite-xray-sidecar-ob-${tag}.json" outboundJson;
+ in
+ ''
+ # outbound: ${tag} (hybrid XRay json sidecar)
+ OB_JSON=$(cat "${jsonFile}")
+ _proxy_suite_add_xray_sidecar_ob "$OB_JSON" ${lib.escapeShellArg tag}
+ ''
+ else if ob.singBoxJson != null || ob.json != null then
+ let
+ outboundJson = builtins.toJSON (singBoxRawOutboundJson ob tag routingMark);
+ jsonFile = pkgs.writeText "proxy-suite-sing-box-ob-${tag}.json" outboundJson;
+ in
+ ''
+ # outbound: ${tag} (hybrid SingBox json)
+ OB_JSON=$(cat "${jsonFile}")
+ _proxy_suite_add_sing_box_ob "$OB_JSON"
+ ''
+ else
+ let
+ urlSource =
+ if ob.urlFile != null then ob.urlFile else pkgs.writeText "proxy-suite-url-${ob.tag}" ob.url;
+ singBoxCommand = ''
+ printf '%s' "$URL" | PYTHONPATH="${parserScriptsPythonPath}" ${python3} ${buildOutboundPy} --backend sing-box --tag ${lib.escapeShellArg tag}${
+ lib.optionalString (routingMark != null) " --routing-mark ${toString routingMark}"
+ }
+ '';
+ xrayCommand = ''
+ printf '%s' "$URL" | PYTHONPATH="${parserScriptsPythonPath}" ${python3} ${buildOutboundPy} --backend xray --tag ${lib.escapeShellArg tag} --routing-mark ${toString xraySidecarRoutingMark}
+ '';
+ in
+ if ob.backend == "xray" then
+ ''
+ # outbound: ${tag} (hybrid forced XRay sidecar)
+ URL=$(cat "${urlSource}")
+ OB_JSON=$(${xrayCommand})
+ _proxy_suite_add_xray_sidecar_ob "$OB_JSON" ${lib.escapeShellArg tag}
+ ''
+ else if ob.backend == "sing-box" then
+ ''
+ # outbound: ${tag} (hybrid forced SingBox)
+ URL=$(cat "${urlSource}")
+ OB_JSON=$(${singBoxCommand})
+ _proxy_suite_add_sing_box_ob "$OB_JSON"
+ ''
+ else
+ ''
+ # outbound: ${tag} (hybrid auto)
+ URL=$(cat "${urlSource}")
+ if OB_JSON=$(${singBoxCommand} 2>"$RUNTIME_DIR/sing-box-parser.err"); then
+ _proxy_suite_add_sing_box_ob "$OB_JSON"
+ else
+ SING_BOX_PARSE_ERROR="$(cat "$RUNTIME_DIR/sing-box-parser.err" 2>/dev/null || true)"
+ if OB_JSON=$(${xrayCommand}); then
+ _proxy_suite_add_xray_sidecar_ob "$OB_JSON" ${lib.escapeShellArg tag}
+ else
+ echo "proxy-suite: outbound '${tag}' cannot be parsed by SingBox or XRay" >&2
+ if [ -n "$SING_BOX_PARSE_ERROR" ]; then
+ printf '%s\n' "$SING_BOX_PARSE_ERROR" >&2
+ fi
+ exit 1
+ fi
+ fi
+ '';
+
mkSubscriptionBlock =
sub: routingMark:
let
@@ -184,9 +272,11 @@ let
fi
if [ -f "$CACHE_FILE" ]; then
SUB_JSON=$(cat "$CACHE_FILE")
- ${lib.optionalString (routingMark != null) ''
- SUB_JSON=$(${jq} 'map(.${markFilter})' <<< "$SUB_JSON")
- ''}OUTBOUNDS_JSON=$(${jq} --argjson sub "$SUB_JSON" '. + $sub' <<< "$OUTBOUNDS_JSON")
+ ${
+ lib.optionalString (routingMark != null) ''
+ SUB_JSON=$(${jq} 'map(.${markFilter})' <<< "$SUB_JSON")
+ ''
+ }OUTBOUNDS_JSON=$(${jq} --argjson sub "$SUB_JSON" '. + $sub' <<< "$OUTBOUNDS_JSON")
fi
'';
@@ -197,14 +287,124 @@ let
fi
'';
+ hybridRuntimeHelpersBlock =
+ routingMark: xraySidecarBasePort: xrayDnsBridgePort:
+ lib.optionalString hybridEnabled ''
+ XRAY_OUTBOUNDS_JSON='[]'
+ XRAY_INBOUNDS_JSON='[]'
+ XRAY_ROUTE_RULES_JSON='[]'
+ XRAY_SIDECAR_NEXT_PORT=${toString xraySidecarBasePort}
+ XRAY_SIDECAR_DNS_PORT=${toString xrayDnsBridgePort}
+
+ _proxy_suite_add_sing_box_ob() {
+ local ob="$1"
+ 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"
+ }
+
+ _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:false,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_write_xray_sidecar_config() {
+ if [ "$(${jq} 'length' <<< "$XRAY_OUTBOUNDS_JSON")" -eq 0 ]; then
+ return 0
+ fi
+ ${jq} -n \
+ --arg loglevel "$XRAY_LOGLEVEL" \
+ --arg bind_interface "$XRAY_TUN_BIND_INTERFACE" \
+ --argjson dns_port "$XRAY_SIDECAR_DNS_PORT" \
+ --argjson inbounds "$XRAY_INBOUNDS_JSON" \
+ --argjson outbounds "$XRAY_OUTBOUNDS_JSON" \
+ --argjson route_rules "$XRAY_ROUTE_RULES_JSON" \
+ '
+ def bind_xray_sidecar($interface):
+ if $interface == "" then
+ .
+ else
+ .streamSettings = (.streamSettings // {})
+ | .streamSettings.sockopt = (.streamSettings.sockopt // {})
+ | if (.streamSettings.sockopt.interface? // "") == "" then
+ .streamSettings.sockopt.interface = $interface
+ else
+ .
+ end
+ end;
+ {
+ log: {
+ loglevel: (if $loglevel == "" then "warning" else $loglevel end),
+ access: "none"
+ },
+ dns: {
+ servers: [
+ {
+ address: "127.0.0.1",
+ port: $dns_port,
+ queryStrategy: "UseIP",
+ skipFallBack: true
+ }
+ ]
+ },
+ inbounds: $inbounds,
+ outbounds: (($outbounds | map(bind_xray_sidecar($bind_interface))) + [{protocol:"freedom",tag:"direct"}]),
+ routing: {
+ domainStrategy: "AsIs",
+ rules: ($route_rules + [{type:"field",ip:["127.0.0.1"],port:$dns_port,outboundTag:"direct"}])
+ }
+ }' > "$RUNTIME_DIR/xray-sidecar.json"
+ }
+ '';
+
mkOutboundScript =
routingMark:
let
outboundBlocks =
if collapseNamedOutbounds && proxyCfg.outbounds != [ ] then
- mkOutboundBlock (builtins.head proxyCfg.outbounds) routingMark "proxy"
+ (if hybridEnabled then mkHybridOutboundBlock else mkOutboundBlock)
+ (builtins.head proxyCfg.outbounds)
+ routingMark
+ "proxy"
else
- lib.concatMapStrings (ob: mkOutboundBlock ob routingMark ob.tag) proxyCfg.outbounds;
+ lib.concatMapStrings (
+ ob: (if hybridEnabled then mkHybridOutboundBlock else mkOutboundBlock) ob routingMark ob.tag
+ ) proxyCfg.outbounds;
subscriptionBlocks = lib.concatMapStrings (
sub: mkSubscriptionBlock sub routingMark
@@ -218,7 +418,7 @@ let
'';
wrapperBlock =
- if xrayEnabled && selectionMode == "urltest" then
+ if pureXrayEnabled && selectionMode == "urltest" then
xrayUrltestTagFilter
else if collapseNamedOutbounds then
lib.optionalString (proxyCfg.outbounds == [ ] && proxyCfg.subscriptions != [ ]) ''
@@ -270,18 +470,21 @@ let
chmod 640 "${runtimeProxychainsConfig}"
'';
- restartActiveConfigConsumersBlock = lib.concatMapStrings (svc: ''
- if ${systemctl} is-active --quiet ${svc}; then
- ${systemctl} restart ${svc}
- fi
- '') [
- "proxy-suite-socks"
- "proxy-suite-tun"
- "proxy-suite-per-app-tun"
- ];
+ restartActiveConfigConsumersBlock =
+ lib.concatMapStrings
+ (svc: ''
+ if ${systemctl} is-active --quiet ${svc}; then
+ ${systemctl} restart ${svc}
+ fi
+ '')
+ [
+ "proxy-suite-socks"
+ "proxy-suite-tun"
+ "proxy-suite-per-app-tun"
+ ];
routeModeBlacklistTail =
- if xrayEnabled then
+ if pureXrayEnabled then
''
+ .proxyGeo
+ .block
@@ -355,7 +558,7 @@ let
'';
mkBackendJqFilter =
- if xrayEnabled then
+ if pureXrayEnabled then
''
def xray_bind_outbound($interface):
if $interface == "" or .protocol == "blackhole" or .protocol == "dns" then
@@ -455,6 +658,8 @@ let
enableLocalProxyAuth ? false,
xrayTunEgressBinding ? false,
xrayTunDnsRuntime ? false,
+ xraySidecarBasePort ? 33080,
+ xrayDnsBridgePort ? 18533,
}:
pkgs.writeShellScript name ''
set -euo pipefail
@@ -472,6 +677,7 @@ let
ROUTE_RULES_JSON='[]'
ROUTE_MODE_ACTIVE=false
CLEAR_DNS_RULES=false
+ ${hybridRuntimeHelpersBlock routingMark xraySidecarBasePort xrayDnsBridgePort}
${subscriptionCacheHelpersBlock}
${lib.optionalString enableLocalProxyAuth ''
umask 077
@@ -503,6 +709,7 @@ let
${routeModeCaseBlock}
${mkOutboundScript routingMark}
+ ${lib.optionalString hybridEnabled "_proxy_suite_write_xray_sidecar_config"}
${jq} \
--argjson obs "$OUTBOUNDS_JSON" \
@@ -526,7 +733,43 @@ let
chmod 600 "$RUNTIME_DIR/config.json"
''}
- exec ${backendBin} run -c "$RUNTIME_DIR/config.json"
+ ${
+ if hybridEnabled then
+ ''
+ if [ -s "$RUNTIME_DIR/xray-sidecar.json" ]; then
+ XRAY_SIDECAR_PID=""
+ _proxy_suite_cleanup_xray_sidecar() {
+ if [ -n "$XRAY_SIDECAR_PID" ]; then
+ kill "$XRAY_SIDECAR_PID" 2>/dev/null || true
+ wait "$XRAY_SIDECAR_PID" 2>/dev/null || true
+ fi
+ }
+ trap _proxy_suite_cleanup_xray_sidecar EXIT
+ trap 'exit 143' INT TERM
+
+ ${xray} run -c "$RUNTIME_DIR/xray-sidecar.json" &
+ XRAY_SIDECAR_PID="$!"
+ ${pkgs.coreutils}/bin/sleep 0.2
+ if ! kill -0 "$XRAY_SIDECAR_PID" 2>/dev/null; then
+ XRAY_SIDECAR_STATUS=1
+ wait "$XRAY_SIDECAR_PID" || XRAY_SIDECAR_STATUS="$?"
+ exit "$XRAY_SIDECAR_STATUS"
+ fi
+
+ ${singBox} run -c "$RUNTIME_DIR/config.json" &
+ SING_BOX_PID="$!"
+ SING_BOX_STATUS=0
+ wait "$SING_BOX_PID" || SING_BOX_STATUS="$?"
+ exit "$SING_BOX_STATUS"
+ fi
+
+ exec ${singBox} run -c "$RUNTIME_DIR/config.json"
+ ''
+ else
+ ''
+ exec ${backendBin} run -c "$RUNTIME_DIR/config.json"
+ ''
+ }
'';
startSocks = mkStartScript {
@@ -535,15 +778,19 @@ let
configFile = tproxyFile;
routingMark = globalTproxy.proxyMark;
enableLocalProxyAuth = localProxyAuthEnabled;
+ xraySidecarBasePort = 33080;
+ xrayDnsBridgePort = 18533;
};
startTun = mkStartScript {
name = "proxy-suite-start-tun";
runtimeDir = "/run/proxy-suite-tun";
configFile = tunFile;
- routingMark = if xrayEnabled then globalTproxy.proxyMark else null;
+ routingMark = if pureXrayEnabled then globalTproxy.proxyMark else null;
xrayTunEgressBinding = xrayEnabled;
- xrayTunDnsRuntime = xrayEnabled;
+ xrayTunDnsRuntime = pureXrayEnabled;
+ xraySidecarBasePort = 33180;
+ xrayDnsBridgePort = 18534;
};
startPerAppTun = mkStartScript {
@@ -552,7 +799,9 @@ let
configFile = perAppTunFile;
routingMark = if xrayEnabled || globalTproxy.enable then globalTproxy.proxyMark else null;
xrayTunEgressBinding = xrayEnabled;
- xrayTunDnsRuntime = xrayEnabled;
+ xrayTunDnsRuntime = pureXrayEnabled;
+ xraySidecarBasePort = 33280;
+ xrayDnsBridgePort = 18535;
};
mkSubscriptionFetchBlock =
diff --git a/nix/checks.nix b/nix/checks.nix
index b4b3318..c411e00 100644
--- a/nix/checks.nix
+++ b/nix/checks.nix
@@ -108,8 +108,7 @@ let
dnsRules: ruleSet:
builtins.any (rule: (rule ? rule_set) && builtins.elem ruleSet rule.rule_set) dnsRules;
dnsServerByTag =
- dnsConfig: tag:
- builtins.head (builtins.filter (server: server.tag == tag) dnsConfig.dns.servers);
+ dnsConfig: tag: builtins.head (builtins.filter (server: server.tag == tag) dnsConfig.dns.servers);
mkZapretBaseFor =
fixture: serviceName:
let
@@ -157,8 +156,7 @@ let
in
pkgs.lib.concatStringsSep "\n" (map builtins.readFile execs);
quotedValueByPrefix =
- text: prefix:
- pkgs.lib.removeSuffix "\"" (pkgs.lib.removePrefix prefix (lineByPrefix text prefix));
+ text: prefix: pkgs.lib.removeSuffix "\"" (pkgs.lib.removePrefix prefix (lineByPrefix text prefix));
shellValueByPrefix =
text: prefix:
let
@@ -187,20 +185,24 @@ let
};
};
};
- mkFixture = proxySuiteConfig: evalProxySuite [
- {
- system.stateVersion = "26.05";
- services.proxy-suite = proxySuiteConfig;
- }
- ];
+ mkFixture =
+ proxySuiteConfig:
+ evalProxySuite [
+ {
+ system.stateVersion = "26.05";
+ services.proxy-suite = proxySuiteConfig;
+ }
+ ];
# Fixture that must fail validation; uses baseModule as the base.
- mkBadFixture = modules:
+ mkBadFixture =
+ modules:
forceEval ((evalProxySuite ([ baseModule ] ++ modules)).config.system.build.toplevel.drvPath);
# Same but without baseModule (for fixtures that need custom base config).
- mkBadFixtureRaw = modules:
- forceEval ((evalProxySuite modules).config.system.build.toplevel.drvPath);
+ mkBadFixtureRaw =
+ modules: forceEval ((evalProxySuite modules).config.system.build.toplevel.drvPath);
# Extract the proxy-ctl package and derived script/profile values from a fixture.
- mkProxyCtlDerived = fixture:
+ mkProxyCtlDerived =
+ fixture:
let
proxyCtl = packageByPattern fixture.config.environment.systemPackages ".*/[^/]*proxy-ctl(-[0-9.]+)?$";
wrapper = builtins.readFile "${proxyCtl}/bin/proxy-ctl";
@@ -208,7 +210,9 @@ let
{
inherit proxyCtl wrapper;
script = wrapper + "\n" + builtins.readFile "${proxyCtl}/bin/.proxy-ctl-wrapped";
- profiles = builtins.fromJSON (builtins.readFile (shellValueByPrefix wrapper "export PER_APP_ROUTING_PROFILES_FILE="));
+ profiles = builtins.fromJSON (
+ builtins.readFile (shellValueByPrefix wrapper "export PER_APP_ROUTING_PROFILES_FILE=")
+ );
};
minimal = evalProxySuite [ baseModule ];
@@ -294,58 +298,63 @@ let
xrayBackendJqFilter = builtins.readFile xrayTunBackendJqFilterFile;
xrayDnsLocalClient = xrayFixture.config.services.proxy-suite.proxy.dns.local.address;
xrayDnsRemoteClient = xrayFixture.config.services.proxy-suite.proxy.dns.remote.address;
- xrayTunConfigJson = pkgs.writeText "proxy-suite-xray-tun-check.json" (builtins.toJSON xrayTunConfig);
- xrayPerAppTunConfigJson =
- pkgs.writeText "proxy-suite-xray-per-app-tun-check.json" (builtins.toJSON xrayPerAppTunConfig);
- xrayJqFilterRuntimeCheck = pkgs.runCommand "proxy-suite-xray-jq-filter-runtime-check" { nativeBuildInputs = [ pkgs.jq ]; } ''
- OBS='[{"protocol":"freedom","tag":"proxy-suite-ob-primary"}]'
+ xrayTunConfigJson = pkgs.writeText "proxy-suite-xray-tun-check.json" (
+ builtins.toJSON xrayTunConfig
+ );
+ xrayPerAppTunConfigJson = pkgs.writeText "proxy-suite-xray-per-app-tun-check.json" (
+ builtins.toJSON xrayPerAppTunConfig
+ );
+ xrayJqFilterRuntimeCheck =
+ pkgs.runCommand "proxy-suite-xray-jq-filter-runtime-check" { nativeBuildInputs = [ pkgs.jq ]; }
+ ''
+ OBS='[{"protocol":"freedom","tag":"proxy-suite-ob-primary"}]'
- check_runtime() {
- local name="$1"
- local input="$2"
- local output="$TMPDIR/$name.json"
+ check_runtime() {
+ local name="$1"
+ local input="$2"
+ local output="$TMPDIR/$name.json"
- jq \
- --argjson obs "$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_bind_interface "eth0" \
- --arg xray_single_proxy_tag "proxy-suite-ob-primary" \
- --argjson xray_tun_dns_runtime true \
- --arg xray_dns_local_client ${pkgs.lib.escapeShellArg xrayDnsLocalClient} \
- --arg xray_dns_remote_client ${pkgs.lib.escapeShellArg xrayDnsRemoteClient} \
- -f ${pkgs.lib.escapeShellArg xrayTunBackendJqFilterFile} \
- "$input" > "$output"
+ jq \
+ --argjson obs "$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_bind_interface "eth0" \
+ --arg xray_single_proxy_tag "proxy-suite-ob-primary" \
+ --argjson xray_tun_dns_runtime true \
+ --arg xray_dns_local_client ${pkgs.lib.escapeShellArg xrayDnsLocalClient} \
+ --arg xray_dns_remote_client ${pkgs.lib.escapeShellArg xrayDnsRemoteClient} \
+ -f ${pkgs.lib.escapeShellArg xrayTunBackendJqFilterFile} \
+ "$input" > "$output"
- jq -e \
- --arg remote ${pkgs.lib.escapeShellArg xrayDnsRemoteClient} \
- --arg local ${pkgs.lib.escapeShellArg xrayDnsLocalClient} \
- '
- 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 ([.outbounds[] | select(.tag == "proxy-suite-ob-primary" and (.streamSettings.sockopt.interface? // "") == "eth0")] | length) == 1
- and ([.outbounds[] | select(.tag == "dns-out" and ((.streamSettings.sockopt.interface? // "") == ""))] | length) == 1
- and ([.inbounds[] | select(.tag == "tun-in") | .settings.dns] | length) == 1
- and ([.inbounds[] | select(.tag == "tun-in") | .settings.dns][0] == [$remote, $local])
- and ((.routing | has("balancers")) | not)
- and ((has("observatory")) | not)
- ' "$output" >/dev/null
- }
+ jq -e \
+ --arg remote ${pkgs.lib.escapeShellArg xrayDnsRemoteClient} \
+ --arg local ${pkgs.lib.escapeShellArg xrayDnsLocalClient} \
+ '
+ 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 ([.outbounds[] | select(.tag == "proxy-suite-ob-primary" and (.streamSettings.sockopt.interface? // "") == "eth0")] | length) == 1
+ and ([.outbounds[] | select(.tag == "dns-out" and ((.streamSettings.sockopt.interface? // "") == ""))] | length) == 1
+ and ([.inbounds[] | select(.tag == "tun-in") | .settings.dns] | length) == 1
+ and ([.inbounds[] | select(.tag == "tun-in") | .settings.dns][0] == [$remote, $local])
+ and ((.routing | has("balancers")) | not)
+ and ((has("observatory")) | not)
+ ' "$output" >/dev/null
+ }
- check_runtime global ${pkgs.lib.escapeShellArg xrayTunConfigJson}
- check_runtime per-app ${pkgs.lib.escapeShellArg xrayPerAppTunConfigJson}
- touch "$out"
- '';
+ check_runtime global ${pkgs.lib.escapeShellArg xrayTunConfigJson}
+ check_runtime per-app ${pkgs.lib.escapeShellArg xrayPerAppTunConfigJson}
+ touch "$out"
+ '';
xraySubscriptionFixture = evalProxySuite [
{
system.stateVersion = "26.05";
@@ -354,7 +363,12 @@ let
proxy = {
enable = true;
xray.enable = true;
- subscriptions = [ { tag = "xray-sub"; url = "https://example.com/xray-sub"; } ];
+ subscriptions = [
+ {
+ tag = "xray-sub";
+ url = "https://example.com/xray-sub";
+ }
+ ];
};
};
}
@@ -412,7 +426,12 @@ let
address = "9.9.9.9";
port = 5353;
};
- outbounds = [ { tag = "primary"; url = "http://proxy.example.com:8080"; } ];
+ outbounds = [
+ {
+ tag = "primary";
+ url = "http://proxy.example.com:8080";
+ }
+ ];
};
};
}
@@ -431,12 +450,54 @@ let
address = "1.1.1.1";
port = 853;
};
- outbounds = [ { tag = "primary"; url = "http://proxy.example.com:8080"; } ];
+ outbounds = [
+ {
+ tag = "primary";
+ url = "http://proxy.example.com:8080";
+ }
+ ];
};
};
}
];
- xrayBothBackends = mkBadFixtureRaw [
+ hybridModule = {
+ system.stateVersion = "26.05";
+ services.proxy-suite = {
+ enable = true;
+ proxy = {
+ enable = true;
+ singBox.enable = true;
+ xray.enable = true;
+ selection = "selector";
+ outbounds = [
+ {
+ tag = "primary";
+ url = "vless://uuid@example.com:443?type=tcp&security=reality&pbk=pubkey&fp=qq&sni=last.fm&sid=8a54&spx=%2F-%2Fen%2Fgp%2Fbestsellers&flow=xtls-rprx-vision&encryption=none";
+ }
+ {
+ tag = "xray-only";
+ url = "vless://uuid@example.com:443?type=xhttp&security=tls&sni=cdn.example.com&host=cdn.example.com&path=%2Fx";
+ }
+ ];
+ tproxy.enable = true;
+ tun.enable = true;
+ tun.perApp.enable = true;
+ };
+ };
+ };
+ hybridFixture = evalProxySuite [ hybridModule ];
+ hybridTproxyConfig = mkTProxyConfig hybridFixture;
+ hybridTunConfig = mkTunConfig hybridFixture;
+ hybridStartScript = builtins.readFile (
+ hybridFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
+ );
+ hybridTunStartScript = builtins.readFile (
+ hybridFixture.config.systemd.services."proxy-suite-tun".serviceConfig.ExecStart
+ );
+ hybridPerAppTunStartScript = builtins.readFile (
+ hybridFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStart
+ );
+ hybridXrayRawFixture = evalProxySuite [
{
system.stateVersion = "26.05";
services.proxy-suite = {
@@ -445,11 +506,22 @@ let
enable = true;
singBox.enable = true;
xray.enable = true;
- outbounds = [ { tag = "primary"; url = "http://proxy.example.com:8080"; } ];
+ outbounds = [
+ {
+ tag = "raw-xray";
+ xrayJson = {
+ protocol = "freedom";
+ settings = { };
+ };
+ }
+ ];
};
};
}
];
+ hybridXrayRawStartScript = builtins.readFile (
+ hybridXrayRawFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
+ );
proxyEnabledNoBackend = mkBadFixtureRaw [
{
system.stateVersion = "26.05";
@@ -457,7 +529,12 @@ let
enable = true;
proxy = {
enable = true;
- outbounds = [ { tag = "primary"; url = "http://proxy.example.com:8080"; } ];
+ outbounds = [
+ {
+ tag = "primary";
+ url = "http://proxy.example.com:8080";
+ }
+ ];
};
};
}
@@ -471,7 +548,12 @@ let
enable = true;
xray.enable = true;
selection = "selector";
- outbounds = [ { tag = "primary"; url = "http://proxy.example.com:8080"; } ];
+ outbounds = [
+ {
+ tag = "primary";
+ url = "http://proxy.example.com:8080";
+ }
+ ];
};
};
}
@@ -487,7 +569,9 @@ let
outbounds = [
{
tag = "raw";
- singBoxJson = { type = "direct"; };
+ singBoxJson = {
+ type = "direct";
+ };
}
];
};
@@ -505,7 +589,10 @@ let
outbounds = [
{
tag = "raw";
- xrayJson = { protocol = "freedom"; settings = { }; };
+ xrayJson = {
+ protocol = "freedom";
+ settings = { };
+ };
}
];
};
@@ -572,7 +659,8 @@ let
};
}
];
- tgWithGlobalTunServiceConfig = tgWithGlobalTun.config.systemd.services."proxy-suite-tg-ws-proxy".serviceConfig;
+ tgWithGlobalTunServiceConfig =
+ tgWithGlobalTun.config.systemd.services."proxy-suite-tg-ws-proxy".serviceConfig;
tgWithGlobalTunBypassUp = builtins.readFile tgWithGlobalTunServiceConfig.ExecStartPre;
tgWithGlobalTunBypassDown = builtins.readFile tgWithGlobalTunServiceConfig.ExecStopPost;
tgWithGlobalTunRules = mkRoutingRules tgWithGlobalTun;
@@ -611,8 +699,14 @@ let
enable = true;
singBox.enable = true;
outbounds = [
- { tag = "dup"; url = "http://one.example.com:8080"; }
- { tag = "dup"; url = "http://two.example.com:8080"; }
+ {
+ tag = "dup";
+ url = "http://one.example.com:8080";
+ }
+ {
+ tag = "dup";
+ url = "http://two.example.com:8080";
+ }
];
};
}).config.system.build.toplevel.drvPath
@@ -624,7 +718,12 @@ let
proxy = {
enable = true;
singBox.enable = true;
- outbounds = [ { tag = "proxy"; url = "http://proxy.example.com:8080"; } ];
+ outbounds = [
+ {
+ tag = "proxy";
+ url = "http://proxy.example.com:8080";
+ }
+ ];
};
}).config.system.build.toplevel.drvPath
);
@@ -635,8 +734,18 @@ let
proxy = {
enable = true;
singBox.enable = true;
- outbounds = [ { tag = "primary"; url = "http://proxy.example.com:8080"; } ];
- routing.rules = [ { outbound = "missing"; domains = [ "example.com" ]; } ];
+ outbounds = [
+ {
+ tag = "primary";
+ url = "http://proxy.example.com:8080";
+ }
+ ];
+ routing.rules = [
+ {
+ outbound = "missing";
+ domains = [ "example.com" ];
+ }
+ ];
};
}).config.system.build.toplevel.drvPath
);
@@ -668,7 +777,8 @@ let
services.proxy-suite.proxy.tproxy.enable = true;
}
];
- tproxyManualServiceConfig = tproxyManualFixture.config.systemd.services."proxy-suite-tproxy".serviceConfig;
+ tproxyManualServiceConfig =
+ tproxyManualFixture.config.systemd.services."proxy-suite-tproxy".serviceConfig;
tproxyManualStartScript = builtins.readFile tproxyManualServiceConfig.ExecStart;
tproxyManualStopScript = builtins.readFile tproxyManualServiceConfig.ExecStop;
@@ -702,18 +812,34 @@ let
conflictingAutostartModes = mkBadFixture [
{
services.proxy-suite.proxy = {
- tproxy = { enable = true; autostart = true; };
- tun = { enable = true; autostart = true; };
+ tproxy = {
+ enable = true;
+ autostart = true;
+ };
+ tun = {
+ enable = true;
+ autostart = true;
+ };
};
}
];
globalTunWithoutProxy = mkBadFixture [
- { services.proxy-suite.proxy = { enable = false; tun.enable = true; }; }
+ {
+ services.proxy-suite.proxy = {
+ enable = false;
+ tun.enable = true;
+ };
+ }
];
globalTproxyWithoutProxy = mkBadFixture [
- { services.proxy-suite.proxy = { enable = false; tproxy.enable = true; }; }
+ {
+ services.proxy-suite.proxy = {
+ enable = false;
+ tproxy.enable = true;
+ };
+ }
];
routingOrFixture = evalProxySuite [
@@ -957,8 +1083,16 @@ let
services.proxy-suite.zapret = {
enable = true;
hostlistRules = [
- { name = "dup"; domains = [ "one.example" ]; nfqwsArgs = [ "--filter-tcp=443 --dpi-desync=fake" ]; }
- { name = "dup"; domains = [ "two.example" ]; nfqwsArgs = [ "--filter-tcp=443 --dpi-desync=fake" ]; }
+ {
+ name = "dup";
+ domains = [ "one.example" ];
+ nfqwsArgs = [ "--filter-tcp=443 --dpi-desync=fake" ];
+ }
+ {
+ name = "dup";
+ domains = [ "two.example" ];
+ nfqwsArgs = [ "--filter-tcp=443 --dpi-desync=fake" ];
+ }
];
};
}
@@ -969,7 +1103,11 @@ let
services.proxy-suite.zapret = {
enable = true;
hostlistRules = [
- { name = "empty"; domains = [ ]; nfqwsArgs = [ "--filter-tcp=443 --dpi-desync=fake" ]; }
+ {
+ name = "empty";
+ domains = [ ];
+ nfqwsArgs = [ "--filter-tcp=443 --dpi-desync=fake" ];
+ }
];
};
}
@@ -979,7 +1117,12 @@ let
{
services.proxy-suite.zapret = {
enable = true;
- hostlistRules = [ { name = "missing"; domains = [ "missing.example" ]; } ];
+ hostlistRules = [
+ {
+ name = "missing";
+ domains = [ "missing.example" ];
+ }
+ ];
};
}
];
@@ -1031,24 +1174,21 @@ let
};
}
];
- subscriptionOnlyProxyCtl =
- packageByPattern subscriptionOnlyFixture.config.environment.systemPackages ".*/[^/]*proxy-ctl(-[0-9.]+)?$";
- subscriptionOnlyWrapper =
- builtins.readFile "${subscriptionOnlyProxyCtl}/bin/proxy-ctl";
+ subscriptionOnlyProxyCtl = packageByPattern subscriptionOnlyFixture.config.environment.systemPackages ".*/[^/]*proxy-ctl(-[0-9.]+)?$";
+ subscriptionOnlyWrapper = builtins.readFile "${subscriptionOnlyProxyCtl}/bin/proxy-ctl";
subscriptionOnlyScript =
subscriptionOnlyWrapper
+ "\n"
+ builtins.readFile "${subscriptionOnlyProxyCtl}/bin/.proxy-ctl-wrapped";
- subscriptionOnlyTags =
- builtins.fromJSON (
- builtins.readFile (
- shellValueByPrefix subscriptionOnlyWrapper "export SUB_TAGS_FILE="
- )
- );
+ subscriptionOnlyTags = builtins.fromJSON (
+ builtins.readFile (shellValueByPrefix subscriptionOnlyWrapper "export SUB_TAGS_FILE=")
+ );
subscriptionOnlyStartScript =
- builtins.readFile subscriptionOnlyFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart;
+ builtins.readFile
+ subscriptionOnlyFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart;
subscriptionOnlyUpdateScript =
- builtins.readFile subscriptionOnlyFixture.config.systemd.services."proxy-suite-subscription-update".serviceConfig.ExecStart;
+ builtins.readFile
+ subscriptionOnlyFixture.config.systemd.services."proxy-suite-subscription-update".serviceConfig.ExecStart;
subscriptionWithStaticFixture = evalProxySuite [
{
@@ -1085,8 +1225,14 @@ let
enable = true;
singBox.enable = true;
subscriptions = [
- { tag = "dup"; url = "https://example.com/sub/one"; }
- { tag = "dup"; url = "https://example.com/sub/two"; }
+ {
+ tag = "dup";
+ url = "https://example.com/sub/one";
+ }
+ {
+ tag = "dup";
+ url = "https://example.com/sub/two";
+ }
];
};
};
@@ -1101,7 +1247,12 @@ let
proxy = {
enable = true;
singBox.enable = true;
- subscriptions = [ { tag = "bad/tag"; url = "https://example.com/sub/token"; } ];
+ subscriptions = [
+ {
+ tag = "bad/tag";
+ url = "https://example.com/sub/token";
+ }
+ ];
};
};
}
@@ -1148,10 +1299,9 @@ let
};
}
];
- subscriptionPerAppTunUpdateScript =
- builtins.readFile (
- subscriptionPerAppTunFixture.config.systemd.services."proxy-suite-subscription-update".serviceConfig.ExecStart
- );
+ subscriptionPerAppTunUpdateScript = builtins.readFile (
+ subscriptionPerAppTunFixture.config.systemd.services."proxy-suite-subscription-update".serviceConfig.ExecStart
+ );
subscriptionUrlFileFixture = evalProxySuite [
{
@@ -1221,8 +1371,9 @@ let
perAppRoutingProxychainsWrapper = _perAppRoutingProxychains.wrapper;
perAppRoutingProxychainsScript = _perAppRoutingProxychains.script;
perAppRoutingProxychainsProfiles = _perAppRoutingProxychains.profiles;
- perAppRoutingProxychainsConfig =
- builtins.readFile (shellValueByPrefix perAppRoutingProxychainsWrapper "export PROXYCHAINS_CONFIG=");
+ perAppRoutingProxychainsConfig = builtins.readFile (
+ shellValueByPrefix perAppRoutingProxychainsWrapper "export PROXYCHAINS_CONFIG="
+ );
localProxyAuthFixture = evalProxySuite [
baseModule
@@ -1250,7 +1401,12 @@ let
perAppRouting = {
enable = true;
proxychains.enable = true;
- profiles = [ { name = "steam-browser"; route = "proxychains"; } ];
+ profiles = [
+ {
+ name = "steam-browser";
+ route = "proxychains";
+ }
+ ];
};
};
}
@@ -1305,7 +1461,12 @@ let
perAppRoutingNoDefaultProfiles = _perAppRoutingNoDefaultProfiles.profiles;
perAppRoutingDefaultProfilesWithoutProxychainsEnable = mkBadFixture [
- { services.proxy-suite.perAppRouting = { enable = true; createDefaultProfiles = true; }; }
+ {
+ services.proxy-suite.perAppRouting = {
+ enable = true;
+ createDefaultProfiles = true;
+ };
+ }
];
perAppRoutingTunFixture = evalProxySuite [
@@ -1325,16 +1486,19 @@ let
perAppRoutingTunWrapper = _perAppRoutingTun.wrapper;
perAppRoutingTunScript = _perAppRoutingTun.script;
perAppRoutingTunProfiles = _perAppRoutingTun.profiles;
- perAppRoutingTunServiceConfig = perAppRoutingTunFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig;
+ perAppRoutingTunServiceConfig =
+ perAppRoutingTunFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig;
perAppRoutingTunStartScript = builtins.readFile perAppRoutingTunServiceConfig.ExecStart;
perAppRoutingTunCleanupScript = builtins.readFile perAppRoutingTunServiceConfig.ExecStopPost;
perAppRoutingTunConfig = mkPerAppTunConfig perAppRoutingTunFixture;
- perAppRoutingTunDirectOutbound =
- builtins.head (builtins.filter (item: item.tag == "direct") perAppRoutingTunConfig.outbounds);
+ perAppRoutingTunDirectOutbound = builtins.head (
+ builtins.filter (item: item.tag == "direct") perAppRoutingTunConfig.outbounds
+ );
perAppRoutingTunUserStartExec =
perAppRoutingTunFixture.config.systemd.services."proxy-suite-per-app-tun-user@".serviceConfig.ExecStart;
- perAppRoutingTunUserStartScript =
- builtins.readFile (builtins.head (pkgs.lib.splitString " " perAppRoutingTunUserStartExec));
+ perAppRoutingTunUserStartScript = builtins.readFile (
+ builtins.head (pkgs.lib.splitString " " perAppRoutingTunUserStartExec)
+ );
perAppRoutingTunWithTproxyFixture = evalProxySuite [
baseModule
@@ -1352,16 +1516,23 @@ let
}
];
perAppRoutingTunWithTproxyStartScript =
- builtins.readFile perAppRoutingTunWithTproxyFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStart;
+ builtins.readFile
+ perAppRoutingTunWithTproxyFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStart;
perAppRoutingTunWithTproxyConfig = mkPerAppTunConfig perAppRoutingTunWithTproxyFixture;
- perAppRoutingTunWithTproxyDirectOutbound =
- builtins.head (builtins.filter (item: item.tag == "direct") perAppRoutingTunWithTproxyConfig.outbounds);
+ perAppRoutingTunWithTproxyDirectOutbound = builtins.head (
+ builtins.filter (item: item.tag == "direct") perAppRoutingTunWithTproxyConfig.outbounds
+ );
perAppRoutingTunWithoutEnable = mkBadFixture [
{
services.proxy-suite.perAppRouting = {
enable = true;
- profiles = [ { name = "game"; route = "tun"; } ];
+ profiles = [
+ {
+ name = "game";
+ route = "tun";
+ }
+ ];
};
}
];
@@ -1383,19 +1554,26 @@ let
perAppRoutingTproxyWrapper = _perAppRoutingTproxy.wrapper;
perAppRoutingTproxyScript = _perAppRoutingTproxy.script;
perAppRoutingTproxyProfiles = _perAppRoutingTproxy.profiles;
- perAppRoutingTproxyServiceConfig = perAppRoutingTproxyFixture.config.systemd.services."proxy-suite-per-app-tproxy".serviceConfig;
+ perAppRoutingTproxyServiceConfig =
+ perAppRoutingTproxyFixture.config.systemd.services."proxy-suite-per-app-tproxy".serviceConfig;
perAppRoutingTproxyStartScript = builtins.readFile perAppRoutingTproxyServiceConfig.ExecStart;
perAppRoutingTproxyStopScript = builtins.readFile perAppRoutingTproxyServiceConfig.ExecStop;
perAppRoutingTproxyUserStartExec =
perAppRoutingTproxyFixture.config.systemd.services."proxy-suite-per-app-tproxy-user@".serviceConfig.ExecStart;
- perAppRoutingTproxyUserStartScript =
- builtins.readFile (builtins.head (pkgs.lib.splitString " " perAppRoutingTproxyUserStartExec));
+ perAppRoutingTproxyUserStartScript = builtins.readFile (
+ builtins.head (pkgs.lib.splitString " " perAppRoutingTproxyUserStartExec)
+ );
perAppRoutingTproxyWithoutEnable = mkBadFixture [
{
services.proxy-suite.perAppRouting = {
enable = true;
- profiles = [ { name = "browser"; route = "tproxy"; } ];
+ profiles = [
+ {
+ name = "browser";
+ route = "tproxy";
+ }
+ ];
};
}
];
@@ -1404,7 +1582,10 @@ let
{
services.proxy-suite = {
proxy.enable = false;
- perAppRouting = { enable = true; proxychains.enable = true; };
+ perAppRouting = {
+ enable = true;
+ proxychains.enable = true;
+ };
};
}
];
@@ -1412,7 +1593,10 @@ let
perAppRoutingTunBackendWithoutProxy = mkBadFixture [
{
services.proxy-suite = {
- proxy = { enable = false; tun.perApp.enable = true; };
+ proxy = {
+ enable = false;
+ tun.perApp.enable = true;
+ };
perAppRouting.enable = true;
};
}
@@ -1421,7 +1605,10 @@ let
perAppRoutingTproxyBackendWithoutProxy = mkBadFixture [
{
services.proxy-suite = {
- proxy = { enable = false; tproxy.perApp.enable = true; };
+ proxy = {
+ enable = false;
+ tproxy.perApp.enable = true;
+ };
perAppRouting.enable = true;
};
}
@@ -1431,7 +1618,15 @@ let
{
services.proxy-suite = {
proxy.enable = false;
- perAppRouting = { enable = true; profiles = [ { name = "game"; route = "tun"; } ]; };
+ perAppRouting = {
+ enable = true;
+ profiles = [
+ {
+ name = "game";
+ route = "tun";
+ }
+ ];
+ };
};
}
];
@@ -1440,7 +1635,15 @@ let
{
services.proxy-suite = {
proxy.enable = false;
- perAppRouting = { enable = true; profiles = [ { name = "browser"; route = "tproxy"; } ]; };
+ perAppRouting = {
+ enable = true;
+ profiles = [
+ {
+ name = "browser";
+ route = "tproxy";
+ }
+ ];
+ };
};
}
];
@@ -1467,18 +1670,20 @@ let
perAppRoutingZapretScript = _perAppRoutingZapret.script;
perAppRoutingZapretProfiles = _perAppRoutingZapret.profiles;
perAppRoutingZapretStartScript =
- readExecScripts perAppRoutingZapretFixture.config.systemd.services."proxy-suite-per-app-zapret".serviceConfig.ExecStartPre;
+ readExecScripts
+ perAppRoutingZapretFixture.config.systemd.services."proxy-suite-per-app-zapret".serviceConfig.ExecStartPre;
perAppRoutingZapretUserStartExec =
perAppRoutingZapretFixture.config.systemd.services."proxy-suite-per-app-zapret-user@".serviceConfig.ExecStart;
- perAppRoutingZapretUserStartScript =
- builtins.readFile (builtins.head (pkgs.lib.splitString " " perAppRoutingZapretUserStartExec));
- perAppRoutingZapretService = perAppRoutingZapretFixture.config.systemd.services."proxy-suite-per-app-zapret";
+ perAppRoutingZapretUserStartScript = builtins.readFile (
+ builtins.head (pkgs.lib.splitString " " perAppRoutingZapretUserStartExec)
+ );
+ perAppRoutingZapretService =
+ perAppRoutingZapretFixture.config.systemd.services."proxy-suite-per-app-zapret";
perAppRoutingZapretBase = mkZapretBase perAppRoutingZapretFixture;
perAppRoutingZapretConfig = builtins.readFile "${perAppRoutingZapretBase}/config";
perAppRoutingPerAppZapretBase = mkZapretBaseFor perAppRoutingZapretFixture "proxy-suite-per-app-zapret";
perAppRoutingPerAppZapretConfig = builtins.readFile "${perAppRoutingPerAppZapretBase}/config";
- perAppRoutingZapretGlobalCustomScript =
- builtins.readFile "${perAppRoutingZapretBase}/init.d/sysv/custom.d/50-proxy-suite-custom.sh";
+ perAppRoutingZapretGlobalCustomScript = builtins.readFile "${perAppRoutingZapretBase}/init.d/sysv/custom.d/50-proxy-suite-custom.sh";
perAppRoutingZapretWithoutGlobalFixture = evalProxySuite [
baseModule
@@ -1498,10 +1703,8 @@ let
];
_perAppRoutingZapretWithoutGlobal = mkProxyCtlDerived perAppRoutingZapretWithoutGlobalFixture;
perAppRoutingZapretWithoutGlobalProfiles = _perAppRoutingZapretWithoutGlobal.profiles;
- perAppRoutingZapretWithoutGlobalPerAppBase =
- mkZapretBaseFor perAppRoutingZapretWithoutGlobalFixture "proxy-suite-per-app-zapret";
- perAppRoutingZapretWithoutGlobalPerAppConfig =
- builtins.readFile "${perAppRoutingZapretWithoutGlobalPerAppBase}/config";
+ perAppRoutingZapretWithoutGlobalPerAppBase = mkZapretBaseFor perAppRoutingZapretWithoutGlobalFixture "proxy-suite-per-app-zapret";
+ perAppRoutingZapretWithoutGlobalPerAppConfig = builtins.readFile "${perAppRoutingZapretWithoutGlobalPerAppBase}/config";
perAppRoutingTunPolkitConfig = perAppRoutingTunFixture.config.security.polkit.extraConfig;
@@ -1548,7 +1751,15 @@ let
{
services.proxy-suite = {
zapret.enable = true;
- perAppRouting = { enable = true; profiles = [ { name = "yt"; route = "zapret"; } ]; };
+ perAppRouting = {
+ enable = true;
+ profiles = [
+ {
+ name = "yt";
+ route = "zapret";
+ }
+ ];
+ };
};
}
];
@@ -1557,7 +1768,10 @@ let
{
services.proxy-suite.perAppRouting = {
enable = true;
- profiles = [ { name = "dup"; } { name = "dup"; } ];
+ profiles = [
+ { name = "dup"; }
+ { name = "dup"; }
+ ];
};
}
];
@@ -1570,7 +1784,12 @@ let
{
services.proxy-suite.perAppRouting = {
enable = true;
- profiles = [ { name = "steam-browser"; route = "proxychains"; } ];
+ profiles = [
+ {
+ name = "steam-browser";
+ route = "proxychains";
+ }
+ ];
};
}
];
@@ -1579,8 +1798,14 @@ let
{
services.proxy-suite = {
proxy = {
- tproxy = { enable = true; proxyMark = 16; };
- tun.perApp = { enable = true; fwmark = 16; };
+ tproxy = {
+ enable = true;
+ proxyMark = 16;
+ };
+ tun.perApp = {
+ enable = true;
+ fwmark = 16;
+ };
};
perAppRouting.enable = true;
};
@@ -1590,7 +1815,13 @@ let
perAppRoutingTproxyFwmarkCollision = mkBadFixture [
{
services.proxy-suite = {
- proxy.tproxy = { proxyMark = 17; perApp = { enable = true; fwmark = 17; }; };
+ proxy.tproxy = {
+ proxyMark = 17;
+ perApp = {
+ enable = true;
+ fwmark = 17;
+ };
+ };
perAppRouting.enable = true;
};
}
@@ -1600,8 +1831,14 @@ let
{
services.proxy-suite = {
proxy = {
- tun.perApp = { enable = true; fwmark = 23; };
- tproxy.perApp = { enable = true; fwmark = 23; };
+ tun.perApp = {
+ enable = true;
+ fwmark = 23;
+ };
+ tproxy.perApp = {
+ enable = true;
+ fwmark = 23;
+ };
};
perAppRouting.enable = true;
};
@@ -1612,8 +1849,14 @@ let
{
services.proxy-suite = {
proxy = {
- tun.perApp = { enable = true; routeTable = 123; };
- tproxy.perApp = { enable = true; routeTable = 123; };
+ tun.perApp = {
+ enable = true;
+ routeTable = 123;
+ };
+ tproxy.perApp = {
+ enable = true;
+ routeTable = 123;
+ };
};
perAppRouting.enable = true;
};
@@ -1623,7 +1866,13 @@ let
perAppRoutingZapretFilterMarkCollision = mkBadFixture [
{
services.proxy-suite = {
- zapret = { enable = true; perApp = { enable = true; filterMark = 268435456; }; };
+ zapret = {
+ enable = true;
+ perApp = {
+ enable = true;
+ filterMark = 268435456;
+ };
+ };
proxy.tproxy.proxyMark = 268435456;
perAppRouting.enable = true;
};
@@ -1633,8 +1882,17 @@ let
perAppRoutingTproxyZapretMarkCollision = mkBadFixture [
{
services.proxy-suite = {
- zapret = { enable = true; perApp = { enable = true; filterMark = 23; }; };
- proxy.tproxy.perApp = { enable = true; fwmark = 23; };
+ zapret = {
+ enable = true;
+ perApp = {
+ enable = true;
+ filterMark = 23;
+ };
+ };
+ proxy.tproxy.perApp = {
+ enable = true;
+ fwmark = 23;
+ };
perAppRouting.enable = true;
};
}
@@ -1650,7 +1908,11 @@ let
enable = true;
singBox.enable = true;
subscriptions = [
- { tag = "bad"; url = "https://example.com/sub/token"; urlFile = "/run/secrets/sub-url"; }
+ {
+ tag = "bad";
+ url = "https://example.com/sub/token";
+ urlFile = "/run/secrets/sub-url";
+ }
];
};
};
@@ -1750,21 +2012,27 @@ let
assert pkgs.lib.hasInfix ''LOCAL_PROXY_PASSWORD="$(cat "'' localProxyAuthStartScript;
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" localProxyAuthStartScript;
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' localProxyAuthStartScript;
- assert pkgs.lib.hasInfix ''--arg user local-user'' localProxyAuthStartScript;
+ assert pkgs.lib.hasInfix "--arg user local-user" localProxyAuthStartScript;
assert pkgs.lib.hasInfix ''--arg password "$LOCAL_PROXY_PASSWORD"'' localProxyAuthStartScript;
- assert pkgs.lib.hasInfix ''select(.type == "mixed" and .tag == "mixed-in") | .users'' localProxyAuthBackendJqFilter;
+ assert pkgs.lib.hasInfix ''select(.type == "mixed" and .tag == "mixed-in") | .users''
+ localProxyAuthBackendJqFilter;
assert pkgs.lib.hasInfix ''chmod 600 "$RUNTIME_DIR/config.json"'' localProxyAuthStartScript;
true
)
# -- proxy.auth: passwordFile is read from runtime path and proxychains uses runtime config --
(
- assert pkgs.lib.hasInfix ''/run/secrets/local-proxy-password'' localProxyAuthPasswordFileStartScript;
- assert pkgs.lib.hasInfix ''/run/proxy-suite-socks/proxychains.conf'' localProxyAuthPasswordFileStartScript;
+ assert pkgs.lib.hasInfix "/run/secrets/local-proxy-password" localProxyAuthPasswordFileStartScript;
+ assert pkgs.lib.hasInfix "/run/proxy-suite-socks/proxychains.conf"
+ localProxyAuthPasswordFileStartScript;
assert pkgs.lib.hasInfix "printf 'socks5 %s %s %s %s\\n'" localProxyAuthPasswordFileStartScript;
- assert pkgs.lib.hasInfix ''chgrp proxy-suite "/run/proxy-suite-socks/proxychains.conf"'' localProxyAuthPasswordFileStartScript;
- assert pkgs.lib.hasInfix ''chmod 640 "/run/proxy-suite-socks/proxychains.conf"'' localProxyAuthPasswordFileStartScript;
+ assert pkgs.lib.hasInfix ''chgrp proxy-suite "/run/proxy-suite-socks/proxychains.conf"''
+ localProxyAuthPasswordFileStartScript;
+ assert pkgs.lib.hasInfix ''chmod 640 "/run/proxy-suite-socks/proxychains.conf"''
+ localProxyAuthPasswordFileStartScript;
assert builtins.hasAttr "proxy-suite" localProxyAuthPasswordFileFixture.config.users.groups;
- assert shellValueByPrefix localProxyAuthPasswordFileWrapper "export PROXYCHAINS_CONFIG=" == "/run/proxy-suite-socks/proxychains.conf";
+ assert
+ shellValueByPrefix localProxyAuthPasswordFileWrapper "export PROXYCHAINS_CONFIG="
+ == "/run/proxy-suite-socks/proxychains.conf";
assert pkgs.lib.hasInfix "Proxychains config is not readable" localProxyAuthPasswordFileScript;
true
)
@@ -1818,6 +2086,49 @@ let
assert pkgs.lib.hasInfix customSingBoxPackageBin customSingBoxPackageStartScript;
true
)
+ # -- hybrid backend: sing-box frontend with XRay loopback sidecar --
+ (
+ let
+ dnsBridgeInbound = builtins.head (
+ builtins.filter (inbound: inbound.tag == "xray-dns-in") hybridTproxyConfig.inbounds
+ );
+ mixedInbound = builtins.head (
+ builtins.filter (inbound: inbound.tag == "mixed-in") hybridTproxyConfig.inbounds
+ );
+ tproxyInbound = builtins.head (
+ builtins.filter (inbound: inbound.tag == "tproxy-in") hybridTproxyConfig.inbounds
+ );
+ tunDnsBridgeInbound = builtins.head (
+ builtins.filter (inbound: inbound.tag == "xray-dns-in") hybridTunConfig.inbounds
+ );
+ in
+ assert hybridFixture.config.services.proxy-suite.proxy.singBox.enable;
+ assert hybridFixture.config.services.proxy-suite.proxy.xray.enable;
+ assert hybridTproxyConfig ? route;
+ assert !(hybridTproxyConfig ? routing);
+ assert dnsBridgeInbound.type == "direct";
+ assert dnsBridgeInbound.listen == "127.0.0.1";
+ assert dnsBridgeInbound.listen_port == 18533;
+ assert mixedInbound.type == "mixed";
+ assert tproxyInbound.type == "tproxy";
+ assert tunDnsBridgeInbound.listen_port == 18534;
+ assert pkgs.lib.hasInfix "/bin/sing-box run -c" hybridStartScript;
+ assert pkgs.lib.hasInfix "/bin/xray run -c" hybridStartScript;
+ assert pkgs.lib.hasInfix "xray-sidecar.json" hybridStartScript;
+ assert pkgs.lib.hasInfix "XRAY_SIDECAR_NEXT_PORT=33080" hybridStartScript;
+ assert pkgs.lib.hasInfix "XRAY_SIDECAR_DNS_PORT=18533" hybridStartScript;
+ assert pkgs.lib.hasInfix "XRAY_SIDECAR_NEXT_PORT=33180" hybridTunStartScript;
+ assert pkgs.lib.hasInfix "XRAY_SIDECAR_DNS_PORT=18534" hybridTunStartScript;
+ assert pkgs.lib.hasInfix "XRAY_SIDECAR_NEXT_PORT=33280" hybridPerAppTunStartScript;
+ assert pkgs.lib.hasInfix "XRAY_SIDECAR_DNS_PORT=18535" hybridPerAppTunStartScript;
+ assert pkgs.lib.hasInfix "--backend sing-box" hybridStartScript;
+ assert pkgs.lib.hasInfix "--backend xray" hybridStartScript;
+ assert pkgs.lib.hasInfix "_proxy_suite_add_xray_sidecar_ob" hybridStartScript;
+ assert pkgs.lib.hasInfix "hybrid XRay json sidecar" hybridXrayRawStartScript;
+ assert pkgs.lib.hasInfix ''{type:"socks",tag:$tag,server:"127.0.0.1"'' hybridXrayRawStartScript;
+ assert pkgs.lib.hasInfix "routing_mark:2" hybridXrayRawStartScript;
+ true
+ )
# -- xray backend: same service surface, XRay config shape, and urltest balancer --
(
let
@@ -1876,14 +2187,26 @@ let
tunDnsOutbound = builtins.head (
builtins.filter (outbound: outbound.tag == "dns-out") xrayTunConfig.outbounds
);
- tunHasFinalRuleTag = builtins.any (rule: (rule ? ruleTag) && rule.ruleTag == "final-default") xrayTunConfig.routing.rules;
- tunHasDirectGeositeRule = builtins.any (rule: (rule ? ruleTag) && rule.ruleTag == "direct-geosite") xrayTunConfig.routing.rules;
- tunHasDnsHijackRule = builtins.any (rule: (rule ? ruleTag) && rule.ruleTag == "dns-hijack") xrayTunConfig.routing.rules;
- tunHasDnsUpstreamRule = builtins.any (rule: (rule ? ruleTag) && rule.ruleTag == "dns-upstream-direct") xrayTunConfig.routing.rules;
+ tunHasFinalRuleTag = builtins.any (
+ rule: (rule ? ruleTag) && rule.ruleTag == "final-default"
+ ) xrayTunConfig.routing.rules;
+ tunHasDirectGeositeRule = builtins.any (
+ rule: (rule ? ruleTag) && rule.ruleTag == "direct-geosite"
+ ) xrayTunConfig.routing.rules;
+ tunHasDnsHijackRule = builtins.any (
+ rule: (rule ? ruleTag) && rule.ruleTag == "dns-hijack"
+ ) xrayTunConfig.routing.rules;
+ tunHasDnsUpstreamRule = builtins.any (
+ rule: (rule ? ruleTag) && rule.ruleTag == "dns-upstream-direct"
+ ) xrayTunConfig.routing.rules;
in
assert tunInbound.protocol == "tun";
assert tunInbound.settings.name == "singtun0";
- assert tunInbound.settings.gateway == [ "172.19.0.1/30" "fd66:19::1/64" ];
+ assert
+ tunInbound.settings.gateway == [
+ "172.19.0.1/30"
+ "fd66:19::1/64"
+ ];
assert builtins.length tunInbound.settings.dns == 2;
assert tunInbound.settings.autoOutboundsInterface == "auto";
assert tunInbound.sniffing.destOverride == [ "fakedns" ];
@@ -1901,14 +2224,23 @@ let
assert (builtins.elemAt xrayTunConfig.dns.servers 2).tag == "local";
assert builtins.length xrayTunConfig.fakedns == 2;
assert tunDnsOutbound.protocol == "dns";
- assert tunDnsOutbound.settings.rules == [ { action = "direct"; qType = "2-27,29-65535"; } ];
+ assert
+ tunDnsOutbound.settings.rules == [
+ {
+ action = "direct";
+ qType = "2-27,29-65535";
+ }
+ ];
assert tunDirectOutbound.streamSettings.sockopt.mark == 2;
assert xrayStartBackendJqFilterFile == xrayTunBackendJqFilterFile;
assert xrayTunBackendJqFilterFile == xrayPerAppTunBackendJqFilterFile;
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" xrayStartScript;
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' xrayStartScript;
- assert pkgs.lib.hasInfix ''select(.protocol == "socks" and .tag == "mixed-in") | .settings.accounts'' xrayBackendJqFilter;
- assert !(pkgs.lib.hasInfix ''select(.protocol == "socks" and .tag == "mixed-in") | .settings.users'' xrayBackendJqFilter);
+ assert pkgs.lib.hasInfix
+ ''select(.protocol == "socks" and .tag == "mixed-in") | .settings.accounts''
+ xrayBackendJqFilter;
+ assert
+ !(pkgs.lib.hasInfix ''select(.protocol == "socks" and .tag == "mixed-in") | .settings.users'' xrayBackendJqFilter);
assert pkgs.lib.hasInfix "xray-loglevel" xrayTunStartScript;
assert pkgs.lib.hasInfix "XRAY_SINGLE_PROXY_TAG=" xrayTunStartScript;
assert pkgs.lib.hasInfix "ip -4 route get 1.1.1.1" xrayTunStartScript;
@@ -1930,17 +2262,25 @@ let
assert pkgs.lib.hasInfix ''uplink_addr="$('' xrayTunUpScript;
assert pkgs.lib.hasInfix ''addr replace "$tun_cidr" dev singtun0'' xrayTunUpScript;
assert pkgs.lib.hasInfix ''-6 addr replace "$tun6_cidr" dev singtun0'' xrayTunUpScript;
- assert pkgs.lib.hasInfix ''route replace "$tun_route_prefix" dev singtun0 src "$tun_addr" table 2022'' xrayTunUpScript;
- assert pkgs.lib.hasInfix ''route replace default dev singtun0 src "$uplink_addr" table 2022'' xrayTunUpScript;
- assert pkgs.lib.hasInfix ''-6 route replace "$tun6_route_prefix" dev singtun0 table 2022'' xrayTunUpScript;
- assert pkgs.lib.hasInfix ''-6 route replace default dev singtun0 table 2022'' xrayTunUpScript;
+ assert pkgs.lib.hasInfix
+ ''route replace "$tun_route_prefix" dev singtun0 src "$tun_addr" table 2022''
+ xrayTunUpScript;
+ assert pkgs.lib.hasInfix ''route replace default dev singtun0 src "$uplink_addr" table 2022''
+ xrayTunUpScript;
+ assert pkgs.lib.hasInfix ''-6 route replace "$tun6_route_prefix" dev singtun0 table 2022''
+ xrayTunUpScript;
+ assert pkgs.lib.hasInfix "-6 route replace default dev singtun0 table 2022" xrayTunUpScript;
assert pkgs.lib.hasInfix "rule add pref 8996 fwmark 17 table 102" xrayTunUpScript;
assert pkgs.lib.hasInfix "rule add pref 8997 fwmark 16 table 101" xrayTunUpScript;
assert pkgs.lib.hasInfix "rule add pref 9000 not fwmark 2 table 2022" xrayTunUpScript;
assert pkgs.lib.hasInfix "-6 rule add pref 8997 fwmark 16 table 101" xrayTunUpScript;
assert pkgs.lib.hasInfix "-6 rule add pref 9000 not fwmark 2 table 2022" xrayTunUpScript;
assert perAppTunInbound.settings.name == "psperapptun0";
- assert perAppTunInbound.settings.gateway == [ "172.20.0.1/30" "fd66:20::1/64" ];
+ assert
+ perAppTunInbound.settings.gateway == [
+ "172.20.0.1/30"
+ "fd66:20::1/64"
+ ];
assert builtins.length perAppTunInbound.settings.dns == 2;
assert perAppTunInbound.sniffing.destOverride == [ "fakedns" ];
assert perAppTunInbound.sniffing.metadataOnly == true;
@@ -1964,18 +2304,24 @@ let
assert pkgs.lib.hasInfix ''uplink_addr="$('' xrayPerAppTunUpScript;
assert pkgs.lib.hasInfix ''addr replace "$tun_cidr" dev psperapptun0'' xrayPerAppTunUpScript;
assert pkgs.lib.hasInfix ''-6 addr replace "$tun6_cidr" dev psperapptun0'' xrayPerAppTunUpScript;
- assert pkgs.lib.hasInfix ''route replace "$tun_route_prefix" dev psperapptun0 src "$tun_addr" table 101'' xrayPerAppTunUpScript;
- assert pkgs.lib.hasInfix ''route replace default dev psperapptun0 src "$uplink_addr" table 101'' xrayPerAppTunUpScript;
- assert pkgs.lib.hasInfix ''-6 route replace "$tun6_route_prefix" dev psperapptun0 table 101'' xrayPerAppTunUpScript;
- assert pkgs.lib.hasInfix ''-6 route replace default dev psperapptun0 table 101'' xrayPerAppTunUpScript;
- assert pkgs.lib.hasInfix ''-6 rule add fwmark 16 table 101'' xrayPerAppTunUpScript;
- assert pkgs.lib.hasInfix ''-4 route flush table 101'' xrayPerAppTunCleanupScript;
- assert pkgs.lib.hasInfix ''-6 route flush table 101'' xrayPerAppTunCleanupScript;
+ assert pkgs.lib.hasInfix
+ ''route replace "$tun_route_prefix" dev psperapptun0 src "$tun_addr" table 101''
+ xrayPerAppTunUpScript;
+ assert pkgs.lib.hasInfix ''route replace default dev psperapptun0 src "$uplink_addr" table 101''
+ xrayPerAppTunUpScript;
+ assert pkgs.lib.hasInfix ''-6 route replace "$tun6_route_prefix" dev psperapptun0 table 101''
+ xrayPerAppTunUpScript;
+ assert pkgs.lib.hasInfix "-6 route replace default dev psperapptun0 table 101"
+ xrayPerAppTunUpScript;
+ assert pkgs.lib.hasInfix "-6 rule add fwmark 16 table 101" xrayPerAppTunUpScript;
+ assert pkgs.lib.hasInfix "-4 route flush table 101" xrayPerAppTunCleanupScript;
+ assert pkgs.lib.hasInfix "-6 route flush table 101" xrayPerAppTunCleanupScript;
assert pkgs.lib.hasInfix "resolvectl flush-caches" xrayPerAppTunCleanupScript;
true
)
(
- assert pkgs.lib.hasInfix ''CACHE_FILE="/var/lib/proxy-suite/subscriptions/xray/xray-sub.json"'' xraySubscriptionStartScript;
+ assert pkgs.lib.hasInfix ''CACHE_FILE="/var/lib/proxy-suite/subscriptions/xray/xray-sub.json"''
+ xraySubscriptionStartScript;
assert pkgs.lib.hasInfix "--backend xray" xraySubscriptionStartScript;
true
)
@@ -1999,7 +2345,6 @@ let
)
# -- backend selection and backend-specific raw JSON options are enforced --
(
- assert xrayBothBackends.success == false;
assert proxyEnabledNoBackend.success == false;
assert xraySelectorUnavailable.success == false;
assert xraySingBoxJsonUnavailable.success == false;
@@ -2073,19 +2418,18 @@ let
)
(
assert tunServiceConfig.ExecStartPre == tunServiceConfig.ExecStopPost;
- assert pkgs.lib.hasInfix ''delete table inet sing-box'' tunCleanupScript;
- assert pkgs.lib.hasInfix ''rule del table 2022'' tunCleanupScript;
- assert pkgs.lib.hasInfix ''rule del pref 8996'' tunCleanupScript;
- assert pkgs.lib.hasInfix ''rule del pref 8997'' tunCleanupScript;
- assert pkgs.lib.hasInfix ''route flush table 2022'' tunCleanupScript;
+ assert pkgs.lib.hasInfix "delete table inet sing-box" tunCleanupScript;
+ assert pkgs.lib.hasInfix "rule del table 2022" tunCleanupScript;
+ assert pkgs.lib.hasInfix "rule del pref 8996" tunCleanupScript;
+ assert pkgs.lib.hasInfix "rule del pref 8997" tunCleanupScript;
+ assert pkgs.lib.hasInfix "route flush table 2022" tunCleanupScript;
assert pkgs.lib.hasInfix "link del dev" tunCleanupScript;
assert pkgs.lib.hasInfix "singtun0" tunCleanupScript;
true
)
(
assert
- tunAutostartFixture.config.systemd.services."proxy-suite-tun".wantedBy
- == [ "multi-user.target" ];
+ tunAutostartFixture.config.systemd.services."proxy-suite-tun".wantedBy == [ "multi-user.target" ];
true
)
(
@@ -2402,8 +2746,10 @@ let
# -- subscription/runtime: generated cache paths use the raw validated tag, not shell-escaped quotes --
(
- assert pkgs.lib.hasInfix ''CACHE_FILE="/var/lib/proxy-suite/subscriptions/sing-box/community.json"'' subscriptionOnlyStartScript;
- assert pkgs.lib.hasInfix ''/var/lib/proxy-suite/subscriptions/sing-box/community.json.tmp'' subscriptionOnlyUpdateScript;
+ assert pkgs.lib.hasInfix ''CACHE_FILE="/var/lib/proxy-suite/subscriptions/sing-box/community.json"''
+ subscriptionOnlyStartScript;
+ assert pkgs.lib.hasInfix "/var/lib/proxy-suite/subscriptions/sing-box/community.json.tmp"
+ subscriptionOnlyUpdateScript;
assert !(pkgs.lib.hasInfix "subscriptions/'community'.json" subscriptionOnlyStartScript);
assert !(pkgs.lib.hasInfix "subscriptions/'community'.json" subscriptionOnlyUpdateScript);
true
@@ -2420,18 +2766,19 @@ let
# -- subscription/runtime: refresh only restarts sing-box units that are active --
(
- assert pkgs.lib.hasInfix ''is-active --quiet proxy-suite-socks'' subscriptionOnlyUpdateScript;
- assert pkgs.lib.hasInfix ''restart proxy-suite-socks'' subscriptionOnlyUpdateScript;
- assert pkgs.lib.hasInfix ''is-active --quiet proxy-suite-tun'' subscriptionOnlyUpdateScript;
- assert !(pkgs.lib.hasInfix ''SOCKS_WAS_ACTIVE'' subscriptionOnlyUpdateScript);
+ assert pkgs.lib.hasInfix "is-active --quiet proxy-suite-socks" subscriptionOnlyUpdateScript;
+ assert pkgs.lib.hasInfix "restart proxy-suite-socks" subscriptionOnlyUpdateScript;
+ assert pkgs.lib.hasInfix "is-active --quiet proxy-suite-tun" subscriptionOnlyUpdateScript;
+ assert !(pkgs.lib.hasInfix "SOCKS_WAS_ACTIVE" subscriptionOnlyUpdateScript);
true
)
# -- subscription/runtime: refresh also handles the per-app TUN sing-box service when present --
(
- assert pkgs.lib.hasInfix ''is-active --quiet proxy-suite-per-app-tun'' subscriptionPerAppTunUpdateScript;
- assert pkgs.lib.hasInfix ''restart proxy-suite-per-app-tun'' subscriptionPerAppTunUpdateScript;
- assert !(pkgs.lib.hasInfix ''PER_APP_TUN_WAS_ACTIVE'' subscriptionPerAppTunUpdateScript);
+ assert pkgs.lib.hasInfix "is-active --quiet proxy-suite-per-app-tun"
+ subscriptionPerAppTunUpdateScript;
+ assert pkgs.lib.hasInfix "restart proxy-suite-per-app-tun" subscriptionPerAppTunUpdateScript;
+ assert !(pkgs.lib.hasInfix "PER_APP_TUN_WAS_ACTIVE" subscriptionPerAppTunUpdateScript);
true
)
@@ -2453,29 +2800,36 @@ let
# -- runtime route mode: proxy-ctl wrapper exports the volatile state file and baseline default --
(
- assert shellValueByPrefix minimalProxyCtlWrapper "export ROUTE_MODE_STATE_FILE=" == "/run/proxy-suite/route-mode";
+ assert
+ shellValueByPrefix minimalProxyCtlWrapper "export ROUTE_MODE_STATE_FILE="
+ == "/run/proxy-suite/route-mode";
assert shellValueByPrefix minimalProxyCtlWrapper "export DEFAULT_ROUTE_MODE=" == "blacklist";
true
)
# -- runtime route mode: proxy-ctl help/status script exposes default + four explicit modes --
(
- assert pkgs.lib.hasInfix "route-mode default|whitelist|blacklist|all-proxy|all-bypass|status" minimalProxyCtlScript;
- assert pkgs.lib.hasInfix ''printf 'route_mode=%s\n' "$(_route_mode_current)"'' minimalProxyCtlScript;
- assert pkgs.lib.hasInfix ''printf 'default_route_mode=%s\n' "$(_route_mode_default)"'' minimalProxyCtlScript;
- assert pkgs.lib.hasInfix ''systemctl start "proxy-suite-route-mode@''${action}.service"'' minimalProxyCtlScript;
+ assert pkgs.lib.hasInfix "route-mode default|whitelist|blacklist|all-proxy|all-bypass|status"
+ minimalProxyCtlScript;
+ assert pkgs.lib.hasInfix ''printf 'route_mode=%s\n' "$(_route_mode_current)"''
+ minimalProxyCtlScript;
+ assert pkgs.lib.hasInfix ''printf 'default_route_mode=%s\n' "$(_route_mode_default)"''
+ minimalProxyCtlScript;
+ assert pkgs.lib.hasInfix ''systemctl start "proxy-suite-route-mode@''${action}.service"''
+ minimalProxyCtlScript;
true
)
# -- runtime route mode: socks start script includes all override branches and uses volatile state --
(
- assert pkgs.lib.hasInfix ''ROUTE_MODE_STATE_FILE="/run/proxy-suite/route-mode"'' routeModeStartScript;
+ assert pkgs.lib.hasInfix ''ROUTE_MODE_STATE_FILE="/run/proxy-suite/route-mode"''
+ routeModeStartScript;
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" routeModeStartScript;
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' routeModeStartScript;
- assert pkgs.lib.hasInfix ''all-proxy)'' routeModeStartScript;
- assert pkgs.lib.hasInfix ''all-bypass)'' routeModeStartScript;
- assert pkgs.lib.hasInfix ''.route.rules = $route_rules'' routeModeBackendJqFilter;
- assert pkgs.lib.hasInfix ''.dns.rules = []'' routeModeBackendJqFilter;
+ assert pkgs.lib.hasInfix "all-proxy)" routeModeStartScript;
+ assert pkgs.lib.hasInfix "all-bypass)" routeModeStartScript;
+ assert pkgs.lib.hasInfix ".route.rules = $route_rules" routeModeBackendJqFilter;
+ assert pkgs.lib.hasInfix ".dns.rules = []" routeModeBackendJqFilter;
true
)
@@ -2492,13 +2846,15 @@ let
(
let
setterSvc = routeModeFixture.config.systemd.services."proxy-suite-route-mode@";
- setterScript = builtins.readFile (builtins.head (pkgs.lib.splitString " " setterSvc.serviceConfig.ExecStart));
+ setterScript = builtins.readFile (
+ builtins.head (pkgs.lib.splitString " " setterSvc.serviceConfig.ExecStart)
+ );
in
assert !(setterSvc.serviceConfig ? RuntimeDirectory);
assert pkgs.lib.hasInfix "/run/proxy-suite/route-mode" setterScript;
- assert pkgs.lib.hasInfix ''default)'' setterScript;
- assert pkgs.lib.hasInfix ''all-proxy)'' setterScript;
- assert pkgs.lib.hasInfix ''all-bypass)'' setterScript;
+ assert pkgs.lib.hasInfix "default)" setterScript;
+ assert pkgs.lib.hasInfix "all-proxy)" setterScript;
+ assert pkgs.lib.hasInfix "all-bypass)" setterScript;
true
)
@@ -2520,7 +2876,9 @@ let
true
)
(
- assert builtins.length perAppRoutingProxychainsFixture.config.services.proxy-suite.perAppRouting.profiles == 2;
+ assert
+ builtins.length perAppRoutingProxychainsFixture.config.services.proxy-suite.perAppRouting.profiles
+ == 2;
true
)
(
@@ -2545,21 +2903,27 @@ let
# -- perAppRouting: createDefaultProfiles injects curated tun profile when backend is enabled --
(
assert builtins.length perAppRoutingTunProfiles == 2;
- assert builtins.any (profile: profile.name == "tun" && profile.route == "tun") perAppRoutingTunProfiles;
+ assert builtins.any (
+ profile: profile.name == "tun" && profile.route == "tun"
+ ) perAppRoutingTunProfiles;
true
)
# -- perAppRouting: createDefaultProfiles injects curated tproxy profile when backend is enabled --
(
assert builtins.length perAppRoutingTproxyProfiles == 2;
- assert builtins.any (profile: profile.name == "tproxy" && profile.route == "tproxy") perAppRoutingTproxyProfiles;
+ assert builtins.any (
+ profile: profile.name == "tproxy" && profile.route == "tproxy"
+ ) perAppRoutingTproxyProfiles;
true
)
# -- perAppRouting: createDefaultProfiles injects curated zapret profile when backend is enabled --
(
assert builtins.length perAppRoutingZapretProfiles == 2;
- assert builtins.any (profile: profile.name == "zapret" && profile.route == "zapret") perAppRoutingZapretProfiles;
+ assert builtins.any (
+ profile: profile.name == "zapret" && profile.route == "zapret"
+ ) perAppRoutingZapretProfiles;
true
)
@@ -2568,7 +2932,8 @@ let
assert pkgs.lib.hasInfix "help)" perAppRoutingProxychainsScript;
assert pkgs.lib.hasInfix "show this help message" perAppRoutingProxychainsScript;
assert pkgs.lib.hasInfix "enable/disable the proxy backend stack" perAppRoutingProxychainsScript;
- assert pkgs.lib.hasInfix "restart active global proxy-suite services" perAppRoutingProxychainsScript;
+ assert pkgs.lib.hasInfix "restart active global proxy-suite services"
+ perAppRoutingProxychainsScript;
assert pkgs.lib.hasInfix "wrap -- " perAppRoutingProxychainsScript;
assert pkgs.lib.hasInfix "apps" perAppRoutingProxychainsScript;
true
@@ -2593,16 +2958,20 @@ let
# -- perAppRouting: generated proxy-ctl script dispatches through proxychains4 --
(
assert pkgs.lib.hasInfix "export PROXYCHAINS_QUIET_ARG='-q'" perAppRoutingProxychainsScript;
- assert pkgs.lib.hasInfix "exec proxychains4 $PROXYCHAINS_QUIET_ARG -f \"$PROXYCHAINS_CONFIG\" \"$@\"" perAppRoutingProxychainsScript;
+ assert pkgs.lib.hasInfix
+ "exec proxychains4 $PROXYCHAINS_QUIET_ARG -f \"$PROXYCHAINS_CONFIG\" \"$@\""
+ perAppRoutingProxychainsScript;
true
)
# -- perAppRouting: generated proxy-ctl script dispatches tun profiles through systemd slices --
(
assert pkgs.lib.hasInfix "PER_APP_ROUTING_TUN_ENABLED" perAppRoutingTunScript;
- assert pkgs.lib.hasInfix "systemd-run --user --scope --quiet --collect --same-dir" perAppRoutingTunScript;
+ assert pkgs.lib.hasInfix "systemd-run --user --scope --quiet --collect --same-dir"
+ perAppRoutingTunScript;
assert pkgs.lib.hasInfix "_check_no_global_proxy tun" perAppRoutingTunScript;
- assert pkgs.lib.hasInfix ''_wrap_slice "proxy-suite-per-app-tun" "$PER_APP_ROUTING_TUN_ENABLED"'' perAppRoutingTunScript;
+ assert pkgs.lib.hasInfix ''_wrap_slice "proxy-suite-per-app-tun" "$PER_APP_ROUTING_TUN_ENABLED"''
+ perAppRoutingTunScript;
assert pkgs.lib.hasInfix "$slice_base-user@$uid.service" perAppRoutingTunScript;
assert pkgs.lib.hasInfix "cleanup_slice()" perAppRoutingTunScript;
assert pkgs.lib.hasInfix "trap cleanup_slice EXIT" perAppRoutingTunScript;
@@ -2612,16 +2981,20 @@ let
# -- perAppRouting: generated proxy-ctl script dispatches tproxy profiles through systemd slices --
(
assert pkgs.lib.hasInfix "PER_APP_ROUTING_TPROXY_ENABLED" perAppRoutingTproxyScript;
- assert pkgs.lib.hasInfix ''_wrap_slice "proxy-suite-per-app-tproxy" "$PER_APP_ROUTING_TPROXY_ENABLED"'' perAppRoutingTproxyScript;
- assert pkgs.lib.hasInfix ''$slice_base-''${profile}-$$'' perAppRoutingTproxyScript;
+ assert pkgs.lib.hasInfix
+ ''_wrap_slice "proxy-suite-per-app-tproxy" "$PER_APP_ROUTING_TPROXY_ENABLED"''
+ perAppRoutingTproxyScript;
+ assert pkgs.lib.hasInfix "$slice_base-\${profile}-$$" perAppRoutingTproxyScript;
true
)
# -- perAppRouting: generated proxy-ctl script dispatches zapret profiles through systemd slices --
(
assert pkgs.lib.hasInfix "PER_APP_ROUTING_ZAPRET_ENABLED" perAppRoutingZapretScript;
- assert pkgs.lib.hasInfix ''_wrap_slice "proxy-suite-per-app-zapret" "$PER_APP_ROUTING_ZAPRET_ENABLED"'' perAppRoutingZapretScript;
- assert pkgs.lib.hasInfix ''$slice_base-''${profile}-$$'' perAppRoutingZapretScript;
+ assert pkgs.lib.hasInfix
+ ''_wrap_slice "proxy-suite-per-app-zapret" "$PER_APP_ROUTING_ZAPRET_ENABLED"''
+ perAppRoutingZapretScript;
+ assert pkgs.lib.hasInfix "$slice_base-\${profile}-$$" perAppRoutingZapretScript;
true
)
@@ -2635,7 +3008,9 @@ let
# -- perAppRouting: app TUN config is separate and does not auto-route globally --
(
let
- inbound = builtins.head (builtins.filter (item: item.tag == "tun-in") perAppRoutingTunConfig.inbounds);
+ inbound = builtins.head (
+ builtins.filter (item: item.tag == "tun-in") perAppRoutingTunConfig.inbounds
+ );
in
assert inbound.interface_name == "psperapptun0";
assert inbound.address == [ "172.20.0.1/30" ];
@@ -2689,7 +3064,8 @@ let
(
assert perAppRoutingTproxyFixture.config.systemd.services ? "proxy-suite-per-app-tproxy";
assert perAppRoutingTproxyFixture.config.systemd.services ? "proxy-suite-per-app-tproxy-user@";
- assert perAppRoutingTproxyFixture.config.systemd.user.services ? "proxy-suite-per-app-tproxy-anchor";
+ assert
+ perAppRoutingTproxyFixture.config.systemd.user.services ? "proxy-suite-per-app-tproxy-anchor";
true
)
@@ -2697,7 +3073,8 @@ let
(
assert perAppRoutingZapretFixture.config.systemd.services ? "proxy-suite-per-app-zapret";
assert perAppRoutingZapretFixture.config.systemd.services ? "proxy-suite-per-app-zapret-user@";
- assert perAppRoutingZapretFixture.config.systemd.user.services ? "proxy-suite-per-app-zapret-anchor";
+ assert
+ perAppRoutingZapretFixture.config.systemd.user.services ? "proxy-suite-per-app-zapret-anchor";
assert builtins.elem "network-online.target" perAppRoutingZapretService.after;
assert builtins.elem "network-online.target" perAppRoutingZapretService.wants;
true
@@ -2705,12 +3082,20 @@ let
# -- perAppRouting: app zapret can run without the global zapret service --
(
- assert perAppRoutingZapretWithoutGlobalFixture.config.systemd.services ? "proxy-suite-per-app-zapret";
- assert perAppRoutingZapretWithoutGlobalFixture.config.systemd.services ? "proxy-suite-per-app-zapret-user@";
- assert perAppRoutingZapretWithoutGlobalFixture.config.systemd.user.services ? "proxy-suite-per-app-zapret-anchor";
- assert !(perAppRoutingZapretWithoutGlobalFixture.config.systemd.services ? "zapret-discord-youtube");
+ assert
+ perAppRoutingZapretWithoutGlobalFixture.config.systemd.services ? "proxy-suite-per-app-zapret";
+ assert
+ perAppRoutingZapretWithoutGlobalFixture.config.systemd.services
+ ? "proxy-suite-per-app-zapret-user@";
+ assert
+ perAppRoutingZapretWithoutGlobalFixture.config.systemd.user.services
+ ? "proxy-suite-per-app-zapret-anchor";
+ assert
+ !(perAppRoutingZapretWithoutGlobalFixture.config.systemd.services ? "zapret-discord-youtube");
assert builtins.length perAppRoutingZapretWithoutGlobalProfiles == 2;
- assert builtins.any (profile: profile.name == "zapret" && profile.route == "zapret") perAppRoutingZapretWithoutGlobalProfiles;
+ assert builtins.any (
+ profile: profile.name == "zapret" && profile.route == "zapret"
+ ) perAppRoutingZapretWithoutGlobalProfiles;
assert pkgs.lib.hasInfix "proxy-suite-per-app-zapret" perAppRoutingZapretWithoutGlobalPerAppBase;
assert !(pkgs.lib.hasInfix "proxy-suite-zapret" perAppRoutingZapretWithoutGlobalPerAppBase);
true
@@ -2720,16 +3105,20 @@ let
(
assert perAppRoutingTunFixture.config.networking.nftables.enable;
assert perAppRoutingTunFixture.config.users.groups ? "proxy-suite";
- assert builtins.elem "network-online.target" tunManualFixture.config.systemd.services."proxy-suite-tun".after;
- assert builtins.elem "network-online.target" tunManualFixture.config.systemd.services."proxy-suite-tun".wants;
+ assert builtins.elem "network-online.target"
+ tunManualFixture.config.systemd.services."proxy-suite-tun".after;
+ assert builtins.elem "network-online.target"
+ tunManualFixture.config.systemd.services."proxy-suite-tun".wants;
true
)
# -- userControl: default polkit rule covers both per-app and global proxy-ctl managed units --
(
- assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-per-app-\") === 0" perAppRoutingTunPolkitConfig;
+ assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-per-app-\") === 0"
+ perAppRoutingTunPolkitConfig;
assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-\") === 0" perAppRoutingTunPolkitConfig;
- assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-per-app-\") !== 0" perAppRoutingTunPolkitConfig;
+ assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-per-app-\") !== 0"
+ perAppRoutingTunPolkitConfig;
assert pkgs.lib.hasInfix "unit === \"zapret-discord-youtube.service\"" perAppRoutingTunPolkitConfig;
true
)
@@ -2738,18 +3127,27 @@ let
(
assert userControlGlobalOnlyFixture.config.users.groups ? "proxy-suite";
assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-\") === 0" userControlGlobalOnlyPolkitConfig;
- assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-per-app-\") !== 0" userControlGlobalOnlyPolkitConfig;
- assert builtins.match ".*unit\\.indexOf\\(\"proxy-suite-per-app-\"\\) === 0.*" userControlGlobalOnlyPolkitConfig == null;
- assert pkgs.lib.hasInfix "unit === \"zapret-discord-youtube.service\"" userControlGlobalOnlyPolkitConfig;
+ assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-per-app-\") !== 0"
+ userControlGlobalOnlyPolkitConfig;
+ assert
+ builtins.match ".*unit\\.indexOf\\(\"proxy-suite-per-app-\"\\) === 0.*" userControlGlobalOnlyPolkitConfig
+ == null;
+ assert pkgs.lib.hasInfix "unit === \"zapret-discord-youtube.service\""
+ userControlGlobalOnlyPolkitConfig;
true
)
# -- userControl: per-app-only rule covers per-app-scoped helpers only --
(
assert userControlPerAppOnlyFixture.config.users.groups ? "proxy-suite";
- assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-per-app-\") === 0" userControlPerAppOnlyPolkitConfig;
- assert builtins.match ".*unit\\.indexOf\\(\"proxy-suite-per-app-\"\\) !== 0.*" userControlPerAppOnlyPolkitConfig == null;
- assert builtins.match ".*unit === \"zapret-discord-youtube\\.service\".*" userControlPerAppOnlyPolkitConfig == null;
+ assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-per-app-\") === 0"
+ userControlPerAppOnlyPolkitConfig;
+ assert
+ builtins.match ".*unit\\.indexOf\\(\"proxy-suite-per-app-\"\\) !== 0.*" userControlPerAppOnlyPolkitConfig
+ == null;
+ assert
+ builtins.match ".*unit === \"zapret-discord-youtube\\.service\".*" userControlPerAppOnlyPolkitConfig
+ == null;
true
)
@@ -2757,8 +3155,12 @@ let
(
assert !(userControlDisabledFixture.config.users.groups ? "proxy-suite");
assert !userControlDisabledFixture.config.security.polkit.enable;
- assert builtins.match ".*subject\\.isInGroup\\(\"proxy-suite\"\\).*" userControlDisabledFixture.config.security.polkit.extraConfig == null;
- assert builtins.match ".*org\\.freedesktop\\.systemd1\\.manage-units.*" userControlDisabledFixture.config.security.polkit.extraConfig == null;
+ assert
+ builtins.match ".*subject\\.isInGroup\\(\"proxy-suite\"\\).*" userControlDisabledFixture.config.security.polkit.extraConfig
+ == null;
+ assert
+ builtins.match ".*org\\.freedesktop\\.systemd1\\.manage-units.*" userControlDisabledFixture.config.security.polkit.extraConfig
+ == null;
true
)
@@ -2774,7 +3176,8 @@ let
(
assert pkgs.lib.hasInfix "proxy_suite_per_app_tproxy" perAppRoutingTproxyStartScript;
assert pkgs.lib.hasInfix "rule del fwmark 17 table 102" perAppRoutingTproxyStartScript;
- assert pkgs.lib.hasInfix "route replace local default dev lo table 102" perAppRoutingTproxyStartScript;
+ assert pkgs.lib.hasInfix "route replace local default dev lo table 102"
+ perAppRoutingTproxyStartScript;
assert pkgs.lib.hasInfix "rule add fwmark 17 table 102" perAppRoutingTproxyStartScript;
assert pkgs.lib.hasInfix "set +e" perAppRoutingTproxyStopScript;
assert pkgs.lib.hasInfix "rule del fwmark 17 table 102" perAppRoutingTproxyStopScript;
@@ -2809,7 +3212,8 @@ let
assert pkgs.lib.hasInfix "QNUM=201" perAppRoutingPerAppZapretConfig;
assert pkgs.lib.hasInfix "DESYNC_MARK=0x8000000" perAppRoutingPerAppZapretConfig;
assert pkgs.lib.hasInfix "DESYNC_MARK_POSTNAT=0x4000000" perAppRoutingPerAppZapretConfig;
- assert pkgs.lib.hasInfix "ZAPRET_NFT_TABLE=proxy_suite_per_app_zapret" perAppRoutingPerAppZapretConfig;
+ assert pkgs.lib.hasInfix "ZAPRET_NFT_TABLE=proxy_suite_per_app_zapret"
+ perAppRoutingPerAppZapretConfig;
true
)
(
diff --git a/scripts/proxy_parsing.py b/scripts/proxy_parsing.py
index 93b7c88..281ade0 100644
--- a/scripts/proxy_parsing.py
+++ b/scripts/proxy_parsing.py
@@ -67,7 +67,7 @@ def _xray_tls(tls: dict | None) -> tuple[str, dict]:
def _xray_transport(transport: dict | None) -> tuple[str, dict]:
if not transport:
- return "tcp", {}
+ return "raw", {}
t = transport["type"]
if t == "ws":
@@ -107,6 +107,7 @@ def render_xray_outbound(ob: dict, routing_mark: int | None = None) -> dict:
stream = {"network": network, "security": security}
stream.update(sec)
stream.update(net)
+ stream.setdefault("sockopt", {})["domainStrategy"] = "UseIP"
if routing_mark is not None:
stream.setdefault("sockopt", {})["mark"] = routing_mark
return stream
diff --git a/scripts/proxy_url_parsers.py b/scripts/proxy_url_parsers.py
index 47e4068..eb83a8e 100644
--- a/scripts/proxy_url_parsers.py
+++ b/scripts/proxy_url_parsers.py
@@ -169,7 +169,7 @@ def parse_vless(url: str, tag: str, backend: str = "sing-box") -> dict:
"public_key": params["pbk"],
"short_id": params.get("sid", ""),
}
- if params.get("spx"):
+ if backend == "xray" and params.get("spx"):
ob["tls"]["reality"]["spider_x"] = params["spx"]
elif security == "tls":
ob["tls"] = _mk_tls(
diff --git a/scripts/test-build-outbound.py b/scripts/test-build-outbound.py
index 26101a3..5550e98 100644
--- a/scripts/test-build-outbound.py
+++ b/scripts/test-build-outbound.py
@@ -34,8 +34,24 @@ class BuildOutboundTests(unittest.TestCase):
self.assertEqual(ob["tls"]["server_name"], "last.fm")
self.assertEqual(ob["tls"]["utls"]["fingerprint"], "qq")
self.assertEqual(ob["tls"]["reality"]["short_id"], "8a54")
+ self.assertNotIn("spider_x", ob["tls"]["reality"])
self.assertNotIn("transport", ob)
+ def test_xray_vless_reality_germany_main_shape(self):
+ ob = run_xray_parser(
+ "vless://uuid@example.com:443?type=tcp&security=reality&pbk=pubkey&fp=qq&sni=last.fm&sid=8a54&spx=%2F-%2Fen%2Fgp%2Fbestsellers&flow=xtls-rprx-vision&encryption=none"
+ )
+ self.assertEqual(ob["protocol"], "vless")
+ self.assertEqual(ob["settings"]["address"], "example.com")
+ self.assertEqual(ob["settings"]["flow"], "xtls-rprx-vision")
+ self.assertEqual(ob["streamSettings"]["network"], "raw")
+ self.assertEqual(ob["streamSettings"]["sockopt"]["domainStrategy"], "UseIP")
+ self.assertEqual(ob["streamSettings"]["realitySettings"]["serverName"], "last.fm")
+ self.assertEqual(ob["streamSettings"]["realitySettings"]["fingerprint"], "qq")
+ self.assertEqual(
+ ob["streamSettings"]["realitySettings"]["spiderX"], "/-/en/gp/bestsellers"
+ )
+
def test_vless_httpupgrade_transport(self):
ob = run_parser(
"vless://uuid@example.com:443?type=httpupgrade&security=tls&sni=cdn.example.com&host=cdn.example.com&path=%2Fupgrade"