chore: refactoring (split)
This commit is contained in:
84 files changed
+9149
-7244
No files matched your search
+18
-3654
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,82 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
minimal,
|
||||
mkRoutingRules,
|
||||
mkTProxyConfig,
|
||||
hasRuleSet,
|
||||
dnsHasRuleSet,
|
||||
dnsServerByTag,
|
||||
mkBadFixtureRaw,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
let
|
||||
fixtures = import ./core-proxy/fixtures.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
minimal
|
||||
mkRoutingRules
|
||||
mkTProxyConfig
|
||||
mkBadFixtureRaw
|
||||
mkFailingAssertions
|
||||
;
|
||||
};
|
||||
inherit (fixtures)
|
||||
customSingBoxPackageBin
|
||||
customSingBoxPackageStartScript
|
||||
ruDefaultRules
|
||||
ruDefaultConfig
|
||||
ruDisabledRules
|
||||
ruDisabledConfig
|
||||
ruExplicitConfig
|
||||
dnsLocalOverrideConfig
|
||||
dnsRemoteOverrideConfig
|
||||
proxyDirectConfig
|
||||
urlTestCustomStartScript
|
||||
noProxyBackendDefaultFixture
|
||||
invalidCoreProxyAssertions
|
||||
blockGeoRules
|
||||
routingOrDomainRules
|
||||
routingOrGeoIPRules
|
||||
;
|
||||
|
||||
routingDnsChecks = import ./core-proxy/routing-dns.nix {
|
||||
inherit
|
||||
hasRuleSet
|
||||
dnsHasRuleSet
|
||||
dnsServerByTag
|
||||
ruDefaultRules
|
||||
ruDefaultConfig
|
||||
ruDisabledRules
|
||||
ruDisabledConfig
|
||||
ruExplicitConfig
|
||||
dnsLocalOverrideConfig
|
||||
dnsRemoteOverrideConfig
|
||||
blockGeoRules
|
||||
routingOrDomainRules
|
||||
routingOrGeoIPRules
|
||||
;
|
||||
};
|
||||
serviceDefaultChecks = import ./core-proxy/service-defaults.nix {
|
||||
inherit
|
||||
pkgs
|
||||
minimal
|
||||
customSingBoxPackageBin
|
||||
customSingBoxPackageStartScript
|
||||
proxyDirectConfig
|
||||
ruDefaultConfig
|
||||
urlTestCustomStartScript
|
||||
noProxyBackendDefaultFixture
|
||||
invalidCoreProxyAssertions
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit ruDefaultConfig;
|
||||
|
||||
assertions = routingDnsChecks.assertions ++ serviceDefaultChecks.assertions;
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
minimal,
|
||||
mkRoutingRules,
|
||||
mkTProxyConfig,
|
||||
mkBadFixtureRaw,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ../read-generated.nix;
|
||||
|
||||
customSingBoxPackage = pkgs.writeShellScriptBin "sing-box" ''
|
||||
exit 0
|
||||
'';
|
||||
customSingBoxPackageFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.singBox.package = customSingBoxPackage;
|
||||
}
|
||||
];
|
||||
customSingBoxPackageBin = "${builtins.unsafeDiscardStringContext (toString customSingBoxPackage)}/bin/sing-box";
|
||||
customSingBoxPackageStartScript = generated.readDerivation (
|
||||
customSingBoxPackageFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
|
||||
routingOrFixture = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
routing.rules = [
|
||||
{
|
||||
outbound = "primary";
|
||||
domains = [ "example.com" ];
|
||||
geoips = [ "us" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
ruDefaultRules = mkRoutingRules minimal;
|
||||
ruDefaultConfig = mkTProxyConfig minimal;
|
||||
|
||||
ruDisabledFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.routing.enableRuDirect = false;
|
||||
}
|
||||
];
|
||||
ruDisabledRules = mkRoutingRules ruDisabledFixture;
|
||||
ruDisabledConfig = mkTProxyConfig ruDisabledFixture;
|
||||
|
||||
ruExplicitConfig = mkTProxyConfig (evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.routing = {
|
||||
enableRuDirect = false;
|
||||
direct.geosites = [ "category-ru" ];
|
||||
};
|
||||
}
|
||||
]);
|
||||
|
||||
dnsLocalOverrideConfig = mkTProxyConfig (evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.dns.local = {
|
||||
type = "tcp";
|
||||
address = "9.9.9.9";
|
||||
port = 5353;
|
||||
};
|
||||
}
|
||||
]);
|
||||
|
||||
dnsRemoteOverrideConfig = mkTProxyConfig (evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.dns.remote = {
|
||||
type = "tls";
|
||||
address = "1.0.0.1";
|
||||
port = 853;
|
||||
};
|
||||
}
|
||||
]);
|
||||
|
||||
proxyDirectConfig = mkTProxyConfig (evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.proxyByDefault = false;
|
||||
}
|
||||
]);
|
||||
|
||||
urlTestCustomFixture = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "test-proxy";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
selection = "urltest";
|
||||
urlTest = {
|
||||
url = "https://telegram.org";
|
||||
interval = "1m";
|
||||
};
|
||||
singBox.urlTest.tolerance = 100;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
urlTestCustomStartScript = generated.readDerivation (
|
||||
urlTestCustomFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
|
||||
noProxyBackendDefaultFixture = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite.enable = true;
|
||||
}
|
||||
];
|
||||
|
||||
invalidCoreProxyAssertions = mkFailingAssertions mkBadFixtureRaw [
|
||||
[
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
blockGeoRules = mkRoutingRules (evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.routing.block = {
|
||||
geosites = [ "category-ads-all" ];
|
||||
geoips = [ "cn" ];
|
||||
};
|
||||
}
|
||||
]);
|
||||
|
||||
routingOrRules = mkRoutingRules routingOrFixture;
|
||||
|
||||
routingOrDomainRules = builtins.filter (
|
||||
rule: (rule ? domain_suffix) && rule.domain_suffix == [ "example.com" ]
|
||||
) routingOrRules;
|
||||
|
||||
routingOrGeoIPRules = builtins.filter (
|
||||
rule: (rule ? rule_set) && rule.rule_set == [ "geoip-us" ]
|
||||
) routingOrRules;
|
||||
in
|
||||
{
|
||||
inherit
|
||||
customSingBoxPackageBin
|
||||
customSingBoxPackageStartScript
|
||||
ruDefaultRules
|
||||
ruDefaultConfig
|
||||
ruDisabledRules
|
||||
ruDisabledConfig
|
||||
ruExplicitConfig
|
||||
dnsLocalOverrideConfig
|
||||
dnsRemoteOverrideConfig
|
||||
proxyDirectConfig
|
||||
urlTestCustomFixture
|
||||
urlTestCustomStartScript
|
||||
noProxyBackendDefaultFixture
|
||||
invalidCoreProxyAssertions
|
||||
blockGeoRules
|
||||
routingOrDomainRules
|
||||
routingOrGeoIPRules
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
{
|
||||
hasRuleSet,
|
||||
dnsHasRuleSet,
|
||||
dnsServerByTag,
|
||||
ruDefaultRules,
|
||||
ruDefaultConfig,
|
||||
ruDisabledRules,
|
||||
ruDisabledConfig,
|
||||
ruExplicitConfig,
|
||||
dnsLocalOverrideConfig,
|
||||
dnsRemoteOverrideConfig,
|
||||
blockGeoRules,
|
||||
routingOrDomainRules,
|
||||
routingOrGeoIPRules,
|
||||
}:
|
||||
|
||||
{
|
||||
assertions = [
|
||||
# -- routing rule entries with domains and geoips preserve both matchers --
|
||||
(
|
||||
assert builtins.length routingOrDomainRules == 1;
|
||||
true
|
||||
)
|
||||
(
|
||||
assert builtins.length routingOrGeoIPRules == 1;
|
||||
true
|
||||
)
|
||||
(
|
||||
assert (builtins.head routingOrDomainRules).outbound == "proxy";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert (builtins.head routingOrGeoIPRules).outbound == "proxy";
|
||||
true
|
||||
)
|
||||
|
||||
# -- default RU direct route and DNS rules are generated --
|
||||
(
|
||||
let
|
||||
localDns = dnsServerByTag ruDefaultConfig "local";
|
||||
remoteDns = dnsServerByTag ruDefaultConfig "remote";
|
||||
in
|
||||
assert localDns.type == "udp";
|
||||
assert localDns.server == "1.1.1.1";
|
||||
assert localDns.server_port == 53;
|
||||
assert !(localDns ? detour);
|
||||
assert remoteDns.type == "udp";
|
||||
assert remoteDns.server == "1.1.1.1";
|
||||
assert remoteDns.server_port == 53;
|
||||
assert remoteDns.detour == "proxy";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert hasRuleSet ruDefaultRules "direct" "geosite-category-ru";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert hasRuleSet ruDefaultRules "direct" "geoip-ru";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert dnsHasRuleSet ruDefaultConfig.dns.rules "geosite-category-ru";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(hasRuleSet ruDisabledRules "direct" "geosite-category-ru");
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(hasRuleSet ruDisabledRules "direct" "geoip-ru");
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(dnsHasRuleSet ruDisabledConfig.dns.rules "geosite-category-ru");
|
||||
true
|
||||
)
|
||||
(
|
||||
assert dnsHasRuleSet ruExplicitConfig.dns.rules "geosite-category-ru";
|
||||
true
|
||||
)
|
||||
|
||||
# -- DNS overrides map to sing-box server entries --
|
||||
(
|
||||
let
|
||||
localDns = dnsServerByTag dnsLocalOverrideConfig "local";
|
||||
in
|
||||
assert localDns.type == "tcp";
|
||||
assert localDns.server == "9.9.9.9";
|
||||
assert localDns.server_port == 5353;
|
||||
assert !(localDns ? detour);
|
||||
true
|
||||
)
|
||||
(
|
||||
let
|
||||
remoteDns = dnsServerByTag dnsRemoteOverrideConfig "remote";
|
||||
in
|
||||
assert remoteDns.type == "tls";
|
||||
assert remoteDns.server == "1.0.0.1";
|
||||
assert remoteDns.server_port == 853;
|
||||
assert remoteDns.detour == "proxy";
|
||||
true
|
||||
)
|
||||
|
||||
# -- block route geosite and geoip sets are emitted --
|
||||
(
|
||||
assert hasRuleSet blockGeoRules "block" "geosite-category-ads-all";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert hasRuleSet blockGeoRules "block" "geoip-cn";
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
{
|
||||
pkgs,
|
||||
minimal,
|
||||
customSingBoxPackageBin,
|
||||
customSingBoxPackageStartScript,
|
||||
proxyDirectConfig,
|
||||
ruDefaultConfig,
|
||||
urlTestCustomStartScript,
|
||||
noProxyBackendDefaultFixture,
|
||||
invalidCoreProxyAssertions,
|
||||
}:
|
||||
|
||||
{
|
||||
assertions = [
|
||||
# -- sing-box package override propagates into generated service scripts --
|
||||
(
|
||||
assert pkgs.lib.hasInfix customSingBoxPackageBin customSingBoxPackageStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
# -- proxy defaults and urltest settings are applied --
|
||||
(
|
||||
assert proxyDirectConfig.dns.final == "local";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert ruDefaultConfig.dns.final == "remote";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert ruDefaultConfig.route.default_domain_resolver == "local";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert builtins.match ".*telegram\\.org.*" urlTestCustomStartScript != null;
|
||||
assert builtins.match ".*1m.*" urlTestCustomStartScript != null;
|
||||
assert builtins.match ".*100.*" urlTestCustomStartScript != null;
|
||||
true
|
||||
)
|
||||
(
|
||||
let
|
||||
cfg = minimal.config.services.proxy-suite.proxy.urlTest;
|
||||
in
|
||||
assert cfg.url == "https://www.gstatic.com/generate_204";
|
||||
assert cfg.interval == "3m";
|
||||
assert minimal.config.services.proxy-suite.proxy.singBox.urlTest.tolerance == 50;
|
||||
true
|
||||
)
|
||||
|
||||
# -- proxy backend defaults and required inputs are enforced --
|
||||
(
|
||||
assert noProxyBackendDefaultFixture.config.services.proxy-suite.proxy.enable == false;
|
||||
assert !(noProxyBackendDefaultFixture.config.systemd.services ? "proxy-suite-socks");
|
||||
true
|
||||
)
|
||||
]
|
||||
++ invalidCoreProxyAssertions;
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
mkTunConfig,
|
||||
dnsServerByTag,
|
||||
checkConstants,
|
||||
}:
|
||||
|
||||
let
|
||||
fixtures = import ./global-proxy-modes/fixtures.nix {
|
||||
inherit
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
mkTunConfig
|
||||
;
|
||||
};
|
||||
|
||||
inherit (fixtures)
|
||||
invalidGlobalProxyModeAssertions
|
||||
tproxyAutostartFixture
|
||||
tproxyManualFixture
|
||||
tproxyManualStartScript
|
||||
tproxyManualStopScript
|
||||
tproxyWithFirewall
|
||||
tunAutostartFixture
|
||||
tunCleanupScript
|
||||
tunDefaultConfig
|
||||
tunManualFixture
|
||||
tunServiceConfig
|
||||
;
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
(
|
||||
assert tproxyWithFirewall.config.networking.firewall.enable;
|
||||
true
|
||||
)
|
||||
(
|
||||
assert tproxyManualFixture.config.services.proxy-suite.proxy.tproxy.autostart == false;
|
||||
assert tproxyManualFixture.config.systemd.services."proxy-suite-tproxy".wantedBy == [ ];
|
||||
true
|
||||
)
|
||||
(
|
||||
assert
|
||||
tproxyAutostartFixture.config.systemd.services."proxy-suite-tproxy".wantedBy
|
||||
== [ "multi-user.target" ];
|
||||
true
|
||||
)
|
||||
(
|
||||
assert pkgs.lib.hasInfix "set -euo pipefail" tproxyManualStartScript;
|
||||
assert pkgs.lib.hasInfix "rule del fwmark 1 table 100" tproxyManualStartScript;
|
||||
assert pkgs.lib.hasInfix "route replace local default dev lo table 100" tproxyManualStartScript;
|
||||
assert pkgs.lib.hasInfix "set +e" tproxyManualStopScript;
|
||||
assert pkgs.lib.hasInfix "rule del fwmark 1 table 100" tproxyManualStopScript;
|
||||
true
|
||||
)
|
||||
(
|
||||
assert tunManualFixture.config.services.proxy-suite.proxy.tun.autostart == false;
|
||||
assert tunManualFixture.config.systemd.services."proxy-suite-tun".wantedBy == [ ];
|
||||
true
|
||||
)
|
||||
(
|
||||
let
|
||||
inbound = builtins.head (builtins.filter (item: item.tag == "tun-in") tunDefaultConfig.inbounds);
|
||||
in
|
||||
assert inbound.iproute2_table_index == checkConstants.tunAutoRouteTableIndex;
|
||||
assert inbound.iproute2_rule_index == checkConstants.tunAutoRouteRulePriority;
|
||||
assert tunDefaultConfig.route.auto_detect_interface == true;
|
||||
true
|
||||
)
|
||||
(
|
||||
assert tunManualFixture.config.networking.nftables.enable;
|
||||
true
|
||||
)
|
||||
(
|
||||
assert tunServiceConfig.ExecStartPre == tunServiceConfig.ExecStopPost;
|
||||
assert pkgs.lib.hasInfix "delete table inet sing-box" tunCleanupScript;
|
||||
assert pkgs.lib.hasInfix "rule del table ${toString checkConstants.tunAutoRouteTableIndex}"
|
||||
tunCleanupScript;
|
||||
assert pkgs.lib.hasInfix "rule del pref ${toString checkConstants.xrayTunPerAppTproxyRulePriority}"
|
||||
tunCleanupScript;
|
||||
assert pkgs.lib.hasInfix "rule del pref ${toString checkConstants.xrayTunPerAppTunRulePriority}"
|
||||
tunCleanupScript;
|
||||
assert pkgs.lib.hasInfix "route flush table ${toString checkConstants.tunAutoRouteTableIndex}"
|
||||
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" ];
|
||||
true
|
||||
)
|
||||
(
|
||||
let
|
||||
localDns = dnsServerByTag tunDefaultConfig "local";
|
||||
in
|
||||
assert !(localDns ? detour);
|
||||
true
|
||||
)
|
||||
(
|
||||
assert tunDefaultConfig.route.default_domain_resolver == "local";
|
||||
true
|
||||
)
|
||||
(
|
||||
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
|
||||
)
|
||||
]
|
||||
++ invalidGlobalProxyModeAssertions;
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
{
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
mkTunConfig,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ../read-generated.nix;
|
||||
|
||||
tproxyWithFirewall = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
networking.firewall.enable = true;
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
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;
|
||||
|
||||
tproxyAutostartFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.tproxy = {
|
||||
enable = true;
|
||||
autostart = true;
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
tunManualFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.tun.enable = true;
|
||||
}
|
||||
];
|
||||
|
||||
tunAutostartFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.tun = {
|
||||
enable = true;
|
||||
autostart = true;
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
invalidGlobalProxyModeAssertions = mkFailingAssertions mkBadFixture [
|
||||
# TUN and TProxy cannot both autostart globally.
|
||||
[
|
||||
{
|
||||
services.proxy-suite.proxy = {
|
||||
tproxy = {
|
||||
enable = true;
|
||||
autostart = true;
|
||||
};
|
||||
tun = {
|
||||
enable = true;
|
||||
autostart = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
# 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
|
||||
tproxyWithFirewall
|
||||
tunAutostartFixture
|
||||
tunCleanupScript
|
||||
tunDefaultConfig
|
||||
tunManualFixture
|
||||
tunServiceConfig
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
mkTProxyConfig,
|
||||
mkTunConfig,
|
||||
shellValueByPrefix,
|
||||
checkConstants,
|
||||
}:
|
||||
|
||||
let
|
||||
fixtures = import ./hybrid-backend/fixtures.nix {
|
||||
inherit
|
||||
evalProxySuite
|
||||
mkTProxyConfig
|
||||
mkTunConfig
|
||||
shellValueByPrefix
|
||||
;
|
||||
};
|
||||
|
||||
inherit (fixtures)
|
||||
hybridBackendJqFilter
|
||||
hybridFixture
|
||||
hybridPerAppTunStartScript
|
||||
hybridStartScript
|
||||
hybridSubscriptionStartScript
|
||||
hybridSubscriptionUpdateScript
|
||||
hybridTproxyConfig
|
||||
hybridTunConfig
|
||||
hybridTunStartScript
|
||||
hybridXrayRawStartScript
|
||||
;
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
# -- 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
|
||||
);
|
||||
dnsBridgeRouteRule = builtins.head (
|
||||
builtins.filter (
|
||||
rule:
|
||||
(rule.action or "") == "hijack-dns" && (rule ? inbound) && builtins.elem "xray-dns-in" rule.inbound
|
||||
) hybridTproxyConfig.route.rules
|
||||
);
|
||||
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 == checkConstants.xrayDnsBridgePorts.socks;
|
||||
assert mixedInbound.type == "mixed";
|
||||
assert tproxyInbound.type == "tproxy";
|
||||
assert tunDnsBridgeInbound.listen_port == checkConstants.xrayDnsBridgePorts.tun;
|
||||
assert
|
||||
dnsBridgeRouteRule.network == [
|
||||
"tcp"
|
||||
"udp"
|
||||
];
|
||||
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=${toString checkConstants.xraySidecarBasePorts.socks}"
|
||||
hybridStartScript;
|
||||
assert pkgs.lib.hasInfix "XRAY_SIDECAR_DNS_PORT=${toString checkConstants.xrayDnsBridgePorts.socks}"
|
||||
hybridStartScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
"XRAY_SIDECAR_NEXT_PORT=${toString checkConstants.xraySidecarBasePorts.tun}"
|
||||
hybridTunStartScript;
|
||||
assert pkgs.lib.hasInfix "XRAY_SIDECAR_DNS_PORT=${toString checkConstants.xrayDnsBridgePorts.tun}"
|
||||
hybridTunStartScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
"XRAY_SIDECAR_NEXT_PORT=${toString checkConstants.xraySidecarBasePorts.perAppTun}"
|
||||
hybridPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
"XRAY_SIDECAR_DNS_PORT=${toString checkConstants.xrayDnsBridgePorts.perAppTun}"
|
||||
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 "udp:true" hybridXrayRawStartScript;
|
||||
assert pkgs.lib.hasInfix "routing_mark:2" hybridXrayRawStartScript;
|
||||
assert pkgs.lib.hasInfix "sing_box_preserved_rules" hybridBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "xray-dns-in" hybridBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "--backend hybrid" hybridSubscriptionStartScript;
|
||||
assert pkgs.lib.hasInfix "--backend hybrid" hybridSubscriptionUpdateScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
''type == "object" and (.singBox | type == "array") and (.xray | type == "array")''
|
||||
hybridSubscriptionStartScript;
|
||||
assert pkgs.lib.hasInfix ".singBox" hybridSubscriptionStartScript;
|
||||
assert pkgs.lib.hasInfix ".xray[]" hybridSubscriptionStartScript;
|
||||
assert pkgs.lib.hasInfix "_proxy_suite_add_xray_sidecar_ob" hybridSubscriptionStartScript;
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
{
|
||||
evalProxySuite,
|
||||
mkTProxyConfig,
|
||||
mkTunConfig,
|
||||
shellValueByPrefix,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ../read-generated.nix;
|
||||
|
||||
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 = generated.readDerivation (
|
||||
hybridFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
hybridTunStartScript = generated.readDerivation (
|
||||
hybridFixture.config.systemd.services."proxy-suite-tun".serviceConfig.ExecStart
|
||||
);
|
||||
hybridPerAppTunStartScript = generated.readDerivation (
|
||||
hybridFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStart
|
||||
);
|
||||
hybridBackendJqFilter =
|
||||
import ../../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix
|
||||
{
|
||||
pureXrayEnabled = false;
|
||||
selectionMode = hybridFixture.config.services.proxy-suite.proxy.selection;
|
||||
};
|
||||
|
||||
hybridXrayRawFixture = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
xray.enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "raw-xray";
|
||||
xrayJson = {
|
||||
protocol = "freedom";
|
||||
settings = { };
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
hybridXrayRawStartScript = generated.readDerivation (
|
||||
hybridXrayRawFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
|
||||
hybridSubscriptionFixture = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
xray.enable = true;
|
||||
subscriptions = [
|
||||
{
|
||||
tag = "community";
|
||||
url = "https://example.com/hybrid-sub";
|
||||
}
|
||||
];
|
||||
selection = "selector";
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
hybridSubscriptionStartScript = generated.readDerivation (
|
||||
hybridSubscriptionFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
hybridSubscriptionUpdateScript = generated.readDerivation (
|
||||
hybridSubscriptionFixture.config.systemd.services."proxy-suite-subscription-update".serviceConfig.ExecStart
|
||||
);
|
||||
in
|
||||
{
|
||||
inherit
|
||||
hybridBackendJqFilter
|
||||
hybridFixture
|
||||
hybridPerAppTunStartScript
|
||||
hybridStartScript
|
||||
hybridSubscriptionStartScript
|
||||
hybridSubscriptionUpdateScript
|
||||
hybridTproxyConfig
|
||||
hybridTunConfig
|
||||
hybridTunStartScript
|
||||
hybridXrayRawStartScript
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
{
|
||||
pkgs,
|
||||
system,
|
||||
nixpkgs,
|
||||
proxySuiteModule,
|
||||
zapret,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ./read-generated.nix;
|
||||
|
||||
evalProxySuite =
|
||||
modules:
|
||||
import "${nixpkgs}/nixos/lib/eval-config.nix" {
|
||||
inherit system;
|
||||
modules = [ proxySuiteModule ] ++ modules;
|
||||
};
|
||||
forceEval = value: builtins.tryEval (builtins.deepSeq value true);
|
||||
rg = "${pkgs.ripgrep}/bin/rg";
|
||||
mkRouting =
|
||||
fixture:
|
||||
let
|
||||
cfg = fixture.config.services.proxy-suite;
|
||||
in
|
||||
import ../../modules/proxy-suite/rules.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit pkgs cfg zapret;
|
||||
};
|
||||
mkRoutingRules = fixture: (mkRouting fixture).routingRules;
|
||||
mkRouteModeRules = fixture: (mkRouting fixture).routeModeRules;
|
||||
mkProxyConfig =
|
||||
fixture: configAttr:
|
||||
let
|
||||
cfg = fixture.config.services.proxy-suite;
|
||||
rules = mkRouting fixture;
|
||||
configs = import ../../modules/proxy-suite/config.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit pkgs cfg rules;
|
||||
};
|
||||
in
|
||||
builtins.fromJSON (
|
||||
builtins.unsafeDiscardStringContext (generated.readDerivation configs.${configAttr})
|
||||
);
|
||||
mkTProxyConfig = fixture: mkProxyConfig fixture "tproxyFile";
|
||||
mkTunConfig = fixture: mkProxyConfig fixture "tunFile";
|
||||
mkPerAppTunConfig = fixture: mkProxyConfig fixture "perAppTunFile";
|
||||
mkTProxyNftRules =
|
||||
fixture:
|
||||
let
|
||||
cfg = fixture.config.services.proxy-suite;
|
||||
nftr = import ../../modules/proxy-suite/nftables.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit pkgs cfg;
|
||||
};
|
||||
in
|
||||
generated.readDerivation nftr.nftablesRulesFile;
|
||||
mkPerAppZapretNftRules =
|
||||
fixture:
|
||||
let
|
||||
cfg = fixture.config.services.proxy-suite;
|
||||
nftr = import ../../modules/proxy-suite/nftables.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit pkgs cfg;
|
||||
};
|
||||
in
|
||||
generated.readDerivation nftr.perAppZapretRulesFile;
|
||||
mkPerAppUserRules =
|
||||
fixture:
|
||||
let
|
||||
cfg = fixture.config.services.proxy-suite;
|
||||
derived = import ../../modules/proxy-suite/derived.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit cfg;
|
||||
};
|
||||
nftr = import ../../modules/proxy-suite/nftables.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit pkgs cfg;
|
||||
};
|
||||
in
|
||||
import ../../modules/proxy-suite/service/per-app-routing/user-rules.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit pkgs;
|
||||
inherit (derived)
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
;
|
||||
perAppTunSliceName = "proxy-suite-per-app-tun.slice";
|
||||
perAppTproxySliceName = "proxy-suite-per-app-tproxy.slice";
|
||||
perAppZapretSliceName = "proxy-suite-per-app-zapret.slice";
|
||||
inherit (nftr) nft;
|
||||
awk = "${pkgs.gawk}/bin/awk";
|
||||
grepBin = "${pkgs.gnugrep}/bin/grep";
|
||||
findBin = "${pkgs.findutils}/bin/find";
|
||||
headBin = "${pkgs.coreutils}/bin/head";
|
||||
};
|
||||
hasDirectDomain =
|
||||
rules: domain:
|
||||
builtins.any (
|
||||
rule: (rule ? domain_suffix) && rule.outbound == "direct" && builtins.elem domain rule.domain_suffix
|
||||
) rules;
|
||||
hasDirectIP =
|
||||
rules: cidr:
|
||||
builtins.any (
|
||||
rule: (rule ? ip_cidr) && rule.outbound == "direct" && builtins.elem cidr rule.ip_cidr
|
||||
) rules;
|
||||
hasRuleSet =
|
||||
rules: outbound: ruleSet:
|
||||
builtins.any (
|
||||
rule: (rule ? rule_set) && rule.outbound == outbound && builtins.elem ruleSet rule.rule_set
|
||||
) rules;
|
||||
dnsHasRuleSet =
|
||||
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);
|
||||
mkZapretBaseFor =
|
||||
fixture: serviceName:
|
||||
let
|
||||
env = fixture.config.systemd.services.${serviceName}.serviceConfig.Environment;
|
||||
zapretBaseEnv = builtins.head (
|
||||
builtins.filter (value: pkgs.lib.hasPrefix "ZAPRET_BASE=" value) env
|
||||
);
|
||||
in
|
||||
pkgs.lib.removePrefix "ZAPRET_BASE=" zapretBaseEnv;
|
||||
mkZapretBase = fixture: mkZapretBaseFor fixture "zapret-discord-youtube";
|
||||
packagePathMatches =
|
||||
packages: pattern:
|
||||
builtins.any (
|
||||
pkg: builtins.match pattern (builtins.unsafeDiscardStringContext (toString pkg)) != null
|
||||
) packages;
|
||||
packageByPattern =
|
||||
packages: pattern:
|
||||
builtins.head (
|
||||
builtins.filter (
|
||||
pkg: builtins.match pattern (builtins.unsafeDiscardStringContext (toString pkg)) != null
|
||||
) packages
|
||||
);
|
||||
lineByPrefix =
|
||||
text: prefix:
|
||||
builtins.head (
|
||||
builtins.filter (line: pkgs.lib.hasPrefix prefix line) (pkgs.lib.splitString "\n" text)
|
||||
);
|
||||
lineContaining =
|
||||
text: infix:
|
||||
builtins.head (
|
||||
builtins.filter (line: pkgs.lib.hasInfix infix line) (pkgs.lib.splitString "\n" text)
|
||||
);
|
||||
shellValueByPrefix =
|
||||
text: prefix:
|
||||
let
|
||||
value = pkgs.lib.removePrefix prefix (lineByPrefix text prefix);
|
||||
in
|
||||
if pkgs.lib.hasPrefix "'" value && pkgs.lib.hasSuffix "'" value then
|
||||
pkgs.lib.removeSuffix "'" (pkgs.lib.removePrefix "'" value)
|
||||
else if pkgs.lib.hasPrefix "\"" value && pkgs.lib.hasSuffix "\"" value then
|
||||
pkgs.lib.removeSuffix "\"" (pkgs.lib.removePrefix "\"" value)
|
||||
else
|
||||
value;
|
||||
|
||||
baseModule = {
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
mkFixture =
|
||||
proxySuiteConfig:
|
||||
evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = proxySuiteConfig;
|
||||
}
|
||||
];
|
||||
mkBadFixture =
|
||||
modules:
|
||||
forceEval ((evalProxySuite ([ baseModule ] ++ modules)).config.system.build.toplevel.drvPath);
|
||||
mkBadFixtureRaw =
|
||||
modules: forceEval ((evalProxySuite modules).config.system.build.toplevel.drvPath);
|
||||
mkBadProxySuiteFixture =
|
||||
proxySuiteConfig: forceEval ((mkFixture proxySuiteConfig).config.system.build.toplevel.drvPath);
|
||||
mkFailingAssertions =
|
||||
evaluate: cases:
|
||||
map (
|
||||
case:
|
||||
assert (evaluate case).success == false;
|
||||
true
|
||||
) cases;
|
||||
mkProxyCtlDerived =
|
||||
fixture:
|
||||
let
|
||||
proxyCtl = packageByPattern fixture.config.environment.systemPackages ".*/[^/]*proxy-ctl(-[0-9.]+)?$";
|
||||
metadata = proxyCtl.proxySuiteCheck;
|
||||
wrapper = pkgs.lib.concatStringsSep "\n" (
|
||||
pkgs.lib.mapAttrsToList (
|
||||
name: value: "export ${name}=${pkgs.lib.escapeShellArg value}"
|
||||
) metadata.wrapperEnv
|
||||
);
|
||||
in
|
||||
{
|
||||
inherit proxyCtl wrapper;
|
||||
script = wrapper + "\n" + metadata.script;
|
||||
profiles = builtins.fromJSON (generated.readDerivation metadata.perAppRoutingProfilesFile);
|
||||
subscriptionTags = builtins.fromJSON (generated.readDerivation metadata.subscriptionTagsFile);
|
||||
inherit (metadata) proxychainsConfigFile;
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit
|
||||
rg
|
||||
evalProxySuite
|
||||
forceEval
|
||||
mkRouting
|
||||
mkRoutingRules
|
||||
mkRouteModeRules
|
||||
mkTProxyConfig
|
||||
mkTunConfig
|
||||
mkPerAppTunConfig
|
||||
mkTProxyNftRules
|
||||
mkPerAppZapretNftRules
|
||||
mkPerAppUserRules
|
||||
hasDirectDomain
|
||||
hasDirectIP
|
||||
hasRuleSet
|
||||
dnsHasRuleSet
|
||||
dnsServerByTag
|
||||
mkZapretBaseFor
|
||||
mkZapretBase
|
||||
packagePathMatches
|
||||
packageByPattern
|
||||
lineByPrefix
|
||||
lineContaining
|
||||
shellValueByPrefix
|
||||
baseModule
|
||||
mkFixture
|
||||
mkBadFixture
|
||||
mkBadFixtureRaw
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
mkProxyCtlDerived
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkProxyCtlDerived,
|
||||
shellValueByPrefix,
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
ruDefaultConfig,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ./read-generated.nix;
|
||||
|
||||
localProxyAuthFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.auth = {
|
||||
username = "local-user";
|
||||
password = "local-pass";
|
||||
};
|
||||
}
|
||||
];
|
||||
localProxyAuthStartScript = generated.readDerivation (
|
||||
localProxyAuthFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
localProxyAuthBackendJqFilter =
|
||||
import ../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix
|
||||
{
|
||||
pureXrayEnabled = false;
|
||||
selectionMode = localProxyAuthFixture.config.services.proxy-suite.proxy.selection;
|
||||
};
|
||||
|
||||
localProxyAuthPasswordFileFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.auth = {
|
||||
username = "local-user";
|
||||
passwordFile = "/run/secrets/local-proxy-password";
|
||||
};
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
proxychains.enable = true;
|
||||
profiles = [
|
||||
{
|
||||
name = "steam-browser";
|
||||
route = "proxychains";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
_localProxyAuthPasswordFile = mkProxyCtlDerived localProxyAuthPasswordFileFixture;
|
||||
localProxyAuthPasswordFileWrapper = _localProxyAuthPasswordFile.wrapper;
|
||||
localProxyAuthPasswordFileScript = _localProxyAuthPasswordFile.script;
|
||||
localProxyAuthPasswordFileStartScript = generated.readDerivation (
|
||||
localProxyAuthPasswordFileFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
|
||||
invalidLocalProxyAuthAssertions = mkFailingAssertions mkBadFixture [
|
||||
# Auth requires both username and a password source.
|
||||
[
|
||||
{ services.proxy-suite.proxy.auth.username = "local-user"; }
|
||||
]
|
||||
[
|
||||
{ services.proxy-suite.proxy.auth.password = "local-pass"; }
|
||||
]
|
||||
|
||||
# Inline password and passwordFile are mutually exclusive.
|
||||
[
|
||||
{
|
||||
services.proxy-suite.proxy.auth = {
|
||||
username = "local-user";
|
||||
password = "local-pass";
|
||||
passwordFile = "/run/secrets/local-proxy-password";
|
||||
};
|
||||
}
|
||||
]
|
||||
];
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
# Default mixed inbound stays unauthenticated.
|
||||
(
|
||||
let
|
||||
mixedInbound = builtins.head (
|
||||
builtins.filter (inbound: inbound.tag == "mixed-in") ruDefaultConfig.inbounds
|
||||
);
|
||||
in
|
||||
assert !(mixedInbound ? users);
|
||||
true
|
||||
)
|
||||
|
||||
# Authenticated mixed inbound is injected at runtime.
|
||||
(
|
||||
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 password "$LOCAL_PROXY_PASSWORD"'' localProxyAuthStartScript;
|
||||
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
|
||||
)
|
||||
|
||||
# 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 "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 builtins.hasAttr "proxy-suite" localProxyAuthPasswordFileFixture.config.users.groups;
|
||||
assert
|
||||
shellValueByPrefix localProxyAuthPasswordFileWrapper "export PROXYCHAINS_CONFIG="
|
||||
== "/run/proxy-suite-socks/proxychains.conf";
|
||||
assert pkgs.lib.hasInfix "Proxychains config is not readable" localProxyAuthPasswordFileScript;
|
||||
true
|
||||
)
|
||||
|
||||
]
|
||||
++ invalidLocalProxyAuthAssertions;
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
{
|
||||
pkgs,
|
||||
checkLib,
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (checkLib)
|
||||
evalProxySuite
|
||||
mkRoutingRules
|
||||
mkRouteModeRules
|
||||
mkTProxyConfig
|
||||
mkTunConfig
|
||||
mkPerAppTunConfig
|
||||
mkTProxyNftRules
|
||||
mkPerAppZapretNftRules
|
||||
mkPerAppUserRules
|
||||
hasDirectDomain
|
||||
hasDirectIP
|
||||
hasRuleSet
|
||||
dnsHasRuleSet
|
||||
dnsServerByTag
|
||||
mkZapretBaseFor
|
||||
mkZapretBase
|
||||
packagePathMatches
|
||||
packageByPattern
|
||||
shellValueByPrefix
|
||||
baseModule
|
||||
mkBadFixture
|
||||
mkBadFixtureRaw
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
mkProxyCtlDerived
|
||||
;
|
||||
|
||||
minimal = evalProxySuite [ baseModule ];
|
||||
checkConstants =
|
||||
(import ../../modules/proxy-suite/derived.nix {
|
||||
lib = pkgs.lib;
|
||||
cfg = minimal.config.services.proxy-suite;
|
||||
}).constants;
|
||||
_minimalProxyCtl = mkProxyCtlDerived minimal;
|
||||
minimalProxyCtlWrapper = _minimalProxyCtl.wrapper;
|
||||
minimalProxyCtlScript = _minimalProxyCtl.script;
|
||||
minimalSocksService = minimal.config.systemd.services."proxy-suite-socks";
|
||||
|
||||
coreProxyChecks = import ./core-proxy.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
minimal
|
||||
mkRoutingRules
|
||||
mkTProxyConfig
|
||||
hasRuleSet
|
||||
dnsHasRuleSet
|
||||
dnsServerByTag
|
||||
mkBadFixtureRaw
|
||||
mkFailingAssertions
|
||||
;
|
||||
};
|
||||
inherit (coreProxyChecks) ruDefaultConfig;
|
||||
|
||||
routeModeChecks = import ./route-mode.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkRouteModeRules
|
||||
shellValueByPrefix
|
||||
minimalProxyCtlWrapper
|
||||
minimalProxyCtlScript
|
||||
;
|
||||
};
|
||||
|
||||
subscriptionChecks = import ./subscriptions.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkBadFixtureRaw
|
||||
mkFailingAssertions
|
||||
mkProxyCtlDerived
|
||||
minimal
|
||||
;
|
||||
};
|
||||
|
||||
trayChecks = import ./tray.nix {
|
||||
inherit
|
||||
evalProxySuite
|
||||
baseModule
|
||||
packagePathMatches
|
||||
;
|
||||
};
|
||||
|
||||
localProxyAuthChecks = import ./local-proxy-auth.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkProxyCtlDerived
|
||||
shellValueByPrefix
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
ruDefaultConfig
|
||||
;
|
||||
};
|
||||
|
||||
perAppRoutingChecks = import ./per-app-routing.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkProxyCtlDerived
|
||||
mkPerAppUserRules
|
||||
mkPerAppZapretNftRules
|
||||
mkPerAppTunConfig
|
||||
dnsServerByTag
|
||||
mkZapretBase
|
||||
mkZapretBaseFor
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
minimalProxyCtlScript
|
||||
;
|
||||
};
|
||||
|
||||
outboundValidationChecks = import ./outbound-validation.nix {
|
||||
inherit mkBadProxySuiteFixture mkFailingAssertions;
|
||||
};
|
||||
|
||||
globalProxyModeChecks = import ./global-proxy-modes.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
mkTunConfig
|
||||
dnsServerByTag
|
||||
checkConstants
|
||||
;
|
||||
};
|
||||
|
||||
zapretChecks = import ./zapret.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkRoutingRules
|
||||
mkZapretBase
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
hasDirectDomain
|
||||
hasDirectIP
|
||||
;
|
||||
};
|
||||
|
||||
tgWsProxyChecks = import ./tg-ws-proxy.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkRoutingRules
|
||||
mkTProxyNftRules
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
hasDirectIP
|
||||
minimal
|
||||
minimalSocksService
|
||||
;
|
||||
zapretSyncService = zapretChecks.syncService;
|
||||
};
|
||||
|
||||
xrayBackendChecks = import ./xray-backends.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkTProxyConfig
|
||||
mkTunConfig
|
||||
mkPerAppTunConfig
|
||||
shellValueByPrefix
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
dnsServerByTag
|
||||
checkConstants
|
||||
;
|
||||
};
|
||||
|
||||
validated = builtins.all (x: x) (
|
||||
[
|
||||
(
|
||||
assert minimal.config.services.proxy-suite.proxy.listenAddress == "127.0.0.1";
|
||||
true
|
||||
)
|
||||
]
|
||||
++ coreProxyChecks.assertions
|
||||
++ localProxyAuthChecks.assertions
|
||||
++ tgWsProxyChecks.assertions
|
||||
++ xrayBackendChecks.assertions
|
||||
++ outboundValidationChecks.assertions
|
||||
++ zapretChecks.assertions
|
||||
++ globalProxyModeChecks.assertions
|
||||
++ trayChecks.assertions
|
||||
++ subscriptionChecks.assertions
|
||||
++ routeModeChecks.assertions
|
||||
++ perAppRoutingChecks.assertions
|
||||
);
|
||||
in
|
||||
{
|
||||
proxy-suite-module = builtins.seq validated (pkgs.writeText "proxy-suite-module-check" "ok");
|
||||
xray-jq-filter-runtime = xrayBackendChecks.runtime;
|
||||
per-app-zapret-runtime = perAppRoutingChecks.runtime;
|
||||
zapret-hostlist-rules = zapretChecks.rules;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
{
|
||||
mkBadProxySuiteFixture,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
{
|
||||
assertions = mkFailingAssertions mkBadProxySuiteFixture [
|
||||
# Outbound tags must be unique.
|
||||
{
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "dup";
|
||||
url = "http://one.example.com:8080";
|
||||
}
|
||||
{
|
||||
tag = "dup";
|
||||
url = "http://two.example.com:8080";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
# Built-in outbound names are reserved.
|
||||
{
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "proxy";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
# Explicit routing rules must target an existing outbound.
|
||||
{
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
routing.rules = [
|
||||
{
|
||||
outbound = "missing";
|
||||
domains = [ "example.com" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkProxyCtlDerived,
|
||||
minimalProxyCtlScript,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ./read-generated.nix;
|
||||
|
||||
perAppRoutingProxychainsFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.perAppRouting = {
|
||||
enable = true;
|
||||
proxychains.enable = true;
|
||||
profiles = [
|
||||
{
|
||||
name = "steam-browser";
|
||||
route = "proxychains";
|
||||
}
|
||||
{
|
||||
name = "native-direct";
|
||||
route = "direct";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
];
|
||||
perAppRoutingProxychains = mkProxyCtlDerived perAppRoutingProxychainsFixture;
|
||||
perAppRoutingProxychainsWrapper = perAppRoutingProxychains.wrapper;
|
||||
perAppRoutingProxychainsScript = perAppRoutingProxychains.script;
|
||||
perAppRoutingProxychainsProfiles = perAppRoutingProxychains.profiles;
|
||||
perAppRoutingProxychainsConfig = generated.readDerivation perAppRoutingProxychains.proxychainsConfigFile;
|
||||
|
||||
perAppRoutingDefaultProfilesFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
proxychains.enable = true;
|
||||
};
|
||||
}
|
||||
];
|
||||
perAppRoutingDefaultProfiles = (mkProxyCtlDerived perAppRoutingDefaultProfilesFixture).profiles;
|
||||
|
||||
perAppRoutingNoDefaultProfilesFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy = {
|
||||
tun.perApp.enable = true;
|
||||
tproxy.perApp.enable = true;
|
||||
};
|
||||
zapret = {
|
||||
enable = true;
|
||||
perApp.enable = true;
|
||||
};
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = false;
|
||||
proxychains.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
perAppRoutingNoDefaultProfiles = (mkProxyCtlDerived perAppRoutingNoDefaultProfilesFixture).profiles;
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
# -- perAppRouting: proxychains/direct profile config is accepted --
|
||||
(
|
||||
assert perAppRoutingProxychainsFixture.config.services.proxy-suite.perAppRouting.enable;
|
||||
true
|
||||
)
|
||||
(
|
||||
assert
|
||||
builtins.length perAppRoutingProxychainsFixture.config.services.proxy-suite.perAppRouting.profiles
|
||||
== 2;
|
||||
true
|
||||
)
|
||||
(
|
||||
assert builtins.length perAppRoutingProxychainsProfiles == 2;
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: createDefaultProfiles injects curated proxychains profile --
|
||||
(
|
||||
assert builtins.length perAppRoutingDefaultProfiles == 1;
|
||||
assert (builtins.head perAppRoutingDefaultProfiles).name == "proxychains";
|
||||
assert (builtins.head perAppRoutingDefaultProfiles).route == "proxychains";
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: createDefaultProfiles = false injects no curated profiles --
|
||||
(
|
||||
assert builtins.length perAppRoutingNoDefaultProfiles == 0;
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: proxy-ctl script embeds wrap/apps commands --
|
||||
(
|
||||
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 "wrap <profile> -- <cmd>" perAppRoutingProxychainsScript;
|
||||
assert pkgs.lib.hasInfix "apps" perAppRoutingProxychainsScript;
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: proxychains config is quiet and points at local SOCKS listener --
|
||||
(
|
||||
assert pkgs.lib.hasInfix "quiet_mode" perAppRoutingProxychainsConfig;
|
||||
assert pkgs.lib.hasInfix "proxy_dns" perAppRoutingProxychainsConfig;
|
||||
assert pkgs.lib.hasInfix "socks5 127.0.0.1 1080" perAppRoutingProxychainsConfig;
|
||||
true
|
||||
)
|
||||
|
||||
# -- proxy-ctl: restart skips services that are not present in zapret-only or tg-only builds --
|
||||
(
|
||||
assert pkgs.lib.hasInfix "if _svc_exists proxy-suite-socks; then" minimalProxyCtlScript;
|
||||
assert pkgs.lib.hasInfix "_svc_exists \"$svc\" && _svc_active \"$svc\"" minimalProxyCtlScript;
|
||||
assert pkgs.lib.hasInfix "proxy-suite-tg-ws-proxy" minimalProxyCtlScript;
|
||||
true
|
||||
)
|
||||
|
||||
# -- 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;
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkProxyCtlDerived,
|
||||
mkPerAppUserRules,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ./read-generated.nix;
|
||||
|
||||
perAppRoutingTproxyFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tproxy.perApp.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
perAppRoutingTproxy = mkProxyCtlDerived perAppRoutingTproxyFixture;
|
||||
perAppRoutingTproxyScript = perAppRoutingTproxy.script;
|
||||
perAppRoutingTproxyProfiles = perAppRoutingTproxy.profiles;
|
||||
perAppRoutingTproxyServiceConfig =
|
||||
perAppRoutingTproxyFixture.config.systemd.services."proxy-suite-per-app-tproxy".serviceConfig;
|
||||
perAppRoutingTproxyStartScript = generated.readDerivation perAppRoutingTproxyServiceConfig.ExecStart;
|
||||
perAppRoutingTproxyStopScript = generated.readDerivation perAppRoutingTproxyServiceConfig.ExecStop;
|
||||
perAppRoutingTproxyUserStartScript = generated.readDerivation (
|
||||
(mkPerAppUserRules perAppRoutingTproxyFixture).perAppTproxyUserRuleStart
|
||||
);
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
# -- 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;
|
||||
true
|
||||
)
|
||||
|
||||
# -- 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" "$profile" "$PER_APP_ROUTING_TPROXY_ENABLED"''
|
||||
perAppRoutingTproxyScript;
|
||||
assert pkgs.lib.hasInfix "$slice_base-\${profile}-$$" perAppRoutingTproxyScript;
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: app TProxy service and helper units are created --
|
||||
(
|
||||
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";
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: app TProxy helper installs socket cgroup mark rules --
|
||||
(
|
||||
assert pkgs.lib.hasInfix "socket cgroupv2" perAppRoutingTproxyUserStartScript;
|
||||
assert pkgs.lib.hasInfix "meta mark set" perAppRoutingTproxyUserStartScript;
|
||||
assert pkgs.lib.hasInfix "ct mark set" perAppRoutingTproxyUserStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: app TProxy startup installs nftables and loopback policy route --
|
||||
(
|
||||
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 "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;
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkProxyCtlDerived,
|
||||
mkPerAppUserRules,
|
||||
mkPerAppTunConfig,
|
||||
dnsServerByTag,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ./read-generated.nix;
|
||||
|
||||
perAppRoutingTunFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tun.perApp.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
perAppRoutingTun = mkProxyCtlDerived perAppRoutingTunFixture;
|
||||
perAppRoutingTunScript = perAppRoutingTun.script;
|
||||
perAppRoutingTunProfiles = perAppRoutingTun.profiles;
|
||||
perAppRoutingTunServiceConfig =
|
||||
perAppRoutingTunFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig;
|
||||
perAppRoutingTunStartScript = generated.readDerivation perAppRoutingTunServiceConfig.ExecStart;
|
||||
perAppRoutingTunUpScript = generated.readDerivation perAppRoutingTunServiceConfig.ExecStartPost;
|
||||
perAppRoutingTunCleanupScript = generated.readDerivation perAppRoutingTunServiceConfig.ExecStopPost;
|
||||
perAppRoutingTunConfig = mkPerAppTunConfig perAppRoutingTunFixture;
|
||||
perAppRoutingTunDirectOutbound = builtins.head (
|
||||
builtins.filter (item: item.tag == "direct") perAppRoutingTunConfig.outbounds
|
||||
);
|
||||
perAppRoutingTunUserStartScript = generated.readDerivation (
|
||||
(mkPerAppUserRules perAppRoutingTunFixture).perAppTunUserRuleStart
|
||||
);
|
||||
|
||||
perAppRoutingTunWithTproxyFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy = {
|
||||
tproxy.enable = true;
|
||||
tun.perApp.enable = true;
|
||||
};
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
perAppRoutingTunWithTproxyStartScript =
|
||||
generated.readDerivation
|
||||
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
|
||||
);
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
# -- 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;
|
||||
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 "_check_no_global_proxy tun" perAppRoutingTunScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
''_wrap_slice "proxy-suite-per-app-tun" "$profile" "$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;
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: user mark script installs fwmark + conntrack mark rules --
|
||||
(
|
||||
assert pkgs.lib.hasInfix "meta mark set" perAppRoutingTunUserStartScript;
|
||||
assert pkgs.lib.hasInfix "ct mark set" perAppRoutingTunUserStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
# -- 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
|
||||
);
|
||||
in
|
||||
assert inbound.interface_name == "psperapptun0";
|
||||
assert inbound.address == [ "172.20.0.1/30" ];
|
||||
assert inbound.auto_route == false;
|
||||
assert inbound.auto_redirect == false;
|
||||
assert inbound.strict_route == false;
|
||||
assert !(inbound ? iproute2_table_index);
|
||||
assert !(inbound ? iproute2_rule_index);
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: app TUN local DNS keeps direct path without explicit detour --
|
||||
(
|
||||
let
|
||||
localDns = dnsServerByTag perAppRoutingTunConfig "local";
|
||||
in
|
||||
assert !(localDns ? detour);
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: app TUN uses local domain resolver and avoids global auto-routing --
|
||||
(
|
||||
assert perAppRoutingTunConfig.route.default_domain_resolver == "local";
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: app TUN does not set outbound routing marks when TProxy is disabled --
|
||||
(
|
||||
assert builtins.match ".*--routing-mark.*" perAppRoutingTunStartScript == null;
|
||||
assert !(perAppRoutingTunDirectOutbound ? routing_mark);
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: app TUN applies outbound routing marks when TProxy is enabled --
|
||||
(
|
||||
let
|
||||
expectedMark = perAppRoutingTunWithTproxyFixture.config.services.proxy-suite.proxy.tproxy.proxyMark;
|
||||
in
|
||||
assert builtins.match ".*--routing-mark.*" perAppRoutingTunWithTproxyStartScript != null;
|
||||
assert perAppRoutingTunWithTproxyDirectOutbound.routing_mark == expectedMark;
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: app TUN service and helper units are created --
|
||||
(
|
||||
assert perAppRoutingTunFixture.config.systemd.services ? "proxy-suite-per-app-tun";
|
||||
assert perAppRoutingTunFixture.config.systemd.services ? "proxy-suite-per-app-tun-user@";
|
||||
assert perAppRoutingTunFixture.config.systemd.user.services ? "proxy-suite-per-app-tun-anchor";
|
||||
assert perAppRoutingTunServiceConfig.ExecStartPre == perAppRoutingTunServiceConfig.ExecStopPost;
|
||||
assert !(pkgs.lib.hasInfix "-6 addr replace" perAppRoutingTunUpScript);
|
||||
assert !(pkgs.lib.hasInfix "-6 route replace" perAppRoutingTunUpScript);
|
||||
assert !(pkgs.lib.hasInfix "-6 rule add" perAppRoutingTunUpScript);
|
||||
assert pkgs.lib.hasInfix "link del dev" perAppRoutingTunCleanupScript;
|
||||
assert pkgs.lib.hasInfix "psperapptun0" perAppRoutingTunCleanupScript;
|
||||
assert pkgs.lib.hasInfix "rule del fwmark 16 table 101" perAppRoutingTunCleanupScript;
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: app TUN enables nftables and user control group --
|
||||
(
|
||||
assert perAppRoutingTunFixture.config.networking.nftables.enable;
|
||||
assert perAppRoutingTunFixture.config.users.groups ? "proxy-suite";
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
{
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
{
|
||||
assertions = mkFailingAssertions mkBadFixture [
|
||||
# route=proxychains requires proxychains.enable.
|
||||
[
|
||||
{
|
||||
services.proxy-suite.perAppRouting = {
|
||||
enable = true;
|
||||
profiles = [
|
||||
{
|
||||
name = "steam-browser";
|
||||
route = "proxychains";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
# proxychains requires proxy.enable.
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.enable = false;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
proxychains.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
# profiles require perAppRouting.enable.
|
||||
[
|
||||
{ services.proxy-suite.perAppRouting.profiles = [ { name = "oops"; } ]; }
|
||||
]
|
||||
|
||||
# default proxychains profile still requires proxychains.enable.
|
||||
[
|
||||
{
|
||||
services.proxy-suite.perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
# route=tun requires proxy.tun.perApp.enable.
|
||||
[
|
||||
{
|
||||
services.proxy-suite.perAppRouting = {
|
||||
enable = true;
|
||||
profiles = [
|
||||
{
|
||||
name = "game";
|
||||
route = "tun";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
# app TUN backend requires proxy.enable.
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy = {
|
||||
enable = false;
|
||||
tun.perApp.enable = true;
|
||||
};
|
||||
perAppRouting.enable = true;
|
||||
};
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.enable = false;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
profiles = [
|
||||
{
|
||||
name = "game";
|
||||
route = "tun";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
# route=tproxy requires proxy.tproxy.perApp.enable.
|
||||
[
|
||||
{
|
||||
services.proxy-suite.perAppRouting = {
|
||||
enable = true;
|
||||
profiles = [
|
||||
{
|
||||
name = "browser";
|
||||
route = "tproxy";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
# app TProxy backend requires proxy.enable.
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy = {
|
||||
enable = false;
|
||||
tproxy.perApp.enable = true;
|
||||
};
|
||||
perAppRouting.enable = true;
|
||||
};
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.enable = false;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
profiles = [
|
||||
{
|
||||
name = "browser";
|
||||
route = "tproxy";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
# route=zapret requires zapret.perApp.enable.
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
zapret.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
profiles = [
|
||||
{
|
||||
name = "yt";
|
||||
route = "zapret";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
# profile names must be unique.
|
||||
[
|
||||
{
|
||||
services.proxy-suite.perAppRouting = {
|
||||
enable = true;
|
||||
profiles = [
|
||||
{ name = "dup"; }
|
||||
{ name = "dup"; }
|
||||
];
|
||||
};
|
||||
}
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
{
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
{
|
||||
assertions = mkFailingAssertions mkBadFixture [
|
||||
# app TUN fwmark must not collide with global TProxy proxyMark.
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tproxy.proxyMark = 7;
|
||||
proxy.tun.perApp = {
|
||||
enable = true;
|
||||
fwmark = 7;
|
||||
};
|
||||
perAppRouting.enable = true;
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
# app TProxy fwmark must not collide with global TProxy proxyMark.
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tproxy = {
|
||||
proxyMark = 8;
|
||||
perApp = {
|
||||
enable = true;
|
||||
fwmark = 8;
|
||||
};
|
||||
};
|
||||
perAppRouting.enable = true;
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
# app TUN and TProxy backends must use distinct marks and route tables.
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tun.perApp = {
|
||||
enable = true;
|
||||
fwmark = 11;
|
||||
};
|
||||
proxy.tproxy.perApp = {
|
||||
enable = true;
|
||||
fwmark = 11;
|
||||
};
|
||||
perAppRouting.enable = true;
|
||||
};
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tun.perApp = {
|
||||
enable = true;
|
||||
routeTable = 100;
|
||||
};
|
||||
proxy.tproxy.perApp = {
|
||||
enable = true;
|
||||
routeTable = 100;
|
||||
};
|
||||
perAppRouting.enable = true;
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
# per-app zapret marks must not collide with TUN/TProxy marks.
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tun.perApp = {
|
||||
enable = true;
|
||||
fwmark = 12;
|
||||
};
|
||||
zapret.perApp = {
|
||||
enable = true;
|
||||
filterMark = 12;
|
||||
};
|
||||
perAppRouting.enable = true;
|
||||
};
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tproxy.perApp = {
|
||||
enable = true;
|
||||
fwmark = 13;
|
||||
};
|
||||
zapret.perApp = {
|
||||
enable = true;
|
||||
filterMark = 13;
|
||||
};
|
||||
perAppRouting.enable = true;
|
||||
};
|
||||
}
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
let
|
||||
profileChecks = import ./per-app-routing-validation-profiles.nix {
|
||||
inherit mkBadFixture mkFailingAssertions;
|
||||
};
|
||||
resourceChecks = import ./per-app-routing-validation-resources.nix {
|
||||
inherit mkBadFixture mkFailingAssertions;
|
||||
};
|
||||
in
|
||||
{
|
||||
assertions = profileChecks.assertions ++ resourceChecks.assertions;
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkProxyCtlDerived,
|
||||
mkPerAppUserRules,
|
||||
mkPerAppZapretNftRules,
|
||||
mkZapretBase,
|
||||
mkZapretBaseFor,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ./read-generated.nix;
|
||||
|
||||
perAppRoutingZapretFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
zapret = {
|
||||
enable = true;
|
||||
perApp.enable = true;
|
||||
};
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
proxychains.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
perAppRoutingZapret = mkProxyCtlDerived perAppRoutingZapretFixture;
|
||||
perAppRoutingZapretScript = perAppRoutingZapret.script;
|
||||
perAppRoutingZapretProfiles = perAppRoutingZapret.profiles;
|
||||
perAppRoutingZapretStartScript = mkPerAppZapretNftRules perAppRoutingZapretFixture;
|
||||
perAppRoutingZapretUserStartScript = generated.readDerivation (
|
||||
(mkPerAppUserRules perAppRoutingZapretFixture).perAppZapretUserRuleStart
|
||||
);
|
||||
perAppRoutingZapretService =
|
||||
perAppRoutingZapretFixture.config.systemd.services."proxy-suite-per-app-zapret";
|
||||
perAppRoutingZapretBase = mkZapretBase perAppRoutingZapretFixture;
|
||||
perAppRoutingPerAppZapretBase = mkZapretBaseFor perAppRoutingZapretFixture "proxy-suite-per-app-zapret";
|
||||
|
||||
perAppRoutingZapretWithoutGlobalFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
zapret = {
|
||||
enable = false;
|
||||
perApp.enable = true;
|
||||
};
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
proxychains.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
perAppRoutingZapretWithoutGlobal = mkProxyCtlDerived perAppRoutingZapretWithoutGlobalFixture;
|
||||
perAppRoutingZapretWithoutGlobalProfiles = perAppRoutingZapretWithoutGlobal.profiles;
|
||||
perAppRoutingZapretWithoutGlobalPerAppBase = mkZapretBaseFor perAppRoutingZapretWithoutGlobalFixture "proxy-suite-per-app-zapret";
|
||||
|
||||
runtime = pkgs.runCommand "proxy-suite-per-app-zapret-runtime-check" { } ''
|
||||
global_config=${perAppRoutingZapretBase}/config
|
||||
per_app_config=${perAppRoutingPerAppZapretBase}/config
|
||||
per_app_only_config=${perAppRoutingZapretWithoutGlobalPerAppBase}/config
|
||||
custom_script=${perAppRoutingZapretBase}/init.d/sysv/custom.d/50-proxy-suite-custom.sh
|
||||
|
||||
grep -F 'FILTER_MARK=' "$global_config"
|
||||
! grep -F 'FILTER_MARK=0x10000000' "$global_config"
|
||||
|
||||
grep -F 'FILTER_MARK=0x10000000' "$per_app_config"
|
||||
grep -F 'MODE_FILTER=none' "$per_app_config"
|
||||
grep -F 'QNUM=201' "$per_app_config"
|
||||
grep -F 'DESYNC_MARK=0x8000000' "$per_app_config"
|
||||
grep -F 'DESYNC_MARK_POSTNAT=0x4000000' "$per_app_config"
|
||||
grep -F 'ZAPRET_NFT_TABLE=proxy_suite_per_app_zapret' "$per_app_config"
|
||||
|
||||
grep -F 'FILTER_MARK=0x10000000' "$per_app_only_config"
|
||||
grep -F 'QNUM=201' "$per_app_only_config"
|
||||
|
||||
grep -F 'proxy-suite per-app-zapret bypass' "$custom_script"
|
||||
grep -F 'mark and 268435456 != 0 return' "$custom_script"
|
||||
|
||||
touch "$out"
|
||||
'';
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
# -- 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;
|
||||
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" "$profile" "$PER_APP_ROUTING_ZAPRET_ENABLED"''
|
||||
perAppRoutingZapretScript;
|
||||
assert pkgs.lib.hasInfix "$slice_base-\${profile}-$$" perAppRoutingZapretScript;
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: app zapret service and helper units are created --
|
||||
(
|
||||
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 builtins.elem "network-online.target" perAppRoutingZapretService.after;
|
||||
assert builtins.elem "network-online.target" perAppRoutingZapretService.wants;
|
||||
true
|
||||
)
|
||||
|
||||
# -- 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 builtins.length perAppRoutingZapretWithoutGlobalProfiles == 2;
|
||||
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
|
||||
)
|
||||
|
||||
# -- perAppRouting: app zapret helper installs socket cgroup bitwise mark rules --
|
||||
(
|
||||
assert pkgs.lib.hasInfix "socket cgroupv2" perAppRoutingZapretUserStartScript;
|
||||
assert pkgs.lib.hasInfix "meta mark set meta mark or 268435456" perAppRoutingZapretUserStartScript;
|
||||
assert pkgs.lib.hasInfix "ct mark set ct mark or 268435456" perAppRoutingZapretUserStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
# -- perAppRouting: app zapret startup installs nftables backend --
|
||||
(
|
||||
assert pkgs.lib.hasInfix "proxy_suite_per_app_zapret_mark" perAppRoutingZapretStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
];
|
||||
|
||||
inherit runtime;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkProxyCtlDerived,
|
||||
mkPerAppUserRules,
|
||||
mkPerAppZapretNftRules,
|
||||
mkPerAppTunConfig,
|
||||
dnsServerByTag,
|
||||
mkZapretBase,
|
||||
mkZapretBaseFor,
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
minimalProxyCtlScript,
|
||||
}:
|
||||
|
||||
let
|
||||
tunChecks = import ./per-app-routing-tun.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkProxyCtlDerived
|
||||
mkPerAppUserRules
|
||||
mkPerAppTunConfig
|
||||
dnsServerByTag
|
||||
;
|
||||
};
|
||||
tproxyChecks = import ./per-app-routing-tproxy.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkProxyCtlDerived
|
||||
mkPerAppUserRules
|
||||
;
|
||||
};
|
||||
zapretChecks = import ./per-app-routing-zapret.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkProxyCtlDerived
|
||||
mkPerAppUserRules
|
||||
mkPerAppZapretNftRules
|
||||
mkZapretBase
|
||||
mkZapretBaseFor
|
||||
;
|
||||
};
|
||||
validationChecks = import ./per-app-routing-validation.nix {
|
||||
inherit mkBadFixture mkFailingAssertions;
|
||||
};
|
||||
userControlChecks = import ./user-control.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
;
|
||||
};
|
||||
proxychainsChecks = import ./per-app-routing-proxychains.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkProxyCtlDerived
|
||||
minimalProxyCtlScript
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
assertions =
|
||||
tunChecks.assertions
|
||||
++ tproxyChecks.assertions
|
||||
++ zapretChecks.assertions
|
||||
++ proxychainsChecks.assertions
|
||||
++ userControlChecks.assertions
|
||||
++ validationChecks.assertions;
|
||||
|
||||
runtime = zapretChecks.runtime;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
# Inspect writeText/writeShellScript output without import-from-derivation.
|
||||
{
|
||||
readDerivation =
|
||||
derivation:
|
||||
if derivation ? drvAttrs && derivation.drvAttrs ? text then
|
||||
derivation.drvAttrs.text
|
||||
else
|
||||
throw "proxy-suite checks: expected a writeText/writeShellScript derivation";
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkRouteModeRules,
|
||||
shellValueByPrefix,
|
||||
minimalProxyCtlWrapper,
|
||||
minimalProxyCtlScript,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ./read-generated.nix;
|
||||
|
||||
routeModeFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.routing = {
|
||||
proxy = {
|
||||
domains = [ "proxy.example" ];
|
||||
geosites = [ "google" ];
|
||||
};
|
||||
direct.domains = [ "direct.example" ];
|
||||
block.domains = [ "block.example" ];
|
||||
rules = [
|
||||
{
|
||||
outbound = "direct";
|
||||
domains = [ "custom-direct.example" ];
|
||||
}
|
||||
{
|
||||
outbound = "primary";
|
||||
domains = [ "custom-proxy.example" ];
|
||||
}
|
||||
{
|
||||
outbound = "block";
|
||||
domains = [ "custom-block.example" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
];
|
||||
routeModeStartScript = generated.readDerivation (
|
||||
routeModeFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
routeModeBackendJqFilter =
|
||||
import ../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix
|
||||
{
|
||||
pureXrayEnabled = false;
|
||||
selectionMode = routeModeFixture.config.services.proxy-suite.proxy.selection;
|
||||
};
|
||||
routeModeSetterScript = generated.readDerivation (
|
||||
(import ../../modules/proxy-suite/service/control-scripts.nix {
|
||||
inherit pkgs;
|
||||
lib = pkgs.lib;
|
||||
proxyCfg = routeModeFixture.config.services.proxy-suite.proxy;
|
||||
routeModeStateFile = "/run/proxy-suite/route-mode";
|
||||
subscriptionCacheDir = "/var/lib/proxy-suite/subscriptions/sing-box";
|
||||
subscriptionCacheHelpersBlock = "";
|
||||
mkSubscriptionFetchBlock = _: "";
|
||||
}).setRouteModeScript
|
||||
);
|
||||
routeModeRules = mkRouteModeRules routeModeFixture;
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
# 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 DEFAULT_ROUTE_MODE=" == "blacklist";
|
||||
true
|
||||
)
|
||||
|
||||
# proxy-ctl help/status exposes default plus the explicit route 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;
|
||||
true
|
||||
)
|
||||
|
||||
# The socks start script includes every override branch and uses volatile state.
|
||||
(
|
||||
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 = (sing_box_preserved_rules + $route_rules)"
|
||||
routeModeBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix ".dns.rules = []" routeModeBackendJqFilter;
|
||||
true
|
||||
)
|
||||
|
||||
# Grouped routing metadata preserves custom rule categories and order.
|
||||
(
|
||||
assert builtins.length routeModeRules.custom == 3;
|
||||
assert (builtins.elemAt routeModeRules.custom 0).category == "direct";
|
||||
assert (builtins.elemAt routeModeRules.custom 1).category == "proxy";
|
||||
assert (builtins.elemAt routeModeRules.custom 2).category == "block";
|
||||
true
|
||||
)
|
||||
|
||||
# Setter unit is present and writes into /run.
|
||||
(
|
||||
let
|
||||
setterSvc = routeModeFixture.config.systemd.services."proxy-suite-route-mode@";
|
||||
in
|
||||
assert !(setterSvc.serviceConfig ? RuntimeDirectory);
|
||||
assert pkgs.lib.hasInfix "/run/proxy-suite/route-mode" routeModeSetterScript;
|
||||
assert pkgs.lib.hasInfix "default)" routeModeSetterScript;
|
||||
assert pkgs.lib.hasInfix "all-proxy)" routeModeSetterScript;
|
||||
assert pkgs.lib.hasInfix "all-bypass)" routeModeSetterScript;
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
mkProxyCtlDerived,
|
||||
minimal,
|
||||
}:
|
||||
|
||||
let
|
||||
fixtures = import ./subscriptions-runtime/fixtures.nix {
|
||||
inherit
|
||||
evalProxySuite
|
||||
mkProxyCtlDerived
|
||||
;
|
||||
};
|
||||
inherit (fixtures)
|
||||
subscriptionOnlyFixture
|
||||
subscriptionOnlyScript
|
||||
subscriptionOnlyTags
|
||||
subscriptionOnlyStartScript
|
||||
subscriptionOnlyUpdateScript
|
||||
subscriptionWithStaticFixture
|
||||
subscriptionWithStaticStartScript
|
||||
subscriptionFirstSelectionFixture
|
||||
subscriptionFirstSelectionStartScript
|
||||
subscriptionPerAppTunUpdateScript
|
||||
;
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
# Basic config is accepted.
|
||||
(
|
||||
assert subscriptionOnlyFixture.config.services.proxy-suite.proxy.subscriptions != [ ];
|
||||
true
|
||||
)
|
||||
|
||||
# Wrapper exposes tags through a JSON file, not shell word splitting.
|
||||
(
|
||||
assert subscriptionOnlyTags == [ "community" ];
|
||||
assert pkgs.lib.hasInfix "export SUB_TAGS_FILE=" subscriptionOnlyScript;
|
||||
assert !(pkgs.lib.hasInfix "SUB_TAGS_RAW" subscriptionOnlyScript);
|
||||
true
|
||||
)
|
||||
|
||||
# Update service and timer are created when subscriptions are configured.
|
||||
(
|
||||
assert subscriptionOnlyFixture.config.systemd.services ? "proxy-suite-subscription-update";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert subscriptionOnlyFixture.config.systemd.timers ? "proxy-suite-subscription-update";
|
||||
true
|
||||
)
|
||||
|
||||
# StateDirectory is set on the socks service.
|
||||
(
|
||||
assert
|
||||
subscriptionOnlyFixture.config.systemd.services."proxy-suite-socks".serviceConfig.StateDirectory
|
||||
== "proxy-suite";
|
||||
true
|
||||
)
|
||||
|
||||
# Custom update interval flows through to the timer.
|
||||
(
|
||||
assert
|
||||
subscriptionWithStaticFixture.config.systemd.timers."proxy-suite-subscription-update".timerConfig.OnUnitActiveSec
|
||||
== "6h";
|
||||
true
|
||||
)
|
||||
|
||||
# selection=first renames the first subscription outbound to "proxy".
|
||||
(
|
||||
assert builtins.match ".*proxy.*" subscriptionFirstSelectionStartScript != null;
|
||||
true
|
||||
)
|
||||
|
||||
# Runtime parser imports are available in socks and update scripts.
|
||||
(
|
||||
assert
|
||||
builtins.match ".*PYTHONPATH=.*build-outbound\\.py.*" subscriptionWithStaticStartScript != null;
|
||||
true
|
||||
)
|
||||
(
|
||||
assert
|
||||
builtins.match ".*PYTHONPATH=.*fetch-subscription\\.py.*" subscriptionOnlyUpdateScript != null;
|
||||
true
|
||||
)
|
||||
|
||||
# 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 "subscriptions/'community'.json" subscriptionOnlyStartScript);
|
||||
assert !(pkgs.lib.hasInfix "subscriptions/'community'.json" subscriptionOnlyUpdateScript);
|
||||
true
|
||||
)
|
||||
|
||||
# Invalid cache files are ignored and refreshed.
|
||||
(
|
||||
assert pkgs.lib.hasInfix "_proxy_suite_valid_subscription_cache()" subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix "_proxy_suite_drop_invalid_subscription_cache" subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix "removed invalid subscription cache" subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix "produced an invalid cache" subscriptionOnlyUpdateScript;
|
||||
true
|
||||
)
|
||||
|
||||
# Refresh restarts only active sing-box units, including per-app TUN when present.
|
||||
(
|
||||
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
|
||||
)
|
||||
(
|
||||
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
|
||||
)
|
||||
|
||||
# No update service or timer exists without subscriptions.
|
||||
(
|
||||
assert !(minimal.config.systemd.services ? "proxy-suite-subscription-update");
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(minimal.config.systemd.timers ? "proxy-suite-subscription-update");
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
{
|
||||
evalProxySuite,
|
||||
mkProxyCtlDerived,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ../read-generated.nix;
|
||||
|
||||
subscriptionOnlyFixture = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
subscriptions = [
|
||||
{
|
||||
tag = "community";
|
||||
url = "https://example.com/sub/token";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
subscriptionOnlyProxyCtl = mkProxyCtlDerived subscriptionOnlyFixture;
|
||||
subscriptionOnlyScript = subscriptionOnlyProxyCtl.script;
|
||||
subscriptionOnlyTags = subscriptionOnlyProxyCtl.subscriptionTags;
|
||||
subscriptionOnlyStartScript =
|
||||
generated.readDerivation
|
||||
subscriptionOnlyFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart;
|
||||
subscriptionOnlyUpdateScript =
|
||||
generated.readDerivation
|
||||
subscriptionOnlyFixture.config.systemd.services."proxy-suite-subscription-update".serviceConfig.ExecStart;
|
||||
|
||||
subscriptionWithStaticFixture = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "own-vps";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
subscriptions = [
|
||||
{
|
||||
tag = "backup";
|
||||
url = "https://example.com/sub/token";
|
||||
}
|
||||
];
|
||||
selection = "urltest";
|
||||
subscriptionUpdateInterval = "6h";
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
subscriptionWithStaticStartScript = generated.readDerivation (
|
||||
subscriptionWithStaticFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
|
||||
subscriptionFirstSelectionFixture = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
subscriptions = [
|
||||
{
|
||||
tag = "community";
|
||||
url = "https://example.com/sub/token";
|
||||
}
|
||||
];
|
||||
selection = "first";
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
subscriptionFirstSelectionStartScript = generated.readDerivation (
|
||||
subscriptionFirstSelectionFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
|
||||
subscriptionPerAppTunFixture = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
subscriptions = [
|
||||
{
|
||||
tag = "community";
|
||||
url = "https://example.com/sub/token";
|
||||
}
|
||||
];
|
||||
tun.perApp.enable = true;
|
||||
};
|
||||
perAppRouting.enable = true;
|
||||
};
|
||||
}
|
||||
];
|
||||
subscriptionPerAppTunUpdateScript = generated.readDerivation (
|
||||
subscriptionPerAppTunFixture.config.systemd.services."proxy-suite-subscription-update".serviceConfig.ExecStart
|
||||
);
|
||||
in
|
||||
{
|
||||
inherit
|
||||
subscriptionOnlyFixture
|
||||
subscriptionOnlyScript
|
||||
subscriptionOnlyTags
|
||||
subscriptionOnlyStartScript
|
||||
subscriptionOnlyUpdateScript
|
||||
subscriptionWithStaticFixture
|
||||
subscriptionWithStaticStartScript
|
||||
subscriptionFirstSelectionFixture
|
||||
subscriptionFirstSelectionStartScript
|
||||
subscriptionPerAppTunUpdateScript
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
{
|
||||
evalProxySuite,
|
||||
mkBadFixtureRaw,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
let
|
||||
proxyWithSubscriptions =
|
||||
subscriptions:
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
inherit subscriptions;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
subscriptionUrlFileFixture = evalProxySuite [
|
||||
(proxyWithSubscriptions [
|
||||
{
|
||||
tag = "private";
|
||||
urlFile = "/run/secrets/sub-url";
|
||||
}
|
||||
])
|
||||
];
|
||||
in
|
||||
{
|
||||
assertions =
|
||||
(mkFailingAssertions mkBadFixtureRaw [
|
||||
# Tags are cache keys and tag prefixes, so duplicates are invalid.
|
||||
[
|
||||
(proxyWithSubscriptions [
|
||||
{
|
||||
tag = "dup";
|
||||
url = "https://example.com/sub/one";
|
||||
}
|
||||
{
|
||||
tag = "dup";
|
||||
url = "https://example.com/sub/two";
|
||||
}
|
||||
])
|
||||
]
|
||||
|
||||
# Tags must be safe for generated names.
|
||||
[
|
||||
(proxyWithSubscriptions [
|
||||
{
|
||||
tag = "bad/tag";
|
||||
url = "https://example.com/sub/token";
|
||||
}
|
||||
])
|
||||
]
|
||||
|
||||
# A subscription source must be either url or urlFile, not both.
|
||||
[
|
||||
(proxyWithSubscriptions [
|
||||
{
|
||||
tag = "bad";
|
||||
url = "https://example.com/sub/token";
|
||||
urlFile = "/run/secrets/sub-url";
|
||||
}
|
||||
])
|
||||
]
|
||||
|
||||
# A subscription with no source is invalid.
|
||||
[
|
||||
(proxyWithSubscriptions [ { tag = "bad"; } ])
|
||||
]
|
||||
])
|
||||
++ [
|
||||
# urlFile form is accepted.
|
||||
(
|
||||
assert subscriptionUrlFileFixture.config.services.proxy-suite.proxy.subscriptions != [ ];
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
mkBadFixtureRaw,
|
||||
mkFailingAssertions,
|
||||
mkProxyCtlDerived,
|
||||
minimal,
|
||||
}:
|
||||
|
||||
let
|
||||
runtimeChecks = import ./subscriptions-runtime.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkProxyCtlDerived
|
||||
minimal
|
||||
;
|
||||
};
|
||||
validationChecks = import ./subscriptions-validation.nix {
|
||||
inherit
|
||||
evalProxySuite
|
||||
mkBadFixtureRaw
|
||||
mkFailingAssertions
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
assertions = runtimeChecks.assertions ++ validationChecks.assertions;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkRoutingRules,
|
||||
mkTProxyNftRules,
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
hasDirectIP,
|
||||
minimal,
|
||||
minimalSocksService,
|
||||
zapretSyncService,
|
||||
}:
|
||||
|
||||
let
|
||||
fixtures = import ./tg-ws-proxy/fixtures.nix {
|
||||
inherit
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkRoutingRules
|
||||
mkTProxyNftRules
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
;
|
||||
};
|
||||
inherit (fixtures)
|
||||
tgSecretFile
|
||||
tgSecretFileService
|
||||
tgAllOptionsStartScript
|
||||
tgWithGlobalTunServiceConfig
|
||||
tgWithGlobalTunBypassUp
|
||||
tgWithGlobalTunBypassDown
|
||||
tgWithGlobalTunRules
|
||||
tgWithGlobalTproxyNft
|
||||
invalidTgWsProxyAssertions
|
||||
;
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
(
|
||||
assert tgSecretFile.config.services.proxy-suite.tgWsProxy.host == "127.0.0.1";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert minimal.config.services.proxy-suite.tgWsProxy.host == "127.0.0.1";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert minimal.config.services.proxy-suite.tgWsProxy.dcIps == { };
|
||||
true
|
||||
)
|
||||
|
||||
# Upstream runtime flags are exposed as typed module options.
|
||||
(
|
||||
assert pkgs.lib.hasInfix "--port=2443" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--host=0.0.0.0" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--secret-file=\"$CREDENTIALS_DIRECTORY/tg_ws_proxy_secret\""
|
||||
tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--verbose" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--log-file=/var/log/tg-ws-proxy.log" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--log-max-mb=2.500000" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--log-backups=3" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--buf-kb=512" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--pool-size=8" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--cfproxy-domain=cdn.example.com" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--cfproxy-domain=edge.example.net" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--cfproxy-worker-domain=worker.example.com" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--no-cfproxy" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--fake-tls-domain=mask.example.com" tgAllOptionsStartScript;
|
||||
assert pkgs.lib.hasInfix "--proxy-protocol" tgAllOptionsStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
(
|
||||
assert
|
||||
tgSecretFile.config.systemd.services."proxy-suite-tg-ws-proxy".serviceConfig.LoadCredential
|
||||
== [ "tg_ws_proxy_secret:/run/secrets/tg-ws-proxy" ];
|
||||
true
|
||||
)
|
||||
|
||||
# Global TUN/TProxy bypass mark keeps relay traffic out of transparent capture.
|
||||
(
|
||||
assert tgWithGlobalTunServiceConfig.SocketMark == "4";
|
||||
assert pkgs.lib.hasInfix "rule add pref 8999 fwmark 4 lookup main" tgWithGlobalTunBypassUp;
|
||||
assert pkgs.lib.hasInfix "rule del pref 8999 fwmark 4 lookup main" tgWithGlobalTunBypassDown;
|
||||
assert hasDirectIP tgWithGlobalTunRules "149.154.167.220";
|
||||
assert pkgs.lib.hasInfix "meta mark 4 return" tgWithGlobalTproxyNft;
|
||||
true
|
||||
)
|
||||
|
||||
# Network-sensitive global services wait for network-online.
|
||||
(
|
||||
assert builtins.elem "network-online.target" minimalSocksService.after;
|
||||
assert builtins.elem "network-online.target" minimalSocksService.wants;
|
||||
assert builtins.elem "network-online.target" tgSecretFileService.after;
|
||||
assert builtins.elem "network-online.target" tgSecretFileService.wants;
|
||||
assert builtins.elem "network-online.target" zapretSyncService.after;
|
||||
assert builtins.elem "network-online.target" zapretSyncService.wants;
|
||||
true
|
||||
)
|
||||
]
|
||||
++ invalidTgWsProxyAssertions;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
{
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkRoutingRules,
|
||||
mkTProxyNftRules,
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ../read-generated.nix;
|
||||
|
||||
tgSecretFile = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.tgWsProxy = {
|
||||
enable = true;
|
||||
host = "127.0.0.1";
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
};
|
||||
}
|
||||
];
|
||||
tgSecretFileService = tgSecretFile.config.systemd.services."proxy-suite-tg-ws-proxy";
|
||||
|
||||
tgAllOptions = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.tgWsProxy = {
|
||||
enable = true;
|
||||
port = 2443;
|
||||
host = "0.0.0.0";
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
verbose = true;
|
||||
logFile = "/var/log/tg-ws-proxy.log";
|
||||
logMaxMb = 2.5;
|
||||
logBackups = 3;
|
||||
bufKb = 512;
|
||||
poolSize = 8;
|
||||
cfProxyDomains = [
|
||||
"cdn.example.com"
|
||||
"edge.example.net"
|
||||
];
|
||||
cfProxyWorkerDomains = [ "worker.example.com" ];
|
||||
cfProxyFallback = false;
|
||||
fakeTlsDomain = "mask.example.com";
|
||||
proxyProtocol = true;
|
||||
};
|
||||
}
|
||||
];
|
||||
tgAllOptionsStartScript = generated.readDerivation (
|
||||
tgAllOptions.config.systemd.services."proxy-suite-tg-ws-proxy".serviceConfig.ExecStart
|
||||
);
|
||||
|
||||
tgWithGlobalTun = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tun.enable = true;
|
||||
tgWsProxy = {
|
||||
enable = true;
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
dcIps."2" = "149.154.167.220";
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
tgWithGlobalTunServiceConfig =
|
||||
tgWithGlobalTun.config.systemd.services."proxy-suite-tg-ws-proxy".serviceConfig;
|
||||
tgWithGlobalTunBypassUp = generated.readDerivation tgWithGlobalTunServiceConfig.ExecStartPre;
|
||||
tgWithGlobalTunBypassDown = generated.readDerivation tgWithGlobalTunServiceConfig.ExecStopPost;
|
||||
tgWithGlobalTunRules = mkRoutingRules tgWithGlobalTun;
|
||||
|
||||
tgWithGlobalTproxy = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tproxy.enable = true;
|
||||
tgWsProxy = {
|
||||
enable = true;
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
tgWithGlobalTproxyNft = mkTProxyNftRules tgWithGlobalTproxy;
|
||||
|
||||
invalidTgWsProxyAssertions = mkFailingAssertions mkBadFixture [
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tproxy.enable = true;
|
||||
tgWsProxy = {
|
||||
enable = true;
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
routingMark = 1;
|
||||
};
|
||||
};
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
services.proxy-suite.tgWsProxy = {
|
||||
enable = true;
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
bufKb = 3;
|
||||
};
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
services.proxy-suite.tgWsProxy = {
|
||||
enable = true;
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
poolSize = -1;
|
||||
};
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
services.proxy-suite.tgWsProxy = {
|
||||
enable = true;
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
logBackups = 0;
|
||||
};
|
||||
}
|
||||
]
|
||||
];
|
||||
in
|
||||
{
|
||||
inherit
|
||||
tgSecretFile
|
||||
tgSecretFileService
|
||||
tgAllOptionsStartScript
|
||||
tgWithGlobalTunServiceConfig
|
||||
tgWithGlobalTunBypassUp
|
||||
tgWithGlobalTunBypassDown
|
||||
tgWithGlobalTunRules
|
||||
tgWithGlobalTproxyNft
|
||||
invalidTgWsProxyAssertions
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
{
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
packagePathMatches,
|
||||
}:
|
||||
|
||||
let
|
||||
trayAutostartFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.tray.enable = true;
|
||||
}
|
||||
];
|
||||
|
||||
trayManualFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.tray = {
|
||||
enable = true;
|
||||
autostart = false;
|
||||
};
|
||||
}
|
||||
];
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
(
|
||||
assert packagePathMatches trayAutostartFixture.config.environment.systemPackages
|
||||
".*/[^/]*proxy-suite-tray(-[0-9.]+)?$";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert packagePathMatches trayAutostartFixture.config.environment.systemPackages
|
||||
".*/[^/]*proxy-suite-tray\\.desktop$";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert
|
||||
builtins.match ".*/share/xdg/autostart/proxy-suite-tray\\.desktop$" (
|
||||
builtins.unsafeDiscardStringContext
|
||||
trayAutostartFixture.config.environment.etc."xdg/autostart/proxy-suite-tray.desktop".source
|
||||
) != null;
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(trayManualFixture.config.environment.etc ? "xdg/autostart/proxy-suite-tray.desktop");
|
||||
true
|
||||
)
|
||||
(
|
||||
assert packagePathMatches trayManualFixture.config.environment.systemPackages
|
||||
".*/[^/]*proxy-suite-tray\\.desktop$";
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
}:
|
||||
|
||||
let
|
||||
userControlDefaultFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tun.perApp.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
userControlDefaultPolkitConfig = userControlDefaultFixture.config.security.polkit.extraConfig;
|
||||
|
||||
userControlGlobalOnlyFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.userControl = {
|
||||
global.enable = true;
|
||||
perApp.enable = false;
|
||||
};
|
||||
}
|
||||
];
|
||||
userControlGlobalOnlyPolkitConfig = userControlGlobalOnlyFixture.config.security.polkit.extraConfig;
|
||||
|
||||
userControlPerAppOnlyFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tun.perApp.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
};
|
||||
userControl = {
|
||||
global.enable = false;
|
||||
perApp.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
userControlPerAppOnlyPolkitConfig = userControlPerAppOnlyFixture.config.security.polkit.extraConfig;
|
||||
|
||||
userControlDisabledFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.userControl = {
|
||||
global.enable = false;
|
||||
perApp.enable = false;
|
||||
};
|
||||
}
|
||||
];
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
# -- 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"
|
||||
userControlDefaultPolkitConfig;
|
||||
assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-\") === 0" userControlDefaultPolkitConfig;
|
||||
assert pkgs.lib.hasInfix "unit.indexOf(\"proxy-suite-per-app-\") !== 0"
|
||||
userControlDefaultPolkitConfig;
|
||||
assert pkgs.lib.hasInfix "unit === \"zapret-discord-youtube.service\""
|
||||
userControlDefaultPolkitConfig;
|
||||
true
|
||||
)
|
||||
|
||||
# -- userControl: global-only rule excludes per-app units --
|
||||
(
|
||||
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;
|
||||
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;
|
||||
true
|
||||
)
|
||||
|
||||
# -- userControl: disabling both scopes removes group and polkit wiring --
|
||||
(
|
||||
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;
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
mkTProxyConfig,
|
||||
mkBadProxySuiteFixture,
|
||||
mkFailingAssertions,
|
||||
dnsServerByTag,
|
||||
}:
|
||||
|
||||
let
|
||||
fixtures = import ./xray-backend-features/fixtures.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkTProxyConfig
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
;
|
||||
};
|
||||
inherit (fixtures)
|
||||
xraySubscriptionStartScript
|
||||
xrayRawStreamOutbound
|
||||
xrayDnsTcpConfig
|
||||
invalidXrayFeatureAssertions
|
||||
;
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
(
|
||||
assert pkgs.lib.hasInfix ''CACHE_FILE="/var/lib/proxy-suite/subscriptions/xray/xray-sub.json"''
|
||||
xraySubscriptionStartScript;
|
||||
assert pkgs.lib.hasInfix "--backend xray" xraySubscriptionStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
# -- xray backend: raw stream settings and DNS encoding are preserved --
|
||||
(
|
||||
let
|
||||
localDns = dnsServerByTag xrayDnsTcpConfig "local";
|
||||
in
|
||||
assert xrayRawStreamOutbound.tag == "proxy";
|
||||
assert xrayRawStreamOutbound.streamSettings.network == "ws";
|
||||
assert xrayRawStreamOutbound.streamSettings.security == "tls";
|
||||
assert xrayRawStreamOutbound.streamSettings.tlsSettings.serverName == "cdn.example.com";
|
||||
assert xrayRawStreamOutbound.streamSettings.wsSettings.path == "/ws";
|
||||
assert xrayRawStreamOutbound.streamSettings.sockopt.tcpFastOpen == true;
|
||||
assert xrayRawStreamOutbound.streamSettings.sockopt.mark == 2;
|
||||
assert localDns.address == "tcp://9.9.9.9";
|
||||
assert localDns.port == 5353;
|
||||
assert localDns.queryStrategy == "UseIP";
|
||||
true
|
||||
)
|
||||
]
|
||||
++ invalidXrayFeatureAssertions;
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
mkTProxyConfig,
|
||||
mkBadProxySuiteFixture,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ../read-generated.nix;
|
||||
rawOutboundJson =
|
||||
(import ../../../modules/proxy-suite/service/script-blocks/outbounds.nix {
|
||||
lib = pkgs.lib;
|
||||
inherit pkgs;
|
||||
pureXrayEnabled = true;
|
||||
singBoxCfg = null;
|
||||
proxyCfg = null;
|
||||
hybridEnabled = null;
|
||||
collapseNamedOutbounds = null;
|
||||
selectionMode = null;
|
||||
backend = null;
|
||||
backendArg = null;
|
||||
xraySidecarRoutingMark = null;
|
||||
jq = null;
|
||||
python3 = null;
|
||||
parserScriptsPythonPath = null;
|
||||
buildOutboundPy = null;
|
||||
mkSubscriptionBlock = null;
|
||||
}).rawOutboundJson;
|
||||
|
||||
xrayRawStreamDefinition = {
|
||||
tag = "raw-stream";
|
||||
xrayJson = {
|
||||
protocol = "vless";
|
||||
settings = {
|
||||
address = "example.com";
|
||||
port = 443;
|
||||
id = "00000000-0000-0000-0000-000000000000";
|
||||
encryption = "none";
|
||||
};
|
||||
streamSettings = {
|
||||
network = "ws";
|
||||
security = "tls";
|
||||
tlsSettings.serverName = "cdn.example.com";
|
||||
wsSettings.path = "/ws";
|
||||
sockopt.tcpFastOpen = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
xraySubscriptionFixture = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
subscriptions = [
|
||||
{
|
||||
tag = "xray-sub";
|
||||
url = "https://example.com/xray-sub";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
xraySubscriptionStartScript = generated.readDerivation (
|
||||
xraySubscriptionFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
|
||||
xrayRawStreamFixture = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
outbounds = [ xrayRawStreamDefinition ];
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
xrayRawStreamOutbound =
|
||||
rawOutboundJson (builtins.head xrayRawStreamFixture.config.services.proxy-suite.proxy.outbounds)
|
||||
"proxy"
|
||||
2;
|
||||
|
||||
xrayDnsTcpConfig = mkTProxyConfig (evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
dns.local = {
|
||||
type = "tcp";
|
||||
address = "9.9.9.9";
|
||||
port = 5353;
|
||||
};
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
]);
|
||||
|
||||
invalidXrayFeatureAssertions = mkFailingAssertions mkBadProxySuiteFixture [
|
||||
{
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
dns.remote = {
|
||||
type = "tls";
|
||||
address = "1.1.1.1";
|
||||
port = 853;
|
||||
};
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
{
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
{
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
selection = "selector";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
url = "http://proxy.example.com:8080";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
{
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "raw";
|
||||
singBoxJson = {
|
||||
type = "direct";
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
{
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "raw";
|
||||
xrayJson = {
|
||||
protocol = "freedom";
|
||||
settings = { };
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
];
|
||||
in
|
||||
{
|
||||
inherit
|
||||
xraySubscriptionStartScript
|
||||
xrayRawStreamOutbound
|
||||
xrayDnsTcpConfig
|
||||
invalidXrayFeatureAssertions
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
mkTProxyConfig,
|
||||
mkTunConfig,
|
||||
mkPerAppTunConfig,
|
||||
shellValueByPrefix,
|
||||
checkConstants,
|
||||
}:
|
||||
|
||||
let
|
||||
fixtures = import ./xray-backend-runtime/fixtures.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkTProxyConfig
|
||||
mkTunConfig
|
||||
mkPerAppTunConfig
|
||||
shellValueByPrefix
|
||||
;
|
||||
};
|
||||
|
||||
inherit (fixtures)
|
||||
xrayBackendJqFilter
|
||||
xrayBackendJqFilterFile
|
||||
xrayDnsLocalClient
|
||||
xrayDnsRemoteClient
|
||||
xrayFixture
|
||||
xrayPerAppTunBackendJqFilterFile
|
||||
xrayPerAppTunCleanupScript
|
||||
xrayPerAppTunConfig
|
||||
xrayPerAppTunConfigJson
|
||||
xrayPerAppTunStartScript
|
||||
xrayPerAppTunUpScript
|
||||
xrayStartBackendJqFilterFile
|
||||
xrayStartScript
|
||||
xrayTproxyConfig
|
||||
xrayTunBackendJqFilterFile
|
||||
xrayTunConfig
|
||||
xrayTunConfigJson
|
||||
xrayTunStartScript
|
||||
xrayTunUpScript
|
||||
;
|
||||
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"
|
||||
|
||||
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 xrayBackendJqFilterFile} \
|
||||
"$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
|
||||
}
|
||||
|
||||
check_runtime global ${pkgs.lib.escapeShellArg xrayTunConfigJson}
|
||||
check_runtime per-app ${pkgs.lib.escapeShellArg xrayPerAppTunConfigJson}
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
serviceShapeChecks = import ./xray-backend-runtime/service-shape.nix {
|
||||
inherit
|
||||
pkgs
|
||||
xrayFixture
|
||||
xrayTproxyConfig
|
||||
xrayStartScript
|
||||
;
|
||||
};
|
||||
tunChecks = import ./xray-backend-runtime/tun.nix {
|
||||
inherit
|
||||
pkgs
|
||||
checkConstants
|
||||
xrayTunConfig
|
||||
xrayPerAppTunConfig
|
||||
xrayStartBackendJqFilterFile
|
||||
xrayTunBackendJqFilterFile
|
||||
xrayPerAppTunBackendJqFilterFile
|
||||
xrayStartScript
|
||||
xrayTunStartScript
|
||||
xrayTunUpScript
|
||||
xrayPerAppTunStartScript
|
||||
xrayPerAppTunUpScript
|
||||
xrayPerAppTunCleanupScript
|
||||
xrayBackendJqFilter
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
runtime = xrayJqFilterRuntimeCheck;
|
||||
|
||||
assertions = serviceShapeChecks.assertions ++ tunChecks.assertions;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
mkTProxyConfig,
|
||||
mkTunConfig,
|
||||
mkPerAppTunConfig,
|
||||
shellValueByPrefix,
|
||||
}:
|
||||
|
||||
let
|
||||
generated = import ../read-generated.nix;
|
||||
|
||||
xrayModule = {
|
||||
system.stateVersion = "26.05";
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
selection = "urltest";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
url = "vless://uuid@example.com:443?type=xhttp&security=tls&sni=cdn.example.com&host=cdn.example.com&path=%2Fx";
|
||||
routing.domains = [ "specific.example" ];
|
||||
}
|
||||
];
|
||||
routing = {
|
||||
proxy.domains = [ "proxy.example" ];
|
||||
direct = {
|
||||
domains = [ "direct.example" ];
|
||||
geosites = [ "category-ru" ];
|
||||
};
|
||||
block.domains = [ "block.example" ];
|
||||
};
|
||||
tproxy.enable = true;
|
||||
tproxy.perApp.enable = true;
|
||||
tun = {
|
||||
enable = true;
|
||||
perApp.enable = true;
|
||||
};
|
||||
};
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
xrayFixture = evalProxySuite [ xrayModule ];
|
||||
xrayTproxyConfig = mkTProxyConfig xrayFixture;
|
||||
xrayTunConfig = mkTunConfig xrayFixture;
|
||||
xrayPerAppTunConfig = mkPerAppTunConfig xrayFixture;
|
||||
xrayStartScript = generated.readDerivation (
|
||||
xrayFixture.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
xrayTunStartScript = generated.readDerivation (
|
||||
xrayFixture.config.systemd.services."proxy-suite-tun".serviceConfig.ExecStart
|
||||
);
|
||||
xrayTunUpScript = generated.readDerivation (
|
||||
xrayFixture.config.systemd.services."proxy-suite-tun".serviceConfig.ExecStartPost
|
||||
);
|
||||
xrayPerAppTunStartScript = generated.readDerivation (
|
||||
xrayFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStart
|
||||
);
|
||||
xrayPerAppTunUpScript = generated.readDerivation (
|
||||
xrayFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStartPost
|
||||
);
|
||||
xrayPerAppTunCleanupScript = generated.readDerivation (
|
||||
xrayFixture.config.systemd.services."proxy-suite-per-app-tun".serviceConfig.ExecStopPost
|
||||
);
|
||||
xrayStartBackendJqFilterFile = builtins.unsafeDiscardStringContext (
|
||||
shellValueByPrefix xrayStartScript "BACKEND_JQ_FILTER="
|
||||
);
|
||||
xrayTunBackendJqFilterFile = builtins.unsafeDiscardStringContext (
|
||||
shellValueByPrefix xrayTunStartScript "BACKEND_JQ_FILTER="
|
||||
);
|
||||
xrayPerAppTunBackendJqFilterFile = builtins.unsafeDiscardStringContext (
|
||||
shellValueByPrefix xrayPerAppTunStartScript "BACKEND_JQ_FILTER="
|
||||
);
|
||||
xrayBackendJqFilter =
|
||||
import ../../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix
|
||||
{
|
||||
pureXrayEnabled = true;
|
||||
selectionMode = xrayFixture.config.services.proxy-suite.proxy.selection;
|
||||
};
|
||||
xrayBackendJqFilterFile = pkgs.writeText "proxy-suite-xray-backend-filter-check.jq" xrayBackendJqFilter;
|
||||
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
|
||||
);
|
||||
in
|
||||
{
|
||||
inherit
|
||||
xrayBackendJqFilter
|
||||
xrayBackendJqFilterFile
|
||||
xrayDnsLocalClient
|
||||
xrayDnsRemoteClient
|
||||
xrayFixture
|
||||
xrayPerAppTunBackendJqFilterFile
|
||||
xrayPerAppTunCleanupScript
|
||||
xrayPerAppTunConfig
|
||||
xrayPerAppTunConfigJson
|
||||
xrayPerAppTunStartScript
|
||||
xrayPerAppTunUpScript
|
||||
xrayStartBackendJqFilterFile
|
||||
xrayStartScript
|
||||
xrayTproxyConfig
|
||||
xrayTunBackendJqFilterFile
|
||||
xrayTunConfig
|
||||
xrayTunConfigJson
|
||||
xrayTunStartScript
|
||||
xrayTunUpScript
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
pkgs,
|
||||
xrayFixture,
|
||||
xrayTproxyConfig,
|
||||
xrayStartScript,
|
||||
}:
|
||||
|
||||
{
|
||||
assertions = [
|
||||
# -- xray backend: same service surface, XRay config shape, and urltest balancer --
|
||||
(
|
||||
let
|
||||
socksInbound = builtins.head (
|
||||
builtins.filter (inbound: inbound.tag == "mixed-in") xrayTproxyConfig.inbounds
|
||||
);
|
||||
tproxyInbound = builtins.head (
|
||||
builtins.filter (inbound: inbound.tag == "tproxy-in") xrayTproxyConfig.inbounds
|
||||
);
|
||||
specificRule = builtins.head (
|
||||
builtins.filter (
|
||||
rule: (rule ? domain) && builtins.elem "domain:specific.example" rule.domain
|
||||
) xrayTproxyConfig.routing.rules
|
||||
);
|
||||
balancer = builtins.head xrayTproxyConfig.routing.balancers;
|
||||
in
|
||||
assert xrayFixture.config.services.proxy-suite.proxy.xray.enable;
|
||||
assert xrayFixture.config.systemd.services ? "proxy-suite-socks";
|
||||
assert xrayFixture.config.systemd.services ? "proxy-suite-tproxy";
|
||||
assert xrayFixture.config.systemd.services ? "proxy-suite-tun";
|
||||
assert xrayFixture.config.systemd.services ? "proxy-suite-per-app-tun";
|
||||
assert pkgs.lib.hasInfix "/bin/xray run -c" xrayStartScript;
|
||||
assert pkgs.lib.hasInfix "--backend xray" xrayStartScript;
|
||||
assert socksInbound.protocol == "socks";
|
||||
assert socksInbound.settings.auth == "noauth";
|
||||
assert socksInbound.settings.udp == true;
|
||||
assert tproxyInbound.protocol == "tunnel";
|
||||
assert tproxyInbound.settings.followRedirect == true;
|
||||
assert tproxyInbound.streamSettings.sockopt.tproxy == "tproxy";
|
||||
assert specificRule.outboundTag == "proxy-suite-ob-primary";
|
||||
assert specificRule.ruleTag == "custom-proxy-domain";
|
||||
assert balancer.tag == "proxy";
|
||||
assert balancer.selector == [ "proxy-suite-ob-" ];
|
||||
assert balancer.strategy.type == "leastPing";
|
||||
assert xrayTproxyConfig.observatory.subjectSelector == [ "proxy-suite-ob-" ];
|
||||
assert xrayTproxyConfig.observatory.probeUrl == "https://www.gstatic.com/generate_204";
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
{
|
||||
pkgs,
|
||||
checkConstants,
|
||||
xrayTunConfig,
|
||||
xrayPerAppTunConfig,
|
||||
xrayStartBackendJqFilterFile,
|
||||
xrayTunBackendJqFilterFile,
|
||||
xrayPerAppTunBackendJqFilterFile,
|
||||
xrayStartScript,
|
||||
xrayTunStartScript,
|
||||
xrayTunUpScript,
|
||||
xrayPerAppTunStartScript,
|
||||
xrayPerAppTunUpScript,
|
||||
xrayPerAppTunCleanupScript,
|
||||
xrayBackendJqFilter,
|
||||
}:
|
||||
|
||||
let
|
||||
backendFilterChecks = import ./tun/backend-filter.nix {
|
||||
inherit
|
||||
pkgs
|
||||
xrayStartBackendJqFilterFile
|
||||
xrayTunBackendJqFilterFile
|
||||
xrayPerAppTunBackendJqFilterFile
|
||||
xrayStartScript
|
||||
xrayBackendJqFilter
|
||||
;
|
||||
};
|
||||
|
||||
globalTunChecks = import ./tun/global.nix {
|
||||
inherit
|
||||
pkgs
|
||||
checkConstants
|
||||
xrayTunConfig
|
||||
xrayTunStartScript
|
||||
xrayTunUpScript
|
||||
;
|
||||
};
|
||||
|
||||
perAppTunChecks = import ./tun/per-app.nix {
|
||||
inherit
|
||||
pkgs
|
||||
checkConstants
|
||||
xrayPerAppTunConfig
|
||||
xrayPerAppTunStartScript
|
||||
xrayPerAppTunUpScript
|
||||
xrayPerAppTunCleanupScript
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
assertions =
|
||||
backendFilterChecks.assertions ++ globalTunChecks.assertions ++ perAppTunChecks.assertions;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
pkgs,
|
||||
xrayStartBackendJqFilterFile,
|
||||
xrayTunBackendJqFilterFile,
|
||||
xrayPerAppTunBackendJqFilterFile,
|
||||
xrayStartScript,
|
||||
xrayBackendJqFilter,
|
||||
}:
|
||||
|
||||
{
|
||||
assertions = [
|
||||
# -- xray backend: shared backend jq filter --
|
||||
(
|
||||
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 "xray_preserved_rules" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "dns-upstream-direct" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "xray_tun_dns_addresses" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "dns-hijack" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix ".streamSettings.sockopt.interface = $interface" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "del(.routing.balancers)" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "del(.observatory)" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix "xray_rewrite_proxy_rule" xrayBackendJqFilter;
|
||||
assert pkgs.lib.hasInfix ".protocol == \"dns\"" xrayBackendJqFilter;
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
{
|
||||
pkgs,
|
||||
checkConstants,
|
||||
xrayTunConfig,
|
||||
xrayTunStartScript,
|
||||
xrayTunUpScript,
|
||||
}:
|
||||
|
||||
{
|
||||
assertions = [
|
||||
# -- xray backend: global TUN runtime config/scripts --
|
||||
(
|
||||
let
|
||||
tunInbound = builtins.head (
|
||||
builtins.filter (inbound: inbound.tag == "tun-in") xrayTunConfig.inbounds
|
||||
);
|
||||
tunDirectOutbound = builtins.head (
|
||||
builtins.filter (outbound: outbound.tag == "direct") xrayTunConfig.outbounds
|
||||
);
|
||||
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;
|
||||
in
|
||||
assert tunInbound.protocol == "tun";
|
||||
assert tunInbound.settings.name == "singtun0";
|
||||
assert
|
||||
tunInbound.settings.gateway == [
|
||||
"172.19.0.1/30"
|
||||
checkConstants.xrayGlobalTunIPv6Address
|
||||
];
|
||||
assert builtins.length tunInbound.settings.dns == 2;
|
||||
assert tunInbound.settings.autoOutboundsInterface == "auto";
|
||||
assert tunInbound.sniffing.destOverride == [ "fakedns" ];
|
||||
assert tunInbound.sniffing.metadataOnly == true;
|
||||
assert xrayTunConfig.routing.domainStrategy == "IPIfNonMatch";
|
||||
assert tunHasFinalRuleTag;
|
||||
assert tunHasDirectGeositeRule;
|
||||
assert tunHasDnsHijackRule;
|
||||
assert tunHasDnsUpstreamRule;
|
||||
assert xrayTunConfig.dns.queryStrategy == "UseIP";
|
||||
assert xrayTunConfig.dns.tag == "dns-in";
|
||||
assert (builtins.head xrayTunConfig.dns.servers).address == "fakedns";
|
||||
assert (builtins.head xrayTunConfig.dns.servers).tag == "fakedns";
|
||||
assert (builtins.elemAt xrayTunConfig.dns.servers 1).tag == "remote";
|
||||
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 tunDirectOutbound.streamSettings.sockopt.mark == 2;
|
||||
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;
|
||||
assert pkgs.lib.hasInfix "ip -4 route get 1.1.1.1 mark 2" xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix "xray_tun_dns_runtime" xrayTunStartScript;
|
||||
assert pkgs.lib.hasInfix ''tun_route_prefix="$(cidr_network "$tun_cidr")"'' xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix checkConstants.xrayGlobalTunIPv6Address xrayTunUpScript;
|
||||
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 ${toString checkConstants.tunAutoRouteTableIndex}''
|
||||
xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
''route replace default dev singtun0 src "$uplink_addr" table ${toString checkConstants.tunAutoRouteTableIndex}''
|
||||
xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
''-6 route replace "$tun6_route_prefix" dev singtun0 table ${toString checkConstants.tunAutoRouteTableIndex}''
|
||||
xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
"-6 route replace default dev singtun0 table ${toString checkConstants.tunAutoRouteTableIndex}"
|
||||
xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
"rule add pref ${toString checkConstants.xrayTunPerAppTproxyRulePriority} fwmark 17 table 102"
|
||||
xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
"rule add pref ${toString checkConstants.xrayTunPerAppTunRulePriority} fwmark 16 table 101"
|
||||
xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
"rule add pref ${toString checkConstants.tunAutoRouteRulePriority} not fwmark 2 table ${toString checkConstants.tunAutoRouteTableIndex}"
|
||||
xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
"-6 rule add pref ${toString checkConstants.xrayTunPerAppTunRulePriority} fwmark 16 table 101"
|
||||
xrayTunUpScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
"-6 rule add pref ${toString checkConstants.tunAutoRouteRulePriority} not fwmark 2 table ${toString checkConstants.tunAutoRouteTableIndex}"
|
||||
xrayTunUpScript;
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
{
|
||||
pkgs,
|
||||
checkConstants,
|
||||
xrayPerAppTunConfig,
|
||||
xrayPerAppTunStartScript,
|
||||
xrayPerAppTunUpScript,
|
||||
xrayPerAppTunCleanupScript,
|
||||
}:
|
||||
|
||||
{
|
||||
assertions = [
|
||||
# -- xray backend: per-app TUN runtime config/scripts --
|
||||
(
|
||||
let
|
||||
perAppTunInbound = builtins.head (
|
||||
builtins.filter (inbound: inbound.tag == "tun-in") xrayPerAppTunConfig.inbounds
|
||||
);
|
||||
perAppTunDirectOutbound = builtins.head (
|
||||
builtins.filter (outbound: outbound.tag == "direct") xrayPerAppTunConfig.outbounds
|
||||
);
|
||||
in
|
||||
assert perAppTunInbound.settings.name == "psperapptun0";
|
||||
assert
|
||||
perAppTunInbound.settings.gateway == [
|
||||
"172.20.0.1/30"
|
||||
checkConstants.xrayPerAppTunIPv6Address
|
||||
];
|
||||
assert builtins.length perAppTunInbound.settings.dns == 2;
|
||||
assert perAppTunInbound.sniffing.destOverride == [ "fakedns" ];
|
||||
assert perAppTunInbound.sniffing.metadataOnly == true;
|
||||
assert xrayPerAppTunConfig.routing.domainStrategy == "IPIfNonMatch";
|
||||
assert (builtins.head xrayPerAppTunConfig.dns.servers).address == "fakedns";
|
||||
assert xrayPerAppTunConfig.dns.tag == "dns-in";
|
||||
assert builtins.length xrayPerAppTunConfig.fakedns == 2;
|
||||
assert perAppTunDirectOutbound.streamSettings.sockopt.mark == 2;
|
||||
assert pkgs.lib.hasInfix "XRAY_SINGLE_PROXY_TAG=" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix "ip -4 route get 1.1.1.1" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix "ip -4 route get 1.1.1.1 mark 2" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix "BACKEND_JQ_FILTER=" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix ''-f "$BACKEND_JQ_FILTER"'' xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix "--routing-mark 2" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix "xray_tun_dns_runtime" xrayPerAppTunStartScript;
|
||||
assert pkgs.lib.hasInfix ''tun_route_prefix="$(cidr_network "$tun_cidr")"'' xrayPerAppTunUpScript;
|
||||
assert pkgs.lib.hasInfix checkConstants.xrayPerAppTunIPv6Address xrayPerAppTunUpScript;
|
||||
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 "resolvectl flush-caches" xrayPerAppTunCleanupScript;
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
mkTProxyConfig,
|
||||
mkTunConfig,
|
||||
mkPerAppTunConfig,
|
||||
shellValueByPrefix,
|
||||
mkBadProxySuiteFixture,
|
||||
mkFailingAssertions,
|
||||
dnsServerByTag,
|
||||
checkConstants,
|
||||
}:
|
||||
|
||||
let
|
||||
runtimeChecks = import ./xray-backend-runtime.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkTProxyConfig
|
||||
mkTunConfig
|
||||
mkPerAppTunConfig
|
||||
shellValueByPrefix
|
||||
checkConstants
|
||||
;
|
||||
};
|
||||
featureChecks = import ./xray-backend-features.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkTProxyConfig
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
dnsServerByTag
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
runtime = runtimeChecks.runtime;
|
||||
assertions = runtimeChecks.assertions ++ featureChecks.assertions;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
mkTProxyConfig,
|
||||
mkTunConfig,
|
||||
mkPerAppTunConfig,
|
||||
shellValueByPrefix,
|
||||
mkBadProxySuiteFixture,
|
||||
mkFailingAssertions,
|
||||
dnsServerByTag,
|
||||
checkConstants,
|
||||
}:
|
||||
|
||||
let
|
||||
xrayChecks = import ./xray-backend.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkTProxyConfig
|
||||
mkTunConfig
|
||||
mkPerAppTunConfig
|
||||
shellValueByPrefix
|
||||
mkBadProxySuiteFixture
|
||||
mkFailingAssertions
|
||||
dnsServerByTag
|
||||
checkConstants
|
||||
;
|
||||
};
|
||||
hybridChecks = import ./hybrid-backend.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkTProxyConfig
|
||||
mkTunConfig
|
||||
shellValueByPrefix
|
||||
checkConstants
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
runtime = xrayChecks.runtime;
|
||||
assertions = hybridChecks.assertions ++ xrayChecks.assertions;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkRoutingRules,
|
||||
mkZapretBase,
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
hasDirectDomain,
|
||||
hasDirectIP,
|
||||
zapretSyncBase,
|
||||
zapretSyncExtraListsBase,
|
||||
zapretSyncNoExtraListsBase,
|
||||
zapretSpacedConfigAliasBase,
|
||||
zapretUnspacedConfigAliasBase,
|
||||
}:
|
||||
|
||||
let
|
||||
fixtures = import ./zapret-hostlist-routing/fixtures.nix {
|
||||
inherit
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkRoutingRules
|
||||
mkZapretBase
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
;
|
||||
};
|
||||
inherit (fixtures)
|
||||
zapretHostlistRules
|
||||
zapretHostlistBase
|
||||
invalidHostlistAssertions
|
||||
;
|
||||
|
||||
zapretHostlistChecks = import ./zapret-hostlist.nix {
|
||||
inherit
|
||||
pkgs
|
||||
zapretSyncBase
|
||||
zapretSyncExtraListsBase
|
||||
zapretSyncNoExtraListsBase
|
||||
zapretSpacedConfigAliasBase
|
||||
zapretUnspacedConfigAliasBase
|
||||
zapretHostlistBase
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit (zapretHostlistChecks) rules;
|
||||
|
||||
assertions = [
|
||||
(
|
||||
assert hasDirectDomain zapretHostlistRules "googlevideo.com";
|
||||
assert hasDirectDomain zapretHostlistRules "example.com";
|
||||
assert !(hasDirectDomain zapretHostlistRules "x.example");
|
||||
true
|
||||
)
|
||||
(
|
||||
assert hasDirectDomain zapretHostlistRules "youtube.com";
|
||||
assert hasDirectDomain zapretHostlistRules "discord.com";
|
||||
assert hasDirectDomain zapretHostlistRules "cloudflare-ech.com";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert hasDirectIP zapretHostlistRules "203.0.113.0/24";
|
||||
assert !(hasDirectIP zapretHostlistRules "1.1.1.0/24");
|
||||
true
|
||||
)
|
||||
]
|
||||
++ invalidHostlistAssertions;
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
{
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkRoutingRules,
|
||||
mkZapretBase,
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
let
|
||||
zapretHostlistRulesFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
hostlistRules = [
|
||||
{
|
||||
name = "googlevideo";
|
||||
domains = [
|
||||
"googlevideo.com"
|
||||
"ggpht.com"
|
||||
];
|
||||
preset = "google";
|
||||
}
|
||||
{
|
||||
name = "example";
|
||||
domains = [
|
||||
"example.com"
|
||||
"example.de"
|
||||
];
|
||||
nfqwsArgs = [ "--filter-tcp=443 --dpi-desync=fake,multisplit" ];
|
||||
}
|
||||
{
|
||||
name = "twitter-no-direct";
|
||||
domains = [ "x.example" ];
|
||||
nfqwsArgs = [ "--filter-udp=443 --dpi-desync=fake --dpi-desync-repeats=6" ];
|
||||
enableDirectSync = false;
|
||||
}
|
||||
{
|
||||
name = "google-general";
|
||||
defaultDomains = [ "google" ];
|
||||
configName = "general";
|
||||
}
|
||||
{
|
||||
name = "general-alt12";
|
||||
defaultDomains = [ "general" ];
|
||||
configName = "general (ALT12)";
|
||||
}
|
||||
{
|
||||
name = "youtube-alias";
|
||||
defaultDomains = [ "youtube" ];
|
||||
configName = "general";
|
||||
enableDirectSync = false;
|
||||
}
|
||||
{
|
||||
name = "discord-alias";
|
||||
defaultDomains = [ "discord" ];
|
||||
configName = "general (ALT12)";
|
||||
enableDirectSync = false;
|
||||
}
|
||||
{
|
||||
name = "upstream-ips";
|
||||
defaultIps = [ "all" ];
|
||||
configName = "general";
|
||||
enableDirectSync = false;
|
||||
}
|
||||
{
|
||||
name = "explicit-ips";
|
||||
ips = [ "203.0.113.0/24" ];
|
||||
configName = "general";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
];
|
||||
zapretHostlistRules = mkRoutingRules zapretHostlistRulesFixture;
|
||||
zapretHostlistBase = mkZapretBase zapretHostlistRulesFixture;
|
||||
|
||||
invalidHostlistAssertions = mkFailingAssertions mkBadFixture [
|
||||
[
|
||||
{
|
||||
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" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
hostlistRules = [
|
||||
{
|
||||
name = "empty";
|
||||
domains = [ ];
|
||||
nfqwsArgs = [ "--filter-tcp=443 --dpi-desync=fake" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
hostlistRules = [
|
||||
{
|
||||
name = "missing";
|
||||
domains = [ "missing.example" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
hostlistRules = [
|
||||
{
|
||||
name = "conflict";
|
||||
defaultDomains = [ "google" ];
|
||||
configName = "general";
|
||||
nfqwsArgs = [ "--filter-tcp=443 --dpi-desync=fake" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
hostlistRules = [
|
||||
{
|
||||
name = "missing-family";
|
||||
domains = [ "example.com" ];
|
||||
configName = "general";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
]
|
||||
];
|
||||
in
|
||||
{
|
||||
inherit
|
||||
zapretHostlistRules
|
||||
zapretHostlistBase
|
||||
invalidHostlistAssertions
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
{
|
||||
pkgs,
|
||||
zapretSyncBase,
|
||||
zapretSyncExtraListsBase,
|
||||
zapretSyncNoExtraListsBase,
|
||||
zapretSpacedConfigAliasBase,
|
||||
zapretUnspacedConfigAliasBase,
|
||||
zapretHostlistBase,
|
||||
}:
|
||||
|
||||
{
|
||||
rules = pkgs.runCommand "proxy-suite-zapret-hostlist-rules-check" { } ''
|
||||
grep -F -- '--hostlist="${zapretSyncExtraListsBase}/hostlists/list-twitter.txt"' "${zapretSyncExtraListsBase}/config"
|
||||
grep -F -- '--hostlist="${zapretSyncExtraListsBase}/hostlists/list-instagram.txt"' "${zapretSyncExtraListsBase}/config"
|
||||
grep -F -- '--hostlist="${zapretSyncExtraListsBase}/hostlists/list-soundcloud.txt"' "${zapretSyncExtraListsBase}/config"
|
||||
! grep -F -- '--hostlist="${zapretSyncBase}/hostlists/list-twitter.txt"' "${zapretSyncBase}/config"
|
||||
! grep -F -- '--hostlist="${zapretSyncBase}/hostlists/list-instagram.txt"' "${zapretSyncBase}/config"
|
||||
! grep -F -- '--hostlist="${zapretSyncBase}/hostlists/list-soundcloud.txt"' "${zapretSyncBase}/config"
|
||||
test -f "${zapretSpacedConfigAliasBase}/config"
|
||||
test -f "${zapretUnspacedConfigAliasBase}/config"
|
||||
! grep -F -- '--hostlist="${zapretSyncNoExtraListsBase}/hostlists/list-twitter.txt"' "${zapretSyncNoExtraListsBase}/config"
|
||||
! grep -F -- '--hostlist="${zapretSyncNoExtraListsBase}/hostlists/list-instagram.txt"' "${zapretSyncNoExtraListsBase}/config"
|
||||
! grep -F -- '--hostlist="${zapretSyncNoExtraListsBase}/hostlists/list-soundcloud.txt"' "${zapretSyncNoExtraListsBase}/config"
|
||||
grep -F 'googlevideo.com' "${zapretHostlistBase}/hostlists/list-googlevideo.txt"
|
||||
grep -F 'example.de' "${zapretHostlistBase}/hostlists/list-example.txt"
|
||||
grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-googlevideo.txt"' "${zapretHostlistBase}/config"
|
||||
grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-example.txt"' "${zapretHostlistBase}/config"
|
||||
grep -F -- '--filter-tcp=443 --dpi-desync=fake,multisplit --hostlist="${zapretHostlistBase}/hostlists/list-example.txt" --hostlist-exclude="${zapretHostlistBase}/hostlists/list-exclude.txt" --hostlist-exclude="${zapretHostlistBase}/hostlists/list-exclude-user.txt" --ipset-exclude="${zapretHostlistBase}/hostlists/ipset-exclude.txt" --ipset-exclude="${zapretHostlistBase}/hostlists/ipset-exclude-user.txt" --new' "${zapretHostlistBase}/config"
|
||||
grep -F 'youtube.com' "${zapretHostlistBase}/hostlists/list-google-general.txt"
|
||||
grep -F 'googlevideo.com' "${zapretHostlistBase}/hostlists/list-google-general.txt"
|
||||
grep -F 'discord.com' "${zapretHostlistBase}/hostlists/list-general-alt12.txt"
|
||||
grep -F 'discord.gg' "${zapretHostlistBase}/hostlists/list-general-alt12.txt"
|
||||
grep -F 'cloudflare-ech.com' "${zapretHostlistBase}/hostlists/list-general-alt12.txt"
|
||||
grep -F 'cloudfront.net' "${zapretHostlistBase}/hostlists/list-general-alt12.txt"
|
||||
grep -F '7tv.app' "${zapretHostlistBase}/hostlists/list-general-alt12.txt"
|
||||
cmp "${zapretHostlistBase}/hostlists/list-google-general.txt" "${zapretHostlistBase}/hostlists/list-youtube-alias.txt"
|
||||
cmp "${zapretHostlistBase}/hostlists/list-general-alt12.txt" "${zapretHostlistBase}/hostlists/list-discord-alias.txt"
|
||||
grep -F '1.1.1.0/24' "${zapretHostlistBase}/hostlists/ipset-upstream-ips.txt"
|
||||
grep -F '203.0.113.0/24' "${zapretHostlistBase}/hostlists/ipset-explicit-ips.txt"
|
||||
grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-google-general.txt"' "${zapretHostlistBase}/config"
|
||||
grep -F -- '--dpi-desync=multisplit --dpi-desync-split-seqovl=681' "${zapretHostlistBase}/config"
|
||||
grep -F -- '--ipset="${zapretHostlistBase}/hostlists/ipset-upstream-ips.txt"' "${zapretHostlistBase}/config"
|
||||
grep -F -- '--ipset="${zapretHostlistBase}/hostlists/ipset-explicit-ips.txt"' "${zapretHostlistBase}/config"
|
||||
google_rule_line=$(grep -nF -- '--hostlist="${zapretHostlistBase}/hostlists/list-google-general.txt"' "${zapretHostlistBase}/config" | head -n1 | cut -d: -f1)
|
||||
default_google_rule_line=$(grep -nF -- '--hostlist="${zapretHostlistBase}/hostlists/list-google.txt"' "${zapretHostlistBase}/config" | head -n1 | cut -d: -f1)
|
||||
general_rule_line=$(grep -nF -- '--hostlist="${zapretHostlistBase}/hostlists/list-general-alt12.txt"' "${zapretHostlistBase}/config" | head -n1 | cut -d: -f1)
|
||||
default_general_rule_line=$(grep -nF -- '--hostlist="${zapretHostlistBase}/hostlists/list-general.txt"' "${zapretHostlistBase}/config" | head -n1 | cut -d: -f1)
|
||||
discord_voice_rule_line=$(grep -nF -- '--filter-l7=discord,stun' "${zapretHostlistBase}/config" | grep -F -- '--dpi-desync-repeats=3' | head -n1 | cut -d: -f1)
|
||||
default_voice_rule_line=$(grep -nF -- '--filter-l7=discord,stun' "${zapretHostlistBase}/config" | grep -F -- '--dpi-desync-repeats=6' | head -n1 | cut -d: -f1)
|
||||
test "$google_rule_line" -lt "$default_google_rule_line"
|
||||
test "$general_rule_line" -lt "$default_general_rule_line"
|
||||
test "$discord_voice_rule_line" -lt "$default_voice_rule_line"
|
||||
touch "$out"
|
||||
'';
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkRoutingRules,
|
||||
mkZapretBase,
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
hasDirectDomain,
|
||||
hasDirectIP,
|
||||
}:
|
||||
|
||||
let
|
||||
fixtures = import ./zapret/fixtures.nix {
|
||||
inherit
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkRoutingRules
|
||||
mkZapretBase
|
||||
;
|
||||
};
|
||||
inherit (fixtures)
|
||||
zapretSyncService
|
||||
zapretSyncRules
|
||||
zapretSyncBase
|
||||
zapretSpacedConfigAliasBase
|
||||
zapretUnspacedConfigAliasBase
|
||||
zapretSyncNoExtraListsBase
|
||||
zapretSyncNoExtraListsRules
|
||||
zapretSyncExtraListsBase
|
||||
zapretSyncExtraListsRules
|
||||
zapretSyncIpsRules
|
||||
zapretSyncUserIpsDisabledRules
|
||||
zapretSyncDisabledRules
|
||||
zapretSyncDomainsOnlyRules
|
||||
zapretExtrasRules
|
||||
zapretIpExtrasRules
|
||||
zapretExcludesRules
|
||||
zapretIpExcludesRules
|
||||
;
|
||||
|
||||
zapretHostlistRoutingChecks = import ./zapret-hostlist-routing.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkRoutingRules
|
||||
mkZapretBase
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
hasDirectDomain
|
||||
hasDirectIP
|
||||
zapretSyncBase
|
||||
zapretSyncExtraListsBase
|
||||
zapretSyncNoExtraListsBase
|
||||
zapretSpacedConfigAliasBase
|
||||
zapretUnspacedConfigAliasBase
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit (zapretHostlistRoutingChecks) rules;
|
||||
syncService = zapretSyncService;
|
||||
|
||||
assertions = [
|
||||
(
|
||||
assert hasDirectDomain zapretSyncRules "discord.com";
|
||||
assert hasDirectDomain zapretSyncRules "youtube.com";
|
||||
assert hasDirectDomain zapretSyncRules "cloudflare-ech.com";
|
||||
assert !(hasDirectDomain zapretSyncRules "twitter.com");
|
||||
assert !(hasDirectIP zapretSyncRules "1.1.1.0/24");
|
||||
true
|
||||
)
|
||||
(
|
||||
assert hasDirectDomain zapretSyncDomainsOnlyRules "cloudflare-ech.com";
|
||||
assert !(hasDirectIP zapretSyncDomainsOnlyRules "1.1.1.0/24");
|
||||
true
|
||||
)
|
||||
(
|
||||
assert hasDirectIP zapretSyncIpsRules "1.1.1.0/24";
|
||||
assert !(hasDirectIP zapretSyncUserIpsDisabledRules "203.0.113.0/24");
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(hasDirectDomain zapretSyncNoExtraListsRules "twitter.com");
|
||||
assert hasDirectDomain zapretSyncExtraListsRules "twitter.com";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(hasDirectDomain zapretSyncDisabledRules "discord.com");
|
||||
assert !(hasDirectIP zapretSyncDisabledRules "1.1.1.0/24");
|
||||
true
|
||||
)
|
||||
(
|
||||
assert hasDirectDomain zapretExtrasRules "pixiv.net";
|
||||
assert hasDirectIP zapretIpExtrasRules "203.0.113.0/24";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(hasDirectDomain zapretExcludesRules "discord.com");
|
||||
assert !(hasDirectIP zapretIpExcludesRules "1.1.1.0/24");
|
||||
true
|
||||
)
|
||||
]
|
||||
++ zapretHostlistRoutingChecks.assertions;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
{
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkRoutingRules,
|
||||
mkZapretBase,
|
||||
}:
|
||||
|
||||
let
|
||||
evalZapret =
|
||||
zapretConfig:
|
||||
evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
}
|
||||
// zapretConfig;
|
||||
}
|
||||
];
|
||||
|
||||
zapretSyncFixture = evalZapret { };
|
||||
zapretSyncService = zapretSyncFixture.config.systemd.services."zapret-discord-youtube";
|
||||
zapretSyncRules = mkRoutingRules zapretSyncFixture;
|
||||
zapretSyncBase = mkZapretBase zapretSyncFixture;
|
||||
|
||||
zapretSpacedConfigAliasBase = mkZapretBase (evalZapret {
|
||||
configName = "general(ALT12)";
|
||||
});
|
||||
|
||||
zapretUnspacedConfigAliasBase = mkZapretBase (evalZapret {
|
||||
configName = "general (ALT)";
|
||||
});
|
||||
|
||||
zapretSyncNoExtraListsFixture = evalZapret {
|
||||
includeExtraUpstreamLists = false;
|
||||
};
|
||||
zapretSyncNoExtraListsBase = mkZapretBase zapretSyncNoExtraListsFixture;
|
||||
zapretSyncNoExtraListsRules = mkRoutingRules zapretSyncNoExtraListsFixture;
|
||||
|
||||
zapretSyncExtraListsFixture = evalZapret {
|
||||
includeExtraUpstreamLists = true;
|
||||
};
|
||||
zapretSyncExtraListsBase = mkZapretBase zapretSyncExtraListsFixture;
|
||||
zapretSyncExtraListsRules = mkRoutingRules zapretSyncExtraListsFixture;
|
||||
|
||||
zapretSyncIpsRules = mkRoutingRules (evalZapret {
|
||||
syncDirectRoutingUpstreamIps = true;
|
||||
});
|
||||
|
||||
zapretSyncUserIpsDisabledRules = mkRoutingRules (evalZapret {
|
||||
syncDirectRoutingUserIps = false;
|
||||
ipsetAll = [ "203.0.113.0/24" ];
|
||||
});
|
||||
|
||||
zapretSyncDisabledRules = mkRoutingRules (evalZapret {
|
||||
syncDirectRouting = false;
|
||||
});
|
||||
|
||||
zapretSyncDomainsOnlyRules = mkRoutingRules (evalZapret {
|
||||
syncDirectRouting = true;
|
||||
syncDirectRoutingUpstreamIps = false;
|
||||
});
|
||||
|
||||
zapretExtrasRules = mkRoutingRules (evalZapret {
|
||||
listGeneral = [ "pixiv.net" ];
|
||||
});
|
||||
|
||||
zapretIpExtrasRules = mkRoutingRules (evalZapret {
|
||||
ipsetAll = [ "203.0.113.0/24" ];
|
||||
});
|
||||
|
||||
zapretExcludesRules = mkRoutingRules (evalZapret {
|
||||
listExclude = [ "discord.com" ];
|
||||
});
|
||||
|
||||
zapretIpExcludesRules = mkRoutingRules (evalZapret {
|
||||
ipsetExclude = [ "1.1.1.0/24" ];
|
||||
ipsetAll = [ "1.1.1.0/24" ];
|
||||
});
|
||||
in
|
||||
{
|
||||
inherit
|
||||
zapretSyncService
|
||||
zapretSyncRules
|
||||
zapretSyncBase
|
||||
zapretSpacedConfigAliasBase
|
||||
zapretUnspacedConfigAliasBase
|
||||
zapretSyncNoExtraListsBase
|
||||
zapretSyncNoExtraListsRules
|
||||
zapretSyncExtraListsBase
|
||||
zapretSyncExtraListsRules
|
||||
zapretSyncIpsRules
|
||||
zapretSyncUserIpsDisabledRules
|
||||
zapretSyncDisabledRules
|
||||
zapretSyncDomainsOnlyRules
|
||||
zapretExtrasRules
|
||||
zapretIpExtrasRules
|
||||
zapretExcludesRules
|
||||
zapretIpExcludesRules
|
||||
;
|
||||
}
|
||||
+24
-205
@@ -25,20 +25,18 @@ let
|
||||
config:
|
||||
builtins.removeAttrs config [ "singBox" ]
|
||||
// {
|
||||
proxy =
|
||||
(config.proxy or { })
|
||||
// {
|
||||
singBox =
|
||||
((config.proxy or { }).singBox or { })
|
||||
// lib.optionalAttrs (((config.proxy or { }).singBox or { }) ? package) {
|
||||
package = singBoxPackagePlaceholder;
|
||||
};
|
||||
xray =
|
||||
((config.proxy or { }).xray or { })
|
||||
// lib.optionalAttrs (((config.proxy or { }).xray or { }) ? package) {
|
||||
package = xrayPackagePlaceholder;
|
||||
};
|
||||
};
|
||||
proxy = (config.proxy or { }) // {
|
||||
singBox =
|
||||
((config.proxy or { }).singBox or { })
|
||||
// lib.optionalAttrs (((config.proxy or { }).singBox or { }) ? package) {
|
||||
package = singBoxPackagePlaceholder;
|
||||
};
|
||||
xray =
|
||||
((config.proxy or { }).xray or { })
|
||||
// lib.optionalAttrs (((config.proxy or { }).xray or { }) ? package) {
|
||||
package = xrayPackagePlaceholder;
|
||||
};
|
||||
};
|
||||
};
|
||||
renderConfigText =
|
||||
config:
|
||||
@@ -51,9 +49,7 @@ let
|
||||
"pkgs.sing-box"
|
||||
"pkgs.xray"
|
||||
]
|
||||
(
|
||||
lib.generators.toPretty { } (sanitizeConfigForDocs config)
|
||||
);
|
||||
(lib.generators.toPretty { } (sanitizeConfigForDocs config));
|
||||
mkGeneratedExampleValue =
|
||||
option:
|
||||
if (option ? _type) && option._type == "option" then
|
||||
@@ -68,8 +64,9 @@ let
|
||||
else
|
||||
lib.mapAttrs (_: mkGeneratedExampleValue) (filterGeneratedOptions option);
|
||||
defaultConfigText = renderConfigText eval.config.services.proxy-suite;
|
||||
generatedExampleConfig =
|
||||
lib.mapAttrs (_: mkGeneratedExampleValue) (filterGeneratedOptions eval.options.services.proxy-suite);
|
||||
generatedExampleConfig = lib.mapAttrs (_: mkGeneratedExampleValue) (
|
||||
filterGeneratedOptions eval.options.services.proxy-suite
|
||||
);
|
||||
exampleConfigText = renderConfigText (builtins.removeAttrs generatedExampleConfig [ "singBox" ]);
|
||||
repoRoot = toString ../.;
|
||||
repoUrl = "https://github.com/FUFSoB/proxy-suite-flake/blob/main";
|
||||
@@ -98,189 +95,11 @@ let
|
||||
transformOptions = opt: opt // { declarations = map transformDeclaration opt.declarations; };
|
||||
};
|
||||
in
|
||||
pkgs.runCommand "proxy-suite-options.md" { } ''
|
||||
preamble="$TMPDIR/preamble.md"
|
||||
sections="$TMPDIR/sections.md"
|
||||
sections_with_anchors="$TMPDIR/sections-with-anchors.md"
|
||||
section_index="$TMPDIR/sections-index.tsv"
|
||||
toc="$TMPDIR/toc.md"
|
||||
|
||||
cat >"$preamble" <<'EOF'
|
||||
# proxy-suite options
|
||||
|
||||
This file is generated from the `services.proxy-suite` option descriptions in [`modules/proxy-suite/options/default.nix`](/modules/proxy-suite/options/default.nix).
|
||||
Update module option docs there instead of editing this file by hand.
|
||||
|
||||
## Table of contents
|
||||
|
||||
EOF
|
||||
|
||||
cat >"$sections" <<'EOF'
|
||||
## Complete default config
|
||||
|
||||
```nix
|
||||
services.proxy-suite = ${defaultConfigText};
|
||||
```
|
||||
|
||||
## Complete example config
|
||||
|
||||
This is generated by filling in all the options with example values (or defaults if no example is provided). This is not meant to be a recommended config, just a comprehensive example of how to set all the options.
|
||||
|
||||
```nix
|
||||
services.proxy-suite = ${exampleConfigText};
|
||||
```
|
||||
|
||||
EOF
|
||||
|
||||
cat ${optionDocs.optionsCommonMark} >>"$sections"
|
||||
|
||||
: >"$section_index"
|
||||
: >"$sections_with_anchors"
|
||||
awk -v section_index="$section_index" -v out="$sections_with_anchors" '
|
||||
function slugify(text, slug) {
|
||||
slug = text
|
||||
gsub(/\\/, "", slug)
|
||||
slug = tolower(slug)
|
||||
gsub(/[^a-z0-9]+/, "-", slug)
|
||||
sub(/^-+/, "", slug)
|
||||
sub(/-+$/, "", slug)
|
||||
return slug
|
||||
}
|
||||
|
||||
/^## / {
|
||||
title = substr($0, 4)
|
||||
base = slugify(title)
|
||||
count = seen[base]
|
||||
seen[base]++
|
||||
slug = count == 0 ? base : base "-" count
|
||||
|
||||
print title "\t" slug >> section_index
|
||||
print "<a id=\"" slug "\"></a>" >> out
|
||||
}
|
||||
|
||||
{
|
||||
print >> out
|
||||
}
|
||||
' "$sections"
|
||||
|
||||
: >"$toc"
|
||||
awk -F '\t' -v toc="$toc" '
|
||||
function addChild(parent, child, key) {
|
||||
key = parent SUBSEP child
|
||||
if (!(key in seenChild)) {
|
||||
seenChild[key] = 1
|
||||
childCount[parent]++
|
||||
childOrder[parent, childCount[parent]] = child
|
||||
}
|
||||
}
|
||||
|
||||
function indent(depth, i, prefix) {
|
||||
prefix = ""
|
||||
for (i = 0; i < depth; i++) {
|
||||
prefix = prefix " "
|
||||
}
|
||||
return prefix
|
||||
}
|
||||
|
||||
function displayLabel(label) {
|
||||
if (label == "*") {
|
||||
return "item"
|
||||
}
|
||||
return label
|
||||
}
|
||||
|
||||
function printNode(path, label, depth, i, child, childPath, text) {
|
||||
text = displayLabel(label)
|
||||
if (path in slugByPath) {
|
||||
text = "[" text "](#" slugByPath[path] ")"
|
||||
}
|
||||
|
||||
print indent(depth) "- " text >> toc
|
||||
|
||||
for (i = 1; i <= childCount[path]; i++) {
|
||||
child = childOrder[path, i]
|
||||
childPath = path "." child
|
||||
printNode(childPath, child, depth + 1)
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
title = $1
|
||||
slug = $2
|
||||
normalized = title
|
||||
gsub(/\\/, "", normalized)
|
||||
|
||||
if (normalized ~ /^Complete /) {
|
||||
sampleCount++
|
||||
sampleTitle[sampleCount] = title
|
||||
sampleSlug[sampleCount] = slug
|
||||
next
|
||||
}
|
||||
|
||||
if (index(normalized, "services.proxy-suite") == 1) {
|
||||
optionRootSeen = 1
|
||||
slugByPath[normalized] = slug
|
||||
|
||||
count = split(normalized, parts, /\./)
|
||||
if (count < 3) {
|
||||
next
|
||||
}
|
||||
|
||||
parent = "services.proxy-suite"
|
||||
for (i = 3; i <= count; i++) {
|
||||
child = parts[i]
|
||||
addChild(parent, child)
|
||||
parent = parent "." child
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
otherCount++
|
||||
otherTitle[otherCount] = title
|
||||
otherSlug[otherCount] = slug
|
||||
}
|
||||
|
||||
END {
|
||||
if (sampleCount > 0) {
|
||||
print "- Config samples" >> toc
|
||||
for (i = 1; i <= sampleCount; i++) {
|
||||
print " - [" sampleTitle[i] "](#" sampleSlug[i] ")" >> toc
|
||||
}
|
||||
}
|
||||
|
||||
if (optionRootSeen) {
|
||||
print "- services.proxy-suite" >> toc
|
||||
for (i = 1; i <= childCount["services.proxy-suite"]; i++) {
|
||||
child = childOrder["services.proxy-suite", i]
|
||||
printNode("services.proxy-suite." child, child, 1)
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i <= otherCount; i++) {
|
||||
print "- [" otherTitle[i] "](#" otherSlug[i] ")" >> toc
|
||||
}
|
||||
}
|
||||
' "$section_index"
|
||||
|
||||
raw="$TMPDIR/options.md.raw"
|
||||
|
||||
cat "$preamble" >"$raw"
|
||||
cat "$toc" >>"$raw"
|
||||
printf '\n' >>"$raw"
|
||||
cat "$sections_with_anchors" >>"$raw"
|
||||
|
||||
awk '
|
||||
NF {
|
||||
for (i = 0; i < blanks; i++) {
|
||||
print ""
|
||||
}
|
||||
blanks = 0
|
||||
print
|
||||
next
|
||||
}
|
||||
|
||||
{
|
||||
blanks++
|
||||
}
|
||||
' "$raw" >"$out"
|
||||
''
|
||||
import ./options-doc/render-options-markdown.nix {
|
||||
inherit
|
||||
pkgs
|
||||
optionDocs
|
||||
defaultConfigText
|
||||
exampleConfigText
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
{
|
||||
pkgs,
|
||||
optionDocs,
|
||||
defaultConfigText,
|
||||
exampleConfigText,
|
||||
}:
|
||||
|
||||
pkgs.runCommand "proxy-suite-options.md" { } ''
|
||||
preamble="$TMPDIR/preamble.md"
|
||||
sections="$TMPDIR/sections.md"
|
||||
sections_with_anchors="$TMPDIR/sections-with-anchors.md"
|
||||
section_index="$TMPDIR/sections-index.tsv"
|
||||
toc="$TMPDIR/toc.md"
|
||||
|
||||
cat >"$preamble" <<'EOF'
|
||||
# proxy-suite options
|
||||
|
||||
This file is generated from the `services.proxy-suite` option descriptions in [`modules/proxy-suite/options/default.nix`](/modules/proxy-suite/options/default.nix).
|
||||
Update module option docs there instead of editing this file by hand.
|
||||
|
||||
## Table of contents
|
||||
|
||||
EOF
|
||||
|
||||
cat >"$sections" <<'EOF'
|
||||
## Complete default config
|
||||
|
||||
```nix
|
||||
services.proxy-suite = ${defaultConfigText};
|
||||
```
|
||||
|
||||
## Complete example config
|
||||
|
||||
This is generated by filling in all the options with example values (or defaults if no example is provided). This is not meant to be a recommended config, just a comprehensive example of how to set all the options.
|
||||
|
||||
```nix
|
||||
services.proxy-suite = ${exampleConfigText};
|
||||
```
|
||||
|
||||
EOF
|
||||
|
||||
cat ${optionDocs.optionsCommonMark} >>"$sections"
|
||||
|
||||
: >"$section_index"
|
||||
: >"$sections_with_anchors"
|
||||
awk -v section_index="$section_index" -v out="$sections_with_anchors" '
|
||||
function slugify(text, slug) {
|
||||
slug = text
|
||||
gsub(/\\/, "", slug)
|
||||
slug = tolower(slug)
|
||||
gsub(/[^a-z0-9]+/, "-", slug)
|
||||
sub(/^-+/, "", slug)
|
||||
sub(/-+$/, "", slug)
|
||||
return slug
|
||||
}
|
||||
|
||||
/^## / {
|
||||
title = substr($0, 4)
|
||||
base = slugify(title)
|
||||
count = seen[base]
|
||||
seen[base]++
|
||||
slug = count == 0 ? base : base "-" count
|
||||
|
||||
print title "\t" slug >> section_index
|
||||
print "<a id=\"" slug "\"></a>" >> out
|
||||
}
|
||||
|
||||
{
|
||||
print >> out
|
||||
}
|
||||
' "$sections"
|
||||
|
||||
: >"$toc"
|
||||
awk -F '\t' -v toc="$toc" '
|
||||
function addChild(parent, child, key) {
|
||||
key = parent SUBSEP child
|
||||
if (!(key in seenChild)) {
|
||||
seenChild[key] = 1
|
||||
childCount[parent]++
|
||||
childOrder[parent, childCount[parent]] = child
|
||||
}
|
||||
}
|
||||
|
||||
function indent(depth, i, prefix) {
|
||||
prefix = ""
|
||||
for (i = 0; i < depth; i++) {
|
||||
prefix = prefix " "
|
||||
}
|
||||
return prefix
|
||||
}
|
||||
|
||||
function displayLabel(label) {
|
||||
if (label == "*") {
|
||||
return "item"
|
||||
}
|
||||
return label
|
||||
}
|
||||
|
||||
function printNode(path, label, depth, i, child, childPath, text) {
|
||||
text = displayLabel(label)
|
||||
if (path in slugByPath) {
|
||||
text = "[" text "](#" slugByPath[path] ")"
|
||||
}
|
||||
|
||||
print indent(depth) "- " text >> toc
|
||||
|
||||
for (i = 1; i <= childCount[path]; i++) {
|
||||
child = childOrder[path, i]
|
||||
childPath = path "." child
|
||||
printNode(childPath, child, depth + 1)
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
title = $1
|
||||
slug = $2
|
||||
normalized = title
|
||||
gsub(/\\/, "", normalized)
|
||||
|
||||
if (normalized ~ /^Complete /) {
|
||||
sampleCount++
|
||||
sampleTitle[sampleCount] = title
|
||||
sampleSlug[sampleCount] = slug
|
||||
next
|
||||
}
|
||||
|
||||
if (index(normalized, "services.proxy-suite") == 1) {
|
||||
optionRootSeen = 1
|
||||
slugByPath[normalized] = slug
|
||||
|
||||
count = split(normalized, parts, /\./)
|
||||
if (count < 3) {
|
||||
next
|
||||
}
|
||||
|
||||
parent = "services.proxy-suite"
|
||||
for (i = 3; i <= count; i++) {
|
||||
child = parts[i]
|
||||
addChild(parent, child)
|
||||
parent = parent "." child
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
otherCount++
|
||||
otherTitle[otherCount] = title
|
||||
otherSlug[otherCount] = slug
|
||||
}
|
||||
|
||||
END {
|
||||
if (sampleCount > 0) {
|
||||
print "- Config samples" >> toc
|
||||
for (i = 1; i <= sampleCount; i++) {
|
||||
print " - [" sampleTitle[i] "](#" sampleSlug[i] ")" >> toc
|
||||
}
|
||||
}
|
||||
|
||||
if (optionRootSeen) {
|
||||
print "- services.proxy-suite" >> toc
|
||||
for (i = 1; i <= childCount["services.proxy-suite"]; i++) {
|
||||
child = childOrder["services.proxy-suite", i]
|
||||
printNode("services.proxy-suite." child, child, 1)
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i <= otherCount; i++) {
|
||||
print "- [" otherTitle[i] "](#" otherSlug[i] ")" >> toc
|
||||
}
|
||||
}
|
||||
' "$section_index"
|
||||
|
||||
raw="$TMPDIR/options.md.raw"
|
||||
|
||||
cat "$preamble" >"$raw"
|
||||
cat "$toc" >>"$raw"
|
||||
printf '\n' >>"$raw"
|
||||
cat "$sections_with_anchors" >>"$raw"
|
||||
|
||||
awk '
|
||||
NF {
|
||||
for (i = 0; i < blanks; i++) {
|
||||
print ""
|
||||
}
|
||||
blanks = 0
|
||||
print
|
||||
next
|
||||
}
|
||||
|
||||
{
|
||||
blanks++
|
||||
}
|
||||
' "$raw" >"$out"
|
||||
''
|
||||
Reference in new issue
Block a user