feat/wip: better awg to outbounds config

This commit is contained in:
fufsob committed 2026-09-15 10:34:42 +00:00
1 parent a82417a2bd
commit 9c9658baa7
26 files changed
+805 -218

No files matched your search

+216
View File
@@ -0,0 +1,216 @@
{
pkgs,
evalProxySuite,
mkBadProxySuiteFixture,
mkFailingAssertions,
mkProxyCtlDerived,
mkTProxyConfig,
dnsServerByTag,
}:
let
generated = import ./read-generated.nix;
inherit (pkgs.lib) hasInfix;
mkFixture =
backend:
evalProxySuite [
{
system.stateVersion = "26.05";
services.proxy-suite = {
enable = true;
proxy = {
enable = true;
inherit backend;
tproxy.enable = true;
};
amneziaWg = {
enable = true;
kernelModulePackage = null;
profiles = {
de = {
asOutbound = "interface";
configFile = "/run/secrets/de.conf";
};
plain = {
asOutbound = "singBox";
configFile = "/run/secrets/plain.conf";
};
home.configFile = "/run/secrets/home.conf";
};
};
};
}
];
singBox = mkFixture "sing-box";
xray = mkFixture "xray";
hybrid = mkFixture "hybrid";
services = singBox.config.systemd.services;
startOf =
fixture:
generated.readDerivation fixture.config.systemd.services.proxy-suite-socks.serviceConfig.ExecStart;
singBoxStart = startOf singBox;
de = services.proxy-suite-awg-de;
dePrepare = generated.readDerivation (builtins.head de.serviceConfig.ExecStartPre);
deStart = generated.readDerivation de.serviceConfig.ExecStart;
plainTunnel = generated.readDerivation services.proxy-suite-awg-plain.serviceConfig.ExecStart;
dnsServer = dnsServerByTag (mkTProxyConfig singBox) "awg-dns-de";
warpInterface = evalProxySuite [
{
system.stateVersion = "26.05";
services.proxy-suite = {
enable = true;
proxy.enable = true;
amneziaWg.enable = true;
warp = {
enable = true;
configFile = "/run/secrets/wgcf-profile.conf";
asOutbound = "interface";
};
};
}
];
in
{
assertions = [
# "interface": the backend binds to the device and resolves through it.
(
assert hasInfix
''"bind_interface":"awg-de","domain_resolver":"awg-dns-de","routing_mark":2,"tag":"de","type":"direct"''
singBoxStart;
assert hasInfix "_proxy_suite_record_tag_source de awg" singBoxStart;
assert
dnsServer == {
tag = "awg-dns-de";
type = "udp";
server = "1.1.1.1";
server_port = 53;
bind_interface = "awg-de";
routing_mark = 2;
};
assert hasInfix
''"protocol":"freedom","streamSettings":{"sockopt":{"interface":"awg-de","mark":2}},"tag":"de"''
(startOf xray);
assert
hasInfix "_proxy_suite_add_sing_box_ob" (startOf hybrid)
&& hasInfix ''"bind_interface":"awg-de"'' (startOf hybrid);
true
)
# "interface": no routes, no bypass rule, no conflicts, always running.
(
assert hasInfix "--outbound-fwmark 2" dePrepare;
assert builtins.length de.serviceConfig.ExecStartPre == 1;
assert !(de.serviceConfig ? ExecStopPost);
assert (de.conflicts or [ ]) == [ ];
assert builtins.elem "multi-user.target" de.wantedBy;
assert de.serviceConfig.Restart == "on-failure";
assert hasInfix "ping -n -c 1 -I awg-de" deStart;
assert !(builtins.elem "proxy-suite-awg-de.service" services.proxy-suite-tproxy.conflicts);
assert builtins.elem "proxy-suite-awg-home.service" services.proxy-suite-tproxy.conflicts;
assert !(builtins.elem "proxy-suite-awg-de.service" services.proxy-suite-awg-home.conflicts);
assert hasInfix ''iifname "awg-de" accept''
singBox.config.networking.firewall.extraReversePathFilterRules;
assert (mkProxyCtlDerived singBox).awgProfiles == [ "home" ];
true
)
# "singBox": a tunnel unit behind a loopback SOCKS hop, fed the prepared profile.
(
assert hasInfix ''"server":"127.0.0.1","server_port":18542,"tag":"plain","type":"socks"''
singBoxStart;
assert hasInfix "_proxy_suite_record_tag_source plain awg" singBoxStart;
assert hasInfix "--output \"$profile\"" plainTunnel && !(hasInfix "--outbound-fwmark" plainTunnel);
assert hasInfix "warp_outbound.py --tag plain --routing-mark 2" plainTunnel;
assert hasInfix "listen_port: 18542" plainTunnel;
assert hasInfix ''detour: "plain"'' plainTunnel;
assert !(services ? proxy-suite-awg-plain-watchdog);
true
)
# warp.asOutbound = "interface" is the AmneziaWG profile, not the sing-box tunnel.
(
assert warpInterface.config.services.proxy-suite.amneziaWg.profiles.warp.asOutbound == "interface";
assert !(warpInterface.config.systemd.services ? proxy-suite-warp-tunnel);
assert hasInfix ''"bind_interface":"awg-warp"'' (startOf warpInterface);
true
)
]
++ mkFailingAssertions mkBadProxySuiteFixture [
# An outbound profile without a backend.
{
enable = true;
amneziaWg = {
enable = true;
profiles.de = {
asOutbound = "interface";
configFile = "/run/de.conf";
};
};
}
# An outbound profile always runs.
{
enable = true;
proxy.enable = true;
amneziaWg = {
enable = true;
profiles.de = {
asOutbound = "singBox";
autostart = true;
configFile = "/run/de.conf";
};
};
}
# Routes for an interface that must have none.
{
enable = true;
proxy.enable = true;
amneziaWg = {
enable = true;
profiles.de = {
asOutbound = "interface";
settings = {
addresses = [ "10.0.0.2/32" ];
privateKey = "private";
table = "auto";
peers = [
{
publicKey = "public";
allowedIPs = [ "0.0.0.0/0" ];
}
];
};
};
};
}
# warp.asOutbound = "interface" without AmneziaWG.
{
enable = true;
proxy.enable = true;
warp = {
enable = true;
configFile = "/run/wgcf.conf";
asOutbound = "interface";
};
}
# A profile tag colliding with a declared outbound.
{
enable = true;
proxy = {
enable = true;
outbounds = [
{
tag = "de";
url = "http://proxy.example.com:8080";
}
];
};
amneziaWg = {
enable = true;
profiles.de = {
asOutbound = "singBox";
configFile = "/run/de.conf";
};
};
}
];
}
+13
View File
@@ -168,6 +168,18 @@ let
;
};
amneziaWgOutboundChecks = import ./amnezia-wg-outbound.nix {
inherit
pkgs
evalProxySuite
mkBadProxySuiteFixture
mkFailingAssertions
mkProxyCtlDerived
mkTProxyConfig
dnsServerByTag
;
};
globalProxyModeChecks = import ./global-proxy-modes.nix {
inherit
pkgs
@@ -253,6 +265,7 @@ let
++ xrayBackendChecks.assertions
++ outboundValidationChecks.assertions
++ amneziaWgChecks.assertions
++ amneziaWgOutboundChecks.assertions
++ zapretChecks.assertions
++ zapret2Checks.assertions
++ globalProxyModeChecks.assertions
+8 -8
View File
@@ -44,20 +44,20 @@ let
singBoxHop = ''"server":"127.0.0.1","server_port":18538,"tag":"warp","type":"socks"'';
xrayHop = ''"protocol":"socks","settings":{"address":"127.0.0.1","port":18538},"tag":"warp"'';
singBox = mkFixture "sing-box" { asOutbound = true; };
singBox = mkFixture "sing-box" { asOutbound = "singBox"; };
singBoxStart = startOf singBox;
singBoxTunnel = tunnelOf singBox;
xray = mkFixture "xray" { asOutbound = true; };
xray = mkFixture "xray" { asOutbound = "singBox"; };
xrayStart = startOf xray;
hybrid = mkFixture "hybrid" { asOutbound = true; };
hybrid = mkFixture "hybrid" { asOutbound = "singBox"; };
hybridStart = startOf hybrid;
auto = mkFixture "sing-box" {
asOutbound = true;
asOutbound = "singBox";
configFile = null;
};
autoTunnel = tunnelOf auto;
generator = mkFixture "sing-box" {
asOutbound = true;
asOutbound = "singBox";
configFile = null;
generatorUrl = "https://gen.example.com/api/warp?mode=awg2";
};
@@ -97,7 +97,7 @@ let
warp = {
enable = true;
configFile = profile;
asOutbound = true;
asOutbound = "singBox";
};
}
# asAmneziaWg without AmneziaWG.
@@ -116,7 +116,7 @@ let
warp = {
enable = true;
configFile = profile;
asOutbound = true;
asOutbound = "singBox";
asAmneziaWg = true;
};
proxy.enable = true;
@@ -127,7 +127,7 @@ let
warp = {
enable = true;
configFile = profile;
asOutbound = true;
asOutbound = "singBox";
};
proxy = {
enable = true;