Files
proxy-suite-flake/nix/checks/global-proxy-modes/fixtures.nix
T

168 lines
4.2 KiB
Nix

{
evalProxySuite,
baseModule,
mkBadFixture,
mkFailingAssertions,
mkTunConfig,
mkTProxyConfig,
mkTProxyNftRules,
}:
let
generated = import ../read-generated.nix;
tproxyWithFirewall = evalProxySuite [
{
system.stateVersion = "26.05";
networking.firewall.enable = true;
services.proxy-suite = {
enable = true;
proxy = {
enable = true;
backend = "sing-box";
tproxy.enable = true;
outbounds = [
{
tag = "primary";
url = "http://proxy.example.com:8080";
}
];
};
};
}
];
tproxyManualFixture = evalProxySuite [
baseModule
{
services.proxy-suite.proxy.tproxy.enable = true;
}
];
tproxyManualServiceConfig =
tproxyManualFixture.config.systemd.services."proxy-suite-tproxy".serviceConfig;
tproxyManualStartScript = generated.readDerivation tproxyManualServiceConfig.ExecStart;
tproxyManualStopScript = generated.readDerivation tproxyManualServiceConfig.ExecStop;
tproxyManualConfig = mkTProxyConfig tproxyManualFixture;
tproxyManualNftRules = mkTProxyNftRules tproxyManualFixture;
tproxyIPv4OnlyFixture = evalProxySuite [
baseModule
{
networking.enableIPv6 = false;
services.proxy-suite.proxy = {
tproxy.enable = true;
tun.enable = true;
};
services.proxy-suite.perAppRouting = {
enable = true;
tun.enable = true;
};
}
];
tproxyIPv4OnlyStartScript =
generated.readDerivation
tproxyIPv4OnlyFixture.config.systemd.services."proxy-suite-tproxy".serviceConfig.ExecStart;
tproxyIPv4OnlyConfig = mkTProxyConfig tproxyIPv4OnlyFixture;
tproxyIPv4OnlyNftRules = mkTProxyNftRules tproxyIPv4OnlyFixture;
ipv4OnlyTunConfig = mkTunConfig tproxyIPv4OnlyFixture;
ipv4OnlyPerAppTunUpScript =
generated.readDerivation
tproxyIPv4OnlyFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStartPost;
# XRay's TUN configures IPv6 itself: with it off, its up script must not touch IPv6 addresses.
xrayIPv4OnlyFixture = evalProxySuite [
baseModule
(
{ lib, ... }:
{
networking.enableIPv6 = false;
services.proxy-suite.proxy = {
backend = lib.mkForce "xray";
tun.enable = true;
};
}
)
];
xrayIPv4OnlyTunConfig = mkTunConfig xrayIPv4OnlyFixture;
xrayIPv4OnlyTunUpScript =
generated.readDerivation
xrayIPv4OnlyFixture.config.systemd.services."proxy-suite-tun".serviceConfig.ExecStartPost;
tproxyAutostartFixture = evalProxySuite [
baseModule
{
services.proxy-suite.proxy = {
tproxy.enable = true;
autostart = "tproxy";
};
}
];
tunManualFixture = evalProxySuite [
baseModule
{
services.proxy-suite.proxy.tun.enable = true;
}
];
tunAutostartFixture = evalProxySuite [
baseModule
{
services.proxy-suite.proxy = {
tun.enable = true;
autostart = "tun";
};
}
];
invalidGlobalProxyModeAssertions = mkFailingAssertions mkBadFixture [
# TUN and TProxy can no longer both autostart: proxy.autostart holds one mode.
# Transparent proxy backends require proxy.enable.
[
{
services.proxy-suite.proxy = {
enable = false;
tun.enable = true;
};
}
]
[
{
services.proxy-suite.proxy = {
enable = false;
tproxy.enable = true;
};
}
]
];
tunDefaultConfig = mkTunConfig tunManualFixture;
tunServiceConfig = tunManualFixture.config.systemd.services."proxy-suite-tun".serviceConfig;
tunCleanupScript = generated.readDerivation tunServiceConfig.ExecStopPost;
in
{
inherit
invalidGlobalProxyModeAssertions
tproxyAutostartFixture
tproxyManualFixture
tproxyManualStartScript
tproxyManualStopScript
tproxyManualConfig
tproxyManualNftRules
tproxyIPv4OnlyStartScript
tproxyIPv4OnlyConfig
tproxyIPv4OnlyNftRules
ipv4OnlyTunConfig
ipv4OnlyPerAppTunUpScript
xrayIPv4OnlyTunConfig
xrayIPv4OnlyTunUpScript
tproxyWithFirewall
tunAutostartFixture
tunCleanupScript
tunDefaultConfig
tunManualFixture
tunServiceConfig
;
}