refactor: overhaul of options and features
Includes, but not limited to: - zapret2 support - declarative inbounds - proxy-ctl revamp - automatic proxy learning
This commit is contained in:
144 files changed
+13198
-14066
No files matched your search
@@ -127,7 +127,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
@@ -137,10 +137,8 @@ let
|
||||
tun.enable = true;
|
||||
tproxy.enable = true;
|
||||
};
|
||||
zapret = {
|
||||
enable = true;
|
||||
perApp.enable = true;
|
||||
};
|
||||
zapret.enable = true;
|
||||
perAppRouting.zapret.enable = true;
|
||||
amneziaWg = {
|
||||
enable = true;
|
||||
kernelModulePackage = null;
|
||||
@@ -329,7 +327,7 @@ in
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
|
||||
@@ -33,7 +33,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
@@ -58,7 +58,7 @@ let
|
||||
ruDisabledFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.routing.enableRuDirect = false;
|
||||
services.proxy-suite.proxy.routing.directRu = false;
|
||||
}
|
||||
];
|
||||
ruDisabledRules = mkRoutingRules ruDisabledFixture;
|
||||
@@ -68,7 +68,7 @@ let
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.routing = {
|
||||
enableRuDirect = false;
|
||||
directRu = false;
|
||||
direct.geosites = [ "category-ru" ];
|
||||
};
|
||||
}
|
||||
@@ -99,7 +99,7 @@ let
|
||||
proxyDirectConfig = mkTProxyConfig (evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.proxyByDefault = false;
|
||||
services.proxy-suite.proxy.routing.default = "direct";
|
||||
}
|
||||
]);
|
||||
|
||||
@@ -110,7 +110,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "test-proxy";
|
||||
@@ -121,8 +121,8 @@ let
|
||||
urlTest = {
|
||||
url = "https://telegram.org";
|
||||
interval = "1m";
|
||||
tolerance = 100;
|
||||
};
|
||||
singBox.urlTest.tolerance = 100;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -146,7 +146,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
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;
|
||||
assert minimal.config.services.proxy-suite.proxy.urlTest.tolerance == 50;
|
||||
true
|
||||
)
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ in
|
||||
true
|
||||
)
|
||||
(
|
||||
assert tproxyManualFixture.config.services.proxy-suite.proxy.tproxy.autostart == false;
|
||||
assert tproxyManualFixture.config.services.proxy-suite.proxy.autostart == null;
|
||||
assert tproxyManualFixture.config.systemd.services."proxy-suite-tproxy".wantedBy == [ ];
|
||||
true
|
||||
)
|
||||
@@ -60,7 +60,7 @@ in
|
||||
true
|
||||
)
|
||||
(
|
||||
assert tunManualFixture.config.services.proxy-suite.proxy.tun.autostart == false;
|
||||
assert tunManualFixture.config.services.proxy-suite.proxy.autostart == null;
|
||||
assert tunManualFixture.config.systemd.services."proxy-suite-tun".wantedBy == [ ];
|
||||
true
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
tproxy.enable = true;
|
||||
outbounds = [
|
||||
{
|
||||
@@ -44,9 +44,9 @@ let
|
||||
tproxyAutostartFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.tproxy = {
|
||||
enable = true;
|
||||
autostart = true;
|
||||
services.proxy-suite.proxy = {
|
||||
tproxy.enable = true;
|
||||
autostart = "tproxy";
|
||||
};
|
||||
}
|
||||
];
|
||||
@@ -61,29 +61,15 @@ let
|
||||
tunAutostartFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.tun = {
|
||||
enable = true;
|
||||
autostart = true;
|
||||
services.proxy-suite.proxy = {
|
||||
tun.enable = true;
|
||||
autostart = "tun";
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
invalidGlobalProxyModeAssertions = mkFailingAssertions mkBadFixture [
|
||||
# TUN and TProxy cannot both autostart globally.
|
||||
[
|
||||
{
|
||||
services.proxy-suite.proxy = {
|
||||
tproxy = {
|
||||
enable = true;
|
||||
autostart = true;
|
||||
};
|
||||
tun = {
|
||||
enable = true;
|
||||
autostart = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
]
|
||||
# TUN and TProxy can no longer both autostart: proxy.autostart holds one mode.
|
||||
|
||||
# Transparent proxy backends require proxy.enable.
|
||||
[
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
let
|
||||
fixtures = import ./hybrid-backend/fixtures.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
mkTProxyConfig
|
||||
mkTunConfig
|
||||
@@ -54,8 +55,7 @@ in
|
||||
) hybridTproxyConfig.route.rules
|
||||
);
|
||||
in
|
||||
assert hybridFixture.config.services.proxy-suite.proxy.singBox.enable;
|
||||
assert hybridFixture.config.services.proxy-suite.proxy.xray.enable;
|
||||
assert hybridFixture.config.services.proxy-suite.proxy.backend == "hybrid";
|
||||
assert hybridTproxyConfig ? route;
|
||||
assert !(hybridTproxyConfig ? routing);
|
||||
assert dnsBridgeInbound.type == "direct";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
mkTProxyConfig,
|
||||
mkTunConfig,
|
||||
@@ -14,8 +15,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
xray.enable = true;
|
||||
backend = "hybrid";
|
||||
selection = "selector";
|
||||
outbounds = [
|
||||
{
|
||||
@@ -29,8 +29,8 @@ let
|
||||
];
|
||||
tproxy.enable = true;
|
||||
tun.enable = true;
|
||||
tun.perApp.enable = true;
|
||||
};
|
||||
perAppRouting.tun.enable = true;
|
||||
};
|
||||
};
|
||||
hybridFixture = evalProxySuite [ hybridModule ];
|
||||
@@ -48,6 +48,8 @@ let
|
||||
hybridBackendJqFilter =
|
||||
import ../../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix
|
||||
{
|
||||
lib = pkgs.lib;
|
||||
proxyInboundsGuardPrivate = false;
|
||||
pureXrayEnabled = false;
|
||||
selectionMode = hybridFixture.config.services.proxy-suite.proxy.selection;
|
||||
};
|
||||
@@ -59,8 +61,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
xray.enable = true;
|
||||
backend = "hybrid";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "raw-xray";
|
||||
@@ -85,8 +86,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
xray.enable = true;
|
||||
backend = "hybrid";
|
||||
subscriptions = [
|
||||
{
|
||||
tag = "community";
|
||||
|
||||
+2
-2
@@ -166,7 +166,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
@@ -214,7 +214,7 @@ let
|
||||
script = wrapper + "\n" + metadata.script;
|
||||
profiles = builtins.fromJSON (generated.readDerivation metadata.perAppRoutingProfilesFile);
|
||||
subscriptionTags = builtins.fromJSON (generated.readDerivation metadata.subscriptionTagsFile);
|
||||
inherit (metadata) proxychainsConfigFile;
|
||||
inherit (metadata) proxychainsConfigFile wrapperEnv;
|
||||
awgProfiles = builtins.fromJSON (generated.readDerivation metadata.amneziaWgProfileNamesFile);
|
||||
};
|
||||
in
|
||||
|
||||
@@ -15,7 +15,7 @@ let
|
||||
localProxyAuthFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.proxy.auth = {
|
||||
services.proxy-suite.proxy.listener.auth = {
|
||||
username = "local-user";
|
||||
password = "local-pass";
|
||||
};
|
||||
@@ -27,7 +27,9 @@ let
|
||||
localProxyAuthBackendJqFilter =
|
||||
import ../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix
|
||||
{
|
||||
lib = pkgs.lib;
|
||||
pureXrayEnabled = false;
|
||||
proxyInboundsGuardPrivate = false;
|
||||
selectionMode = localProxyAuthFixture.config.services.proxy-suite.proxy.selection;
|
||||
};
|
||||
|
||||
@@ -35,7 +37,7 @@ let
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.auth = {
|
||||
proxy.listener.auth = {
|
||||
username = "local-user";
|
||||
passwordFile = "/run/secrets/local-proxy-password";
|
||||
};
|
||||
@@ -62,16 +64,16 @@ let
|
||||
invalidLocalProxyAuthAssertions = mkFailingAssertions mkBadFixture [
|
||||
# Auth requires both username and a password source.
|
||||
[
|
||||
{ services.proxy-suite.proxy.auth.username = "local-user"; }
|
||||
{ services.proxy-suite.proxy.listener.auth.username = "local-user"; }
|
||||
]
|
||||
[
|
||||
{ services.proxy-suite.proxy.auth.password = "local-pass"; }
|
||||
{ services.proxy-suite.proxy.listener.auth.password = "local-pass"; }
|
||||
]
|
||||
|
||||
# Inline password and passwordFile are mutually exclusive.
|
||||
[
|
||||
{
|
||||
services.proxy-suite.proxy.auth = {
|
||||
services.proxy-suite.proxy.listener.auth = {
|
||||
username = "local-user";
|
||||
password = "local-pass";
|
||||
passwordFile = "/run/secrets/local-proxy-password";
|
||||
|
||||
@@ -186,6 +186,17 @@ let
|
||||
;
|
||||
};
|
||||
|
||||
zapret2Checks = import ./zapret2.nix {
|
||||
inherit
|
||||
pkgs
|
||||
evalProxySuite
|
||||
baseModule
|
||||
mkProxyCtlDerived
|
||||
mkBadFixture
|
||||
mkFailingAssertions
|
||||
;
|
||||
};
|
||||
|
||||
tgWsProxyChecks = import ./tg-ws-proxy.nix {
|
||||
inherit
|
||||
pkgs
|
||||
@@ -220,7 +231,7 @@ let
|
||||
validated = builtins.all (x: x) (
|
||||
[
|
||||
(
|
||||
assert minimal.config.services.proxy-suite.proxy.listenAddress == "127.0.0.1";
|
||||
assert minimal.config.services.proxy-suite.proxy.listener.address == "127.0.0.1";
|
||||
true
|
||||
)
|
||||
]
|
||||
@@ -233,6 +244,7 @@ let
|
||||
++ outboundValidationChecks.assertions
|
||||
++ amneziaWgChecks.assertions
|
||||
++ zapretChecks.assertions
|
||||
++ zapret2Checks.assertions
|
||||
++ globalProxyModeChecks.assertions
|
||||
++ trayChecks.assertions
|
||||
++ subscriptionChecks.assertions
|
||||
@@ -246,4 +258,5 @@ in
|
||||
xray-jq-filter-runtime = xrayBackendChecks.runtime;
|
||||
per-app-zapret-runtime = perAppRoutingChecks.runtime;
|
||||
zapret-hostlist-rules = zapretChecks.rules;
|
||||
zapret2-config = zapret2Checks.runtime;
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "dup";
|
||||
@@ -29,7 +29,7 @@
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "proxy";
|
||||
@@ -44,7 +44,7 @@
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
|
||||
@@ -50,18 +50,14 @@ let
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy = {
|
||||
tun.perApp.enable = true;
|
||||
tproxy.perApp.enable = true;
|
||||
};
|
||||
zapret = {
|
||||
enable = true;
|
||||
perApp.enable = true;
|
||||
};
|
||||
zapret.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = false;
|
||||
proxychains.enable = true;
|
||||
tun.enable = true;
|
||||
tproxy.enable = true;
|
||||
zapret.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -102,12 +98,12 @@ in
|
||||
|
||||
# -- 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"
|
||||
assert pkgs.lib.hasInfix "help | -h | --help)" perAppRoutingProxychainsScript;
|
||||
assert pkgs.lib.hasInfix "Usage: proxy-ctl <group>" perAppRoutingProxychainsScript;
|
||||
assert pkgs.lib.hasInfix "local proxy backend" perAppRoutingProxychainsScript;
|
||||
assert pkgs.lib.hasInfix "restart active services"
|
||||
perAppRoutingProxychainsScript;
|
||||
assert pkgs.lib.hasInfix "wrap <profile> -- <cmd>" perAppRoutingProxychainsScript;
|
||||
assert pkgs.lib.hasInfix "apps run <profile> -- <cmd>" perAppRoutingProxychainsScript;
|
||||
assert pkgs.lib.hasInfix "apps" perAppRoutingProxychainsScript;
|
||||
true
|
||||
)
|
||||
|
||||
@@ -13,10 +13,10 @@ let
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tproxy.perApp.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
tproxy.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ let
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tun.perApp.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
tun.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -43,13 +43,11 @@ let
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy = {
|
||||
tproxy.enable = true;
|
||||
tun.perApp.enable = true;
|
||||
};
|
||||
proxy.tproxy.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
tun.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
}
|
||||
]
|
||||
|
||||
# route=tun requires proxy.tun.perApp.enable.
|
||||
# route=tun requires perAppRouting.tun.enable.
|
||||
[
|
||||
{
|
||||
services.proxy-suite.perAppRouting = {
|
||||
@@ -67,11 +67,11 @@
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy = {
|
||||
enable = false;
|
||||
tun.perApp.enable = true;
|
||||
proxy.enable = false;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
tun.enable = true;
|
||||
};
|
||||
perAppRouting.enable = true;
|
||||
};
|
||||
}
|
||||
]
|
||||
@@ -92,7 +92,7 @@
|
||||
}
|
||||
]
|
||||
|
||||
# route=tproxy requires proxy.tproxy.perApp.enable.
|
||||
# route=tproxy requires perAppRouting.tproxy.enable.
|
||||
[
|
||||
{
|
||||
services.proxy-suite.perAppRouting = {
|
||||
@@ -111,11 +111,11 @@
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy = {
|
||||
enable = false;
|
||||
tproxy.perApp.enable = true;
|
||||
proxy.enable = false;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
tproxy.enable = true;
|
||||
};
|
||||
perAppRouting.enable = true;
|
||||
};
|
||||
}
|
||||
]
|
||||
@@ -136,7 +136,7 @@
|
||||
}
|
||||
]
|
||||
|
||||
# route=zapret requires zapret.perApp.enable.
|
||||
# route=zapret requires perAppRouting.zapret.enable.
|
||||
[
|
||||
{
|
||||
services.proxy-suite = {
|
||||
|
||||
@@ -16,14 +16,12 @@ let
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
zapret = {
|
||||
enable = true;
|
||||
perApp.enable = true;
|
||||
};
|
||||
zapret.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
proxychains.enable = true;
|
||||
zapret.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -44,14 +42,12 @@ let
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
zapret = {
|
||||
enable = false;
|
||||
perApp.enable = true;
|
||||
};
|
||||
zapret.enable = false;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
proxychains.enable = true;
|
||||
zapret.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -69,11 +65,13 @@ let
|
||||
proxy.tun = {
|
||||
enable = true;
|
||||
interface = "test-global0";
|
||||
perApp.enable = true;
|
||||
perApp.interface = "test-app0";
|
||||
};
|
||||
perAppRouting.tun = {
|
||||
enable = true;
|
||||
interface = "test-app0";
|
||||
};
|
||||
zapret.enable = true;
|
||||
zapret.perApp.enable = perAppZapret;
|
||||
perAppRouting.zapret.enable = perAppZapret;
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
@@ -36,10 +36,10 @@ pkgs.testers.runNixOSTest {
|
||||
services.proxy-suite = {
|
||||
enable = true;
|
||||
proxy.enable = false;
|
||||
proxyInbounds = {
|
||||
inbounds = {
|
||||
enable = true;
|
||||
inherit serverAddress;
|
||||
via = "direct";
|
||||
routing.via = "direct";
|
||||
openFirewall = true;
|
||||
listeners.vless-in = {
|
||||
type = "vless";
|
||||
@@ -79,8 +79,8 @@ pkgs.testers.runNixOSTest {
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
port = 1080;
|
||||
backend = "xray";
|
||||
listener.port = 1080;
|
||||
outbounds = [
|
||||
{
|
||||
tag = "server";
|
||||
@@ -106,7 +106,7 @@ pkgs.testers.runNixOSTest {
|
||||
server.succeed(f"jq -e '.inbounds[] | select(.tag == \"ss-in\" and .port == 8388)' {cfg}")
|
||||
# Credentials live only in the runtime config, never in the store.
|
||||
server.succeed(f"test $(stat -c %a {cfg}) = 600")
|
||||
server.fail(f"grep -r '${uuid}' /nix/store/*proxy-suite-inbounds-*.json")
|
||||
server.fail("grep -r '${uuid}' /nix/store/*proxy-suite-inbounds-*.json")
|
||||
|
||||
with subtest("safety rules are present and ordered first"):
|
||||
cfg = "/run/proxy-suite-inbounds/config.json"
|
||||
@@ -138,7 +138,7 @@ pkgs.testers.runNixOSTest {
|
||||
assert link.startswith("vless://${uuid}@${serverAddress}:8443"), link
|
||||
assert "#tester" in link, link
|
||||
server.succeed("proxy-ctl inbounds | grep -q vless-in")
|
||||
server.succeed("proxy-ctl inbounds qr vless-in | head -c 1")
|
||||
server.succeed("proxy-ctl inbounds link vless-in --qr | head -c 1")
|
||||
server.succeed("proxy-ctl status | grep -q proxy-suite-inbounds")
|
||||
|
||||
with subtest("a listener keeps serving after a restart"):
|
||||
|
||||
@@ -24,10 +24,10 @@ let
|
||||
};
|
||||
|
||||
mkInbounds =
|
||||
proxyInbounds:
|
||||
inbounds:
|
||||
evalProxySuite [
|
||||
baseModule
|
||||
{ services.proxy-suite.proxyInbounds = { enable = true; } // proxyInbounds; }
|
||||
{ services.proxy-suite.inbounds = { enable = true; } // inbounds; }
|
||||
];
|
||||
|
||||
relayFixture = mkInbounds { listeners.vless-in = realityListener; };
|
||||
@@ -35,7 +35,7 @@ let
|
||||
relaySpec = mkInboundsSpec relayFixture;
|
||||
|
||||
exitFixture = mkInbounds {
|
||||
via = "direct";
|
||||
routing.via = "direct";
|
||||
listeners.vless-in = realityListener;
|
||||
};
|
||||
exitConfig = mkInboundsConfig exitFixture;
|
||||
@@ -57,7 +57,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "nl-vps";
|
||||
@@ -75,9 +75,9 @@ let
|
||||
}
|
||||
];
|
||||
};
|
||||
proxyInbounds = {
|
||||
inbounds = {
|
||||
enable = true;
|
||||
via = "nl-vps";
|
||||
routing.via = "nl-vps";
|
||||
listeners.through-nl = realityListener;
|
||||
listeners.through-de = realityListener // {
|
||||
port = 8443;
|
||||
@@ -104,10 +104,10 @@ let
|
||||
ipNamedConfig = mkInboundsConfig ipNamedFixture;
|
||||
|
||||
unguardedFixture = mkInbounds {
|
||||
|
||||
|
||||
blockRu = false;
|
||||
blockPrivate = false;
|
||||
routing = {
|
||||
blockRu = false;
|
||||
blockPrivate = false;
|
||||
};
|
||||
listeners.vless-in = realityListener;
|
||||
};
|
||||
unguardedConfig = mkInboundsConfig unguardedFixture;
|
||||
@@ -119,13 +119,12 @@ let
|
||||
port = 8388;
|
||||
users = [ { passwordFile = "/run/secrets/ss"; } ];
|
||||
};
|
||||
# Fronted by something else on this host, so its port stays closed even
|
||||
# though the share link advertises the public one.
|
||||
# Loopback-bound: the port stays closed though the link advertises the public one.
|
||||
listeners.ws-in = {
|
||||
type = "vless";
|
||||
port = 10002;
|
||||
sharePort = 443;
|
||||
listenAddress = "127.0.0.1";
|
||||
address = "127.0.0.1";
|
||||
users = [ { uuidFile = "/run/secrets/ws"; } ];
|
||||
transport = {
|
||||
type = "ws";
|
||||
@@ -137,6 +136,22 @@ let
|
||||
keyFile = "/run/acme/key.pem";
|
||||
};
|
||||
};
|
||||
# h3 only: UDP is opened, the TCP port stays free.
|
||||
listeners.h3-in = {
|
||||
type = "vless";
|
||||
port = 8443;
|
||||
users = [ { uuidFile = "/run/secrets/h3"; } ];
|
||||
transport = {
|
||||
type = "xhttp";
|
||||
path = "/h3";
|
||||
};
|
||||
tls = {
|
||||
enable = true;
|
||||
certificateFile = "/run/acme/fullchain.pem";
|
||||
keyFile = "/run/acme/key.pem";
|
||||
alpn = [ "h3" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
firewallSpec = mkInboundsSpec firewallFixture;
|
||||
wsListener = lib.head (builtins.filter (l: l.tag == "ws-in") firewallSpec.listeners);
|
||||
@@ -154,13 +169,28 @@ let
|
||||
|
||||
service = fixture: fixture.config.systemd.services."proxy-suite-inbounds";
|
||||
|
||||
# Bad configurations are checked by looking at config.assertions directly
|
||||
# rather than by forcing system.build.toplevel: it is far cheaper, and it
|
||||
# pins which assertion fired instead of just "something failed".
|
||||
# `proxy-ctl inbounds stats` reads the collected file, so userControl members need it.
|
||||
statsScript =
|
||||
fixture:
|
||||
(import ./read-generated.nix).readDerivation
|
||||
fixture.config.systemd.services."proxy-suite-inbound-stats".serviceConfig.ExecStart;
|
||||
noControlFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
inbounds.enable = true;
|
||||
inbounds.listeners.vless-in = realityListener;
|
||||
userControl.allow = [ ];
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
# Checked against config.assertions directly: cheaper than toplevel, and names the
|
||||
# assertion.
|
||||
baseProxy = {
|
||||
enable = true;
|
||||
proxy.enable = true;
|
||||
proxy.singBox.enable = true;
|
||||
proxy.backend = "sing-box";
|
||||
proxy.outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
@@ -183,15 +213,13 @@ let
|
||||
if lib.any (a: lib.hasInfix fragment a.message) failed then
|
||||
true
|
||||
else
|
||||
# Name what was expected and what actually failed, so a regression here
|
||||
# points at the assertion instead of just "something evaluated wrong".
|
||||
throw "proxy-inbounds check: expected an assertion matching '${fragment}', got: ${builtins.toJSON (map (a: a.message) failed)}";
|
||||
|
||||
failing = [
|
||||
(mkRejects (
|
||||
baseProxy
|
||||
// {
|
||||
proxyInbounds = {
|
||||
inbounds = {
|
||||
enable = true;
|
||||
listeners.bad = {
|
||||
type = "vless";
|
||||
@@ -204,7 +232,7 @@ let
|
||||
(mkRejects (
|
||||
baseProxy
|
||||
// {
|
||||
proxyInbounds = {
|
||||
inbounds = {
|
||||
enable = true;
|
||||
listeners.a = realityListener;
|
||||
listeners.b = realityListener;
|
||||
@@ -215,9 +243,9 @@ let
|
||||
(mkRejects {
|
||||
enable = true;
|
||||
proxy.enable = false;
|
||||
proxyInbounds = {
|
||||
inbounds = {
|
||||
enable = true;
|
||||
via = "proxy";
|
||||
routing.via = "proxy";
|
||||
listeners.vless-in = realityListener;
|
||||
};
|
||||
} "requires proxy.enable = true")
|
||||
@@ -225,7 +253,7 @@ let
|
||||
(mkRejects (
|
||||
baseProxy
|
||||
// {
|
||||
proxyInbounds = {
|
||||
inbounds = {
|
||||
enable = true;
|
||||
listeners.vless-in = realityListener // {
|
||||
reality = realityListener.reality // {
|
||||
@@ -239,7 +267,7 @@ let
|
||||
(mkRejects (
|
||||
baseProxy
|
||||
// {
|
||||
proxyInbounds = {
|
||||
inbounds = {
|
||||
enable = true;
|
||||
listeners.tls-in = {
|
||||
type = "vless";
|
||||
@@ -254,7 +282,7 @@ let
|
||||
(mkRejects (
|
||||
baseProxy
|
||||
// {
|
||||
proxyInbounds = {
|
||||
inbounds = {
|
||||
enable = true;
|
||||
listeners.ws-in = realityListener // {
|
||||
transport.type = "ws";
|
||||
@@ -266,9 +294,9 @@ let
|
||||
(mkRejects (
|
||||
baseProxy
|
||||
// {
|
||||
proxyInbounds = {
|
||||
inbounds = {
|
||||
enable = true;
|
||||
via = "no-such-outbound";
|
||||
routing.via = "no-such-outbound";
|
||||
listeners.vless-in = realityListener;
|
||||
};
|
||||
}
|
||||
@@ -277,46 +305,47 @@ let
|
||||
(mkRejects {
|
||||
enable = true;
|
||||
proxy.enable = true;
|
||||
proxy.singBox.enable = true;
|
||||
proxy.backend = "sing-box";
|
||||
proxy.outbounds = [
|
||||
{
|
||||
tag = "sb-only";
|
||||
singBoxJson.type = "tuic";
|
||||
}
|
||||
];
|
||||
proxyInbounds = {
|
||||
inbounds = {
|
||||
enable = true;
|
||||
via = "sb-only";
|
||||
routing.via = "sb-only";
|
||||
listeners.vless-in = realityListener;
|
||||
};
|
||||
} "targets a sing-box-only outbound")
|
||||
|
||||
(mkRejects (baseProxy // { proxyInbounds.enable = true; })
|
||||
"requires at least one entry in proxyInbounds.listeners"
|
||||
(mkRejects (baseProxy // { inbounds.enable = true; })
|
||||
"requires at least one entry in inbounds.listeners"
|
||||
)
|
||||
|
||||
# recursiveUpdate, not //: this one nests into proxy, which baseProxy sets.
|
||||
(mkRejects
|
||||
(lib.recursiveUpdate baseProxy {
|
||||
proxy.port = 1080;
|
||||
proxyInbounds = {
|
||||
proxy.listener.port = 1080;
|
||||
inbounds = {
|
||||
enable = true;
|
||||
listeners.clash = realityListener // {
|
||||
port = 1080;
|
||||
};
|
||||
};
|
||||
})
|
||||
"collides with proxy.port"
|
||||
"collides with proxy.listener.port"
|
||||
)
|
||||
];
|
||||
|
||||
assertions = [
|
||||
# The template carries no listeners; they are rendered at start time so no
|
||||
# credential reaches the Nix store.
|
||||
# Listeners are rendered at start time.
|
||||
(assert relayConfig.inbounds == [ ]; true)
|
||||
|
||||
# Relaying goes through the client stack's local SOCKS listener rather than
|
||||
# a second copy of the outbound machinery.
|
||||
# AsIs when relayed through sing-box; IPOnDemand when XRay dials (see the template).
|
||||
(assert relayConfig.routing.domainStrategy == "AsIs"; true)
|
||||
(assert exitConfig.routing.domainStrategy == "IPOnDemand"; true)
|
||||
|
||||
(assert hasOutbound relayConfig "proxy"; true)
|
||||
(assert (ruleByTag relayConfig "inbound-final").outboundTag == "proxy"; true)
|
||||
(
|
||||
@@ -342,15 +371,13 @@ let
|
||||
(assert !hasOutbound exitConfig "proxy"; true)
|
||||
(assert (ruleByTag exitConfig "inbound-final").outboundTag == "direct"; true)
|
||||
|
||||
# Safety rules are on by default and come before anything else, so an
|
||||
# inbound credential cannot reach the LAN or loopback.
|
||||
# Safety rules come first.
|
||||
(assert builtins.head (ruleTags relayConfig) == "inbound-block-private"; true)
|
||||
(assert (ruleByTag relayConfig "inbound-block-private").outboundTag == "block"; true)
|
||||
(assert (ruleByTag relayConfig "inbound-block-ru-domain").domain == [ "geosite:category-ru" ]; true)
|
||||
(assert (ruleByTag relayConfig "inbound-block-ru-ip").ip == [ "geoip:ru" ]; true)
|
||||
(assert !builtins.elem "inbound-block-private" (ruleTags unguardedConfig); true)
|
||||
# The relay must not blackhole the address clients dial to reach it, and the
|
||||
# exemption has to sit after blockPrivate but ahead of the country blocks.
|
||||
# serverAddress is exempt after blockPrivate, before the country blocks.
|
||||
(
|
||||
assert
|
||||
lib.take 3 (ruleTags namedConfig) == [
|
||||
@@ -380,12 +407,10 @@ let
|
||||
(assert (ruleByTag mixedConfig "inbound-via-local-exit").inboundTag == [ "local-exit" ]; true)
|
||||
(assert (ruleByTag mixedConfig "inbound-via-local-exit").outboundTag == "direct"; true)
|
||||
|
||||
# Two listeners can leave through two different servers: the pinned one
|
||||
# gets its own rule, the default one rides the final rule.
|
||||
# The pinned listener gets its own rule; the default one rides the final rule.
|
||||
(assert (ruleByTag pinnedConfig "inbound-via-through-de").outboundTag == "de-vps"; true)
|
||||
(assert (ruleByTag pinnedConfig "inbound-final").outboundTag == "nl-vps"; true)
|
||||
# Pinned outbounds are injected at start time, not baked into the template,
|
||||
# and chaining through the local proxy is not needed for either of them.
|
||||
# Pinned outbounds are injected at start and need no local proxy.
|
||||
(assert !hasOutbound pinnedConfig "proxy"; true)
|
||||
(assert outboundTags pinnedConfig == [ "direct" "block" ]; true)
|
||||
# Only referenced outbounds are rendered, so the sing-box-only one is fine.
|
||||
@@ -427,9 +452,14 @@ let
|
||||
];
|
||||
true
|
||||
)
|
||||
(assert firewallFixture.config.networking.firewall.allowedUDPPorts == [ 8388 ]; true)
|
||||
# A loopback-bound listener is fronted on this host; opening its port would
|
||||
# expose what the arrangement hides.
|
||||
(
|
||||
assert
|
||||
lib.sort lib.lessThan firewallFixture.config.networking.firewall.allowedUDPPorts == [
|
||||
8388
|
||||
8443
|
||||
];
|
||||
true
|
||||
)
|
||||
(assert wsListener.port == 10002 && wsListener.sharePort == 443; true)
|
||||
(assert noFirewallFixture.config.networking.firewall.allowedTCPPorts == [ ]; true)
|
||||
|
||||
@@ -440,6 +470,15 @@ let
|
||||
# Not `requires`: direct-routed listeners keep serving if the client is down.
|
||||
(assert (service relayFixture).requires == [ ]; true)
|
||||
|
||||
# The collected stats are group-readable with userControl, root-only without.
|
||||
(
|
||||
assert lib.hasInfix "chgrp proxy-suite \"$tmp\"" (statsScript relayFixture);
|
||||
assert lib.hasInfix "chmod 640 \"$tmp\"" (statsScript relayFixture);
|
||||
assert !lib.hasInfix "chgrp" (statsScript noControlFixture);
|
||||
assert lib.hasInfix "chmod 600 \"$tmp\"" (statsScript noControlFixture);
|
||||
true
|
||||
)
|
||||
|
||||
]
|
||||
++ failing;
|
||||
in
|
||||
|
||||
+640
-3
@@ -31,7 +31,7 @@
|
||||
options-doc =
|
||||
pkgs.runCommand "proxy-suite-options-doc-check" { nativeBuildInputs = [ pkgs.diffutils ]; }
|
||||
''
|
||||
diff -u ${../../docs/options.md} ${generatedOptionsDoc}
|
||||
diff -ru ${../../docs/options} ${generatedOptionsDoc}
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
@@ -78,7 +78,10 @@
|
||||
PROXYCHAINS_QUIET_ARG="" \
|
||||
ROUTE_MODE_STATE_FILE="$PWD/route-mode" \
|
||||
DEFAULT_ROUTE_MODE="blacklist" \
|
||||
bash "$proxy_ctl" subscription list > output
|
||||
bash "$proxy_ctl" proxy subs list > output
|
||||
# The old spelling still dispatches.
|
||||
env SUB_TAGS_FILE="$PWD/tags.json" SUB_CACHE_DIR="$PWD/cache" \
|
||||
bash "$proxy_ctl" subscription list | cmp - output
|
||||
|
||||
awk '$1 == "plain" { found = 1; if ($NF != "2") exit 1 } END { exit found ? 0 : 1 }' output
|
||||
awk '$1 == "hybrid" { found = 1; if ($NF != "3") exit 1 } END { exit found ? 0 : 1 }' output
|
||||
@@ -87,6 +90,641 @@
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
proxy-ctl-outbounds =
|
||||
pkgs.runCommand "proxy-suite-proxy-ctl-outbounds-check"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
pkgs.bash
|
||||
pkgs.coreutils
|
||||
pkgs.curl
|
||||
pkgs.gawk
|
||||
pkgs.gnugrep
|
||||
pkgs.jq
|
||||
];
|
||||
}
|
||||
''
|
||||
proxy_ctl="$TMPDIR/proxy-ctl"
|
||||
cat ${../../pkgs/proxy-ctl-lib.sh} ${../../pkgs/proxy-ctl.sh} > "$proxy_ctl"
|
||||
chmod +x "$proxy_ctl"
|
||||
|
||||
# systemd is not in the sandbox. The reload stub stands in for the start
|
||||
# script, which is what actually republishes the inventory.
|
||||
mkdir -p stub
|
||||
{
|
||||
printf '%s\n' '#!/bin/sh'
|
||||
printf '%s\n' 'if [ "$1" = start ] && [ "$2" = proxy-suite-outbound-reload.service ]; then'
|
||||
printf '%s\n' ' ls "$RUNTIME_OUTBOUNDS_DIR" > "$OUTBOUND_INVENTORY_FILE.spool"'
|
||||
printf '%s\n' ' jq --rawfile spool "$OUTBOUND_INVENTORY_FILE.spool" '"'"'($spool | split("\n") | map(select(endswith(".url")) | rtrimstr(".url"))) as $new | .tags = (.tags + $new | unique) | .sources = reduce $new[] as $t (.sources; .[$t] = "runtime")'"'"' "$OUTBOUND_INVENTORY_FILE" > "$OUTBOUND_INVENTORY_FILE.tmp"'
|
||||
printf '%s\n' ' mv "$OUTBOUND_INVENTORY_FILE.tmp" "$OUTBOUND_INVENTORY_FILE"'
|
||||
printf '%s\n' 'fi'
|
||||
printf '%s\n' 'exit 0'
|
||||
} > stub/systemctl
|
||||
printf '#!/bin/sh\nprintf %%s "$2"\n' > stub/systemd-escape
|
||||
chmod +x stub/systemctl stub/systemd-escape
|
||||
export PATH="$PWD/stub:$PATH"
|
||||
|
||||
mkdir -p obd subd cache
|
||||
printf '%s\n' '["community"]' > tags.json
|
||||
jq -n '{tags:["own-vps","community-de"],
|
||||
sources:{"own-vps":"static","community-de":"sub:community"},
|
||||
pinned:"community-de", selection:"urltest"}' > inventory.json
|
||||
|
||||
run() {
|
||||
env \
|
||||
SUB_TAGS_FILE="$PWD/tags.json" \
|
||||
SUB_CACHE_DIR="$PWD/cache" \
|
||||
OUTBOUND_INVENTORY_FILE="$PWD/inventory.json" \
|
||||
RUNTIME_OUTBOUNDS_DIR="$PWD/obd" \
|
||||
RUNTIME_SUBS_DIR="$PWD/subd" \
|
||||
USER_CONTROL_GROUP="proxy-suite" \
|
||||
CLASH_API="http://127.0.0.1:1" \
|
||||
SELECTION="urltest" \
|
||||
PER_APP_ROUTING_ENABLED="0" \
|
||||
PER_APP_ROUTING_PROXYCHAINS_ENABLED="0" \
|
||||
PER_APP_ROUTING_TUN_ENABLED="0" \
|
||||
PER_APP_ROUTING_TPROXY_ENABLED="0" \
|
||||
PER_APP_ROUTING_ZAPRET_ENABLED="0" \
|
||||
PER_APP_ROUTING_PROFILES_FILE="$PWD/profiles.json" \
|
||||
PROXYCHAINS_CONFIG="$PWD/proxychains.conf" \
|
||||
PROXYCHAINS_QUIET_ARG="" \
|
||||
ROUTE_MODE_STATE_FILE="$PWD/route-mode" \
|
||||
DEFAULT_ROUTE_MODE="blacklist" \
|
||||
bash "$proxy_ctl" "$@"
|
||||
}
|
||||
|
||||
# Listing works from the inventory alone, with no Clash API answering.
|
||||
run proxy outbounds > listing
|
||||
grep -q 'Selection: urltest' listing
|
||||
grep -q 'Pinned: community-de' listing
|
||||
grep -q '\*community-de' listing
|
||||
grep -q 'own-vps *static' listing
|
||||
# The old spelling still dispatches.
|
||||
run outbounds | cmp - listing
|
||||
|
||||
# Reserved and malformed tags are refused before anything is written.
|
||||
for bad in proxy direct block "has space" "-leading"; do
|
||||
if run proxy outbounds add "$bad" http://example.com:1 2>/dev/null; then
|
||||
echo "accepted invalid tag: $bad" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
# Tags that already exist are refused too, declared or not.
|
||||
! run proxy outbounds add own-vps http://example.com:1 2>/dev/null
|
||||
! run proxy subs add community https://example.com/sub 2>/dev/null
|
||||
# A URL with whitespace is refused.
|
||||
! run proxy outbounds add ok-tag "http://example.com:1 x" 2>/dev/null
|
||||
# Nothing above touched the spool.
|
||||
[ -z "$(ls -A obd)" ]
|
||||
|
||||
# Removing something that was never added says so.
|
||||
! run proxy outbounds rm nope 2>/dev/null
|
||||
|
||||
# A good add lands in the spool group-readable, not world-readable.
|
||||
run proxy outbounds add spool-one http://example.com:1 | grep -q 'Added outbound: spool-one'
|
||||
[ "$(cat obd/spool-one.url)" = "http://example.com:1" ]
|
||||
[ "$(stat -c %a obd/spool-one.url)" = "640" ]
|
||||
run proxy outbounds | grep -q 'spool-one *runtime'
|
||||
# Adding it twice is refused.
|
||||
! run proxy outbounds add spool-one http://example.com:1 2>/dev/null
|
||||
run proxy outbounds rm spool-one | grep -q 'Removed outbound: spool-one'
|
||||
[ ! -e obd/spool-one.url ]
|
||||
|
||||
# Subscriptions use the same spool machinery, verified by cache file.
|
||||
printf '%s\n' '[{},{}]' > cache/extra.json
|
||||
run proxy subs add extra https://example.com/sub | grep -q 'Added subscription: extra (2 proxies)'
|
||||
run proxy subs list > subs
|
||||
grep -q 'community .* static' subs
|
||||
grep -q 'extra .* runtime' subs
|
||||
|
||||
# A spool entry the backend refused is reported, not silently accepted.
|
||||
run proxy subs add rejected https://example.com/sub > rejected 2>&1 && exit 1
|
||||
grep -q 'did not come up' rejected
|
||||
|
||||
# Pinning goes through the unit, including "auto".
|
||||
run proxy select community-de | grep -q 'Pinned: community-de'
|
||||
run proxy select auto | grep -q 'Selecting automatically again'
|
||||
# Without a terminal and without a tag there is nothing to pick from.
|
||||
! run proxy select </dev/null 2>/dev/null
|
||||
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
proxy-ctl-zapret-auto =
|
||||
pkgs.runCommand "proxy-suite-proxy-ctl-zapret-auto-check"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
pkgs.bash
|
||||
pkgs.coreutils
|
||||
pkgs.gnugrep
|
||||
];
|
||||
}
|
||||
''
|
||||
proxy_ctl="$TMPDIR/proxy-ctl"
|
||||
cat ${../../pkgs/proxy-ctl-lib.sh} ${../../pkgs/proxy-ctl.sh} > "$proxy_ctl"
|
||||
|
||||
state="$PWD/state"
|
||||
mkdir -p "$state"
|
||||
printf 'blocked.example\nother.example\n' > "$state/zapret-hosts-auto.txt"
|
||||
: > "$state/zapret-hosts-user.txt"
|
||||
: > "$state/zapret-hosts-user-exclude.txt"
|
||||
|
||||
run() {
|
||||
env ZAPRET_AUTO_ENABLED=1 ZAPRET_STATE_DIR="$state" bash "$proxy_ctl" zapret auto "$@"
|
||||
}
|
||||
|
||||
run list | grep -qx blocked.example
|
||||
|
||||
# exclude must also blacklist, or the host is relearned.
|
||||
run exclude blocked.example > /dev/null
|
||||
! grep -qx blocked.example "$state/zapret-hosts-auto.txt"
|
||||
grep -qx blocked.example "$state/zapret-hosts-user-exclude.txt"
|
||||
|
||||
# Pinning is idempotent, so repeated runs cannot grow the list.
|
||||
run add pinned.example > /dev/null
|
||||
run add pinned.example > /dev/null
|
||||
test "$(grep -c -x pinned.example "$state/zapret-hosts-user.txt")" = 1
|
||||
|
||||
# The lists stay readable by unprivileged proxy-ctl after a rewrite.
|
||||
test "$(stat -c %a "$state/zapret-hosts-user.txt")" = 644
|
||||
|
||||
run clear > /dev/null
|
||||
run list | grep -q 'No hostnames learned'
|
||||
|
||||
# Without the zapret2 engine there is nothing to inspect.
|
||||
! env ZAPRET_AUTO_ENABLED=0 ZAPRET_STATE_DIR="$state" bash "$proxy_ctl" zapret auto list
|
||||
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
proxy-ctl-complete =
|
||||
pkgs.runCommand "proxy-suite-proxy-ctl-complete-check"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
pkgs.bash
|
||||
pkgs.coreutils
|
||||
pkgs.gawk
|
||||
pkgs.gnugrep
|
||||
pkgs.jq
|
||||
];
|
||||
}
|
||||
''
|
||||
proxy_ctl="$TMPDIR/proxy-ctl"
|
||||
cat ${../../pkgs/proxy-ctl-lib.sh} ${../../pkgs/proxy-ctl.sh} > "$proxy_ctl"
|
||||
|
||||
printf '%s\n' '["home","work"]' > awg.json
|
||||
jq -n '[{name:"torrent",route:"direct"}]' > profiles.json
|
||||
jq -n '{tags:["own-vps","community-de"]}' > inventory.json
|
||||
|
||||
run() {
|
||||
env AWG_PROFILES_FILE="$PWD/awg.json" \
|
||||
PER_APP_ROUTING_PROFILES_FILE="$PWD/profiles.json" \
|
||||
OUTBOUND_INVENTORY_FILE="$PWD/inventory.json" \
|
||||
bash "$proxy_ctl" __complete "$@"
|
||||
}
|
||||
|
||||
# Every group the help lists must complete, or the table has drifted.
|
||||
bash "$proxy_ctl" help | awk '/^ [a-z]/ { print $1 }' | sort -u > groups
|
||||
run > top
|
||||
while read -r group; do
|
||||
grep -qx "$group" top || { echo "help lists $group, completion does not" >&2; exit 1; }
|
||||
done < groups
|
||||
|
||||
# Piping into `grep -q` would race the script against SIGPIPE.
|
||||
has() {
|
||||
local want="$1"
|
||||
shift
|
||||
run "$@" > words
|
||||
grep -qx "$want" words
|
||||
}
|
||||
|
||||
has outbounds proxy
|
||||
has all-bypass proxy mode
|
||||
has exclude zapret auto
|
||||
has proxy-suite-awg-work logs
|
||||
has work awg on
|
||||
has torrent apps run
|
||||
has auto proxy select
|
||||
has community-de proxy select
|
||||
|
||||
# A shell completing must never die, however unreadable the state is.
|
||||
run inbounds link | cmp - /dev/null
|
||||
env AWG_PROFILES_FILE=/nonexistent bash "$proxy_ctl" __complete awg on
|
||||
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
proxy-ctl-where =
|
||||
pkgs.runCommand "proxy-suite-proxy-ctl-where-check"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
pkgs.bash
|
||||
pkgs.coreutils
|
||||
pkgs.gnugrep
|
||||
pkgs.jq
|
||||
];
|
||||
}
|
||||
''
|
||||
proxy_ctl="$TMPDIR/proxy-ctl"
|
||||
cat ${../../pkgs/proxy-ctl-lib.sh} ${../../pkgs/proxy-ctl.sh} > "$proxy_ctl"
|
||||
|
||||
mkdir -p ap zap
|
||||
jq -n '{domains:{"spotify.com":{exit:"community-de",host:"open.spotify.com",at:0}}}' > ap/state.json
|
||||
printf 'nyt.com\n' > zap/zapret-hosts-auto.txt
|
||||
printf 'discord.com\n' > zap/zapret-hosts-user.txt
|
||||
printf 'ok.ru\n' > zap/zapret-hosts-user-exclude.txt
|
||||
|
||||
run() {
|
||||
env AUTOPROXY_ENABLED=1 AUTOPROXY_STATE_DIR="$PWD/ap" \
|
||||
ZAPRET_AUTO_ENABLED=1 ZAPRET_STATE_DIR="$PWD/zap" \
|
||||
bash "$proxy_ctl" where "$@"
|
||||
}
|
||||
|
||||
# Piping into `grep -q` would race the script against SIGPIPE.
|
||||
verdict() {
|
||||
run "$1" > where
|
||||
grep -q -- "$2" where
|
||||
}
|
||||
|
||||
# Both stores key on an apex, so a subdomain has to match its parent.
|
||||
verdict open.spotify.com '-> proxied via community-de'
|
||||
grep -q 'autoProxy .*routed via community-de' where
|
||||
# What proxy-ctl cannot see has to be said out loud.
|
||||
grep -q 'proxy.routing.rules are not visible' where
|
||||
|
||||
verdict discord.com '-> direct, with the zapret2 bypass'
|
||||
verdict nyt.com '-> direct, with the zapret2 bypass'
|
||||
# Excluded is not bypassed: it must not read as a zapret2 verdict.
|
||||
verdict ok.ru '-> nothing runtime matches it'
|
||||
verdict example.org '-> nothing runtime matches it'
|
||||
|
||||
# A URL is accepted where a hostname is.
|
||||
verdict https://open.spotify.com/track/x '^ domain *open.spotify.com$'
|
||||
|
||||
! bash "$proxy_ctl" where 2>/dev/null
|
||||
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
# The verdict table, fed tuples measured on a real censored network.
|
||||
proxy-ctl-proxy-probe =
|
||||
pkgs.runCommand "proxy-suite-proxy-ctl-proxy-probe-check"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
pkgs.bash
|
||||
pkgs.coreutils
|
||||
pkgs.gnugrep
|
||||
pkgs.jq
|
||||
];
|
||||
}
|
||||
''
|
||||
cat > "$TMPDIR/test.sh" <<'EOF'
|
||||
set -euo pipefail
|
||||
. ${../../pkgs/proxy-ctl-lib.sh}
|
||||
|
||||
expect() {
|
||||
local want="$1" direct="$2" via="$3" got
|
||||
got="$(_probe_verdict "$direct" "$via")"
|
||||
if [ "$got" != "$want" ]; then
|
||||
echo "FAIL: expected $want, got $got" >&2
|
||||
echo " direct=$direct" >&2
|
||||
echo " proxy =$via" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Origin refuses direct, accepts the proxy: chatgpt.com/robots.txt.
|
||||
expect destination '0|0.146175|403|6633|' '0|0.230116|200|4302|'
|
||||
|
||||
# The same through a redirect: claude.ai/robots.txt.
|
||||
expect destination \
|
||||
'0|0.141625|302|143|https://claude.com/app-unavailable-in-region' \
|
||||
'0|0.181276|200|281|'
|
||||
|
||||
# TLS never completed: censorship, zapret's job.
|
||||
expect censor '35|0.000000|000|0|' '0|0.119348|200|6258|'
|
||||
|
||||
# Handshake, then silence: the post-handshake throttle.
|
||||
expect censor '0|0.125029|000|0|' '0|0.143772|200|32881|'
|
||||
|
||||
# Direct works. Nothing to do, whoever else also works.
|
||||
expect ok '0|0.099546|200|2678|' '0|0.146822|200|2678|'
|
||||
|
||||
# robots.txt legitimately absent is not a failure.
|
||||
expect ok '0|0.161330|404|559|' '0|0.214667|404|559|'
|
||||
|
||||
# An ordinary redirect must not read as a block.
|
||||
expect ok \
|
||||
'0|0.10|301|0|https://www.example.com/robots.txt' \
|
||||
'0|0.20|301|0|https://www.example.com/robots.txt'
|
||||
|
||||
# Refused everywhere: not an egress problem.
|
||||
expect both-fail '0|0.10|403|100|' '0|0.20|403|100|'
|
||||
|
||||
# Nothing reaches it at all - a dead name, not a blocked one.
|
||||
expect unreachable '6|0.000000|000|0|' '35|0.000000|000|0|'
|
||||
|
||||
# --- redirect chains ---
|
||||
# spotify.com: the block is four same-site hops in.
|
||||
curl() {
|
||||
local url
|
||||
for url; do :; done
|
||||
echo x >> "$TMPDIR/curl-calls"
|
||||
case "$url" in
|
||||
https://spotify.test/) printf '0|0.1|301|0|https://www.spotify.test/' ;;
|
||||
https://www.spotify.test/) printf '0|0.1|301|0|https://open.spotify.test/' ;;
|
||||
https://open.spotify.test/) printf '0|0.1|302|93|https://accounts.spotify.test/login' ;;
|
||||
https://accounts.spotify.test/login)
|
||||
printf '0|0.1|301|0|https://www.spotify.test/int/why-not-available/' ;;
|
||||
https://redir.test/) printf '0|0.1|301|0|https://elsewhere.example/' ;;
|
||||
https://loop.test/) printf '0|0.1|301|0|https://loop.test/' ;;
|
||||
*) printf '0|0.1|200|10|' ;;
|
||||
esac
|
||||
}
|
||||
test "$(_probe_exit_verdict "$(_probe_fetch spotify.test / --noproxy '*')")" = blocked
|
||||
# Leaving the site ends the walk.
|
||||
test "$(_probe_exit_verdict "$(_probe_fetch redir.test / --noproxy '*')")" = ok
|
||||
# A redirect loop inside the site still stops.
|
||||
: > "$TMPDIR/curl-calls"
|
||||
_probe_fetch loop.test / --noproxy '*' > /dev/null
|
||||
test "$(wc -l < "$TMPDIR/curl-calls")" -le 6
|
||||
unset -f curl
|
||||
|
||||
# --- which path decides: the apex, robots.txt only breaks ties ---
|
||||
_svc_active() { return 0; }
|
||||
# No listener index: only this host and the local proxy.
|
||||
PROBE_EXITS_FILE=/nonexistent
|
||||
|
||||
# A curl that cannot start is an error, not a dead site.
|
||||
! (PROBE_CURL=/nonexistent cmd_proxy_probe --json x.test) 2> "$TMPDIR/curl-err"
|
||||
grep -q 'Cannot run /nonexistent' "$TMPDIR/curl-err"
|
||||
|
||||
probe_with() {
|
||||
# $1 apex-direct $2 apex-proxy $3 robots-direct $4 robots-proxy
|
||||
_probe_fetch() {
|
||||
case "$2" in
|
||||
/) [ "$3" = --noproxy ] && printf '%s' "$APEX_DIRECT" || printf '%s' "$APEX_PROXY" ;;
|
||||
*) [ "$3" = --noproxy ] && printf '%s' "$ROBOTS_DIRECT" || printf '%s' "$ROBOTS_PROXY" ;;
|
||||
esac
|
||||
}
|
||||
APEX_DIRECT="$1" APEX_PROXY="$2" ROBOTS_DIRECT="$3" ROBOTS_PROXY="$4" \
|
||||
cmd_proxy_probe --json example.test
|
||||
}
|
||||
|
||||
# last.fm: apex geo-blocked, robots.txt served everywhere.
|
||||
out="$(probe_with '0|0.11|403|424|' '0|0.17|200|59809|' '0|0.11|200|400|' '0|0.17|200|400|')"
|
||||
grep -q '"verdict":"destination"' <<<"$out"
|
||||
grep -q '"url":"https://example.test/"' <<<"$out"
|
||||
|
||||
# chatgpt.com: apex 403 everywhere, robots.txt separates.
|
||||
out="$(probe_with '0|0.14|403|6633|' '0|0.23|403|8442|' '0|0.14|403|6633|' '0|0.23|200|4302|')"
|
||||
grep -q '"verdict":"destination"' <<<"$out"
|
||||
grep -q '"url":"https://example.test/robots.txt"' <<<"$out"
|
||||
|
||||
# A working apex is never second-guessed by the fallback path.
|
||||
out="$(probe_with '0|0.10|200|500|' '0|0.20|200|500|' '0|0.10|403|10|' '0|0.20|200|10|')"
|
||||
grep -q '"verdict":"ok"' <<<"$out"
|
||||
|
||||
# --- walking more than two exits ---
|
||||
# Direct and the first proxy share a WAF; only the third exit gets through.
|
||||
printf '%s' '[{"i":0,"tag":"direct","port":18540},
|
||||
{"i":1,"tag":"fi","port":18541},{"i":2,"tag":"de","port":18542}]' \
|
||||
> "$TMPDIR/exits.json"
|
||||
PROBE_EXITS_FILE="$TMPDIR/exits.json"
|
||||
_probe_fetch() {
|
||||
# every exit, direct included, goes through its pinned listener
|
||||
case "$4" in
|
||||
*:18540 | *:18541) printf '0|0.10|403|919|' ;;
|
||||
*:18542) printf '0|0.10|200|500|' ;;
|
||||
esac
|
||||
}
|
||||
out="$(cmd_proxy_probe --json sekai.test)"
|
||||
jq -e '.verdict == "destination" and .exit == "de"' <<<"$out" > /dev/null
|
||||
|
||||
# --exits restricts and orders the walk; direct is always tried first.
|
||||
out="$(cmd_proxy_probe --json --exits de sekai.test)"
|
||||
jq -e '[.exits[].tag] == ["direct", "de"]' <<<"$out" > /dev/null
|
||||
|
||||
# An empty list probes direct only (every exit shares one network).
|
||||
out="$(cmd_proxy_probe --json --exits "" sekai.test)"
|
||||
jq -e '([.exits[].tag] | unique) == ["direct"] and .exit == null' <<<"$out" > /dev/null
|
||||
|
||||
# --via: can this exit carry what direct reaches?
|
||||
out="$(cmd_proxy_probe --json --via de sekai.test)"
|
||||
jq -e '.verdict == "ok" and ([.exits[].tag] | unique) == ["de", "direct"]' <<<"$out" > /dev/null
|
||||
out="$(cmd_proxy_probe --json --via fi sekai.test)"
|
||||
jq -e '.verdict == "blocked"' <<<"$out" > /dev/null
|
||||
! (cmd_proxy_probe --json --via nowhere sekai.test) 2> /dev/null
|
||||
# A given path is probed as is, for that probe only.
|
||||
out="$(cmd_proxy_probe --json --via de sekai.test/robots.txt)"
|
||||
jq -e '.url == "https://sekai.test/robots.txt" and ([.exits[].path] | unique) == ["/robots.txt"]' \
|
||||
<<<"$out" > /dev/null
|
||||
out="$(cmd_proxy_probe --json --via fi sekai.test)"
|
||||
jq -e '([.exits[].path] | unique) == ["/", "/robots.txt"]' <<<"$out" > /dev/null
|
||||
|
||||
# Refused a front page direct gets: not a stand-in (www.reddit.com).
|
||||
_probe_fetch() {
|
||||
case "$4:$2" in
|
||||
*:18541:/) printf '0|0.10|403|190240|' ;;
|
||||
*) printf '0|0.10|200|500|' ;;
|
||||
esac
|
||||
}
|
||||
out="$(cmd_proxy_probe --json --via fi geo.test)"
|
||||
jq -e '.verdict == "blocked"' <<<"$out" > /dev/null
|
||||
# i.pximg.net: the front page is 400 everywhere, so robots.txt decides.
|
||||
_probe_fetch() {
|
||||
case "$2" in
|
||||
/) printf '0|0.10|400|0|' ;;
|
||||
*) printf '0|0.10|200|43|' ;;
|
||||
esac
|
||||
}
|
||||
out="$(cmd_proxy_probe --json --via fi cdn.test)"
|
||||
jq -e '.verdict == "ok"' <<<"$out" > /dev/null
|
||||
|
||||
# --- proxy-ctl proxy auto learn ---
|
||||
learn_dir="$TMPDIR/learn"
|
||||
mkdir -p "$learn_dir"
|
||||
systemctl() {
|
||||
# stands in for the requests-only run
|
||||
printf '%s' '{"domains":{"last.fm":{"verdict":"destination","exit":"primary","host":"www.last.fm"}},
|
||||
"hosts":{"www.last.fm":{"domain":"last.fm","verdict":"destination","exit":"primary"}}}' \
|
||||
> "$learn_dir/state.json"
|
||||
}
|
||||
! (AUTOPROXY_ENABLED=0 cmd_proxy_learn www.last.fm) 2> /dev/null
|
||||
# It lands in a root-owned file and then in a URL: hostnames only.
|
||||
! (AUTOPROXY_ENABLED=1 AUTOPROXY_STATE_DIR="$learn_dir" cmd_proxy_learn 'x;rm -rf /') 2> /dev/null
|
||||
! (AUTOPROXY_ENABLED=1 AUTOPROXY_STATE_DIR="$learn_dir" cmd_proxy_learn '-evil.test/path') 2> /dev/null
|
||||
out="$(AUTOPROXY_ENABLED=1 AUTOPROXY_STATE_DIR="$learn_dir" cmd_proxy_learn www.last.fm)"
|
||||
test "$(cat "$learn_dir/requests")" = www.last.fm
|
||||
grep -q 'last.fm: destination - routed via primary' <<<"$out"
|
||||
|
||||
# A verdict that routes nothing is kept for its host and reported.
|
||||
systemctl() {
|
||||
printf '%s' '{"domains":{},
|
||||
"hosts":{"api.example.test":{"domain":"example.test","verdict":"ok","exit":null}}}' \
|
||||
> "$learn_dir/state.json"
|
||||
}
|
||||
out="$(AUTOPROXY_ENABLED=1 AUTOPROXY_STATE_DIR="$learn_dir" cmd_proxy_learn api.example.test)"
|
||||
grep -q 'api.example.test: ok - nothing to route' <<<"$out"
|
||||
|
||||
# A failed run is reported in plain words, and the request is not lost.
|
||||
systemctl() { return 1; }
|
||||
: > "$learn_dir/requests"
|
||||
! (AUTOPROXY_ENABLED=1 AUTOPROXY_STATE_DIR="$learn_dir" cmd_proxy_learn www.last.fm) 2> "$TMPDIR/learn-err"
|
||||
grep -q 'still queued' "$TMPDIR/learn-err"
|
||||
grep -qx www.last.fm "$learn_dir/requests"
|
||||
|
||||
# --- queue and learned ----------------------------------------------
|
||||
systemctl() { return 0; }
|
||||
printf '%s' '{"domains":{"spotify.com":{"verdict":"destination","exit":"primary","host":"www.spotify.com","at":0}},
|
||||
"hosts":{"www.spotify.com":{"domain":"spotify.com","verdict":"destination","exit":"primary"},
|
||||
"gew1-spclient.spotify.com":{"domain":"spotify.com","verdict":"ok","exit":null}},
|
||||
"backlog":{"a.example":{"domain":"example","hits":2},"b.example":{"domain":"example","hits":9}}}' \
|
||||
> "$learn_dir/state.json"
|
||||
q="$(AUTOPROXY_ENABLED=1 AUTOPROXY_STATE_DIR="$learn_dir" cmd_proxy_queue)"
|
||||
grep -qx ' www.last.fm' <<<"$q"
|
||||
# Most-dialled first.
|
||||
test "$(grep -oE '[ab]\.example' <<<"$q" | head -n 1)" = b.example
|
||||
l="$(AUTOPROXY_ENABLED=1 AUTOPROXY_STATE_DIR="$learn_dir" cmd_proxy_learned)"
|
||||
grep -q 'spotify.com .*-> primary' <<<"$l"
|
||||
grep -q 'ok=1' <<<"$l"
|
||||
# An unreadable state directory asks for sudo.
|
||||
chmod 000 "$learn_dir"
|
||||
! (AUTOPROXY_ENABLED=1 AUTOPROXY_STATE_DIR="$learn_dir" cmd_proxy_queue) 2> "$TMPDIR/q-err"
|
||||
chmod 755 "$learn_dir"
|
||||
grep -q 'enable userControl, or run with sudo' "$TMPDIR/q-err"
|
||||
EOF
|
||||
bash "$TMPDIR/test.sh"
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
# autoProxy slowness routing: sampler and judge.
|
||||
autoproxy-slowness =
|
||||
pkgs.runCommand "proxy-suite-autoproxy-slowness-check"
|
||||
{ nativeBuildInputs = [ pkgs.jq ]; }
|
||||
''
|
||||
sample=${../../modules/proxy-suite/autoproxy-slow-sample.jq}
|
||||
judge=${../../modules/proxy-suite/autoproxy-slow-judge.jq}
|
||||
|
||||
# A steady crawl, a burst, probe traffic, and a tiny flow.
|
||||
res="$(jq -n -c '[range(0; 11) as $t | {connections: [
|
||||
{id: "a", metadata: {host: "i.pximg.net", type: "mixed/mixed-in"}, chains: ["direct"], download: ($t * 50000)},
|
||||
{id: "b", metadata: {host: "audio.example", type: "mixed/mixed-in"}, chains: ["direct"], download: (if $t >= 5 then 2000000 else 0 end)},
|
||||
{id: "c", metadata: {host: "probe.example", type: "mixed/probe-in-0"}, chains: ["direct"], download: ($t * 50000)},
|
||||
{id: "d", metadata: {host: "tiny.example", type: "mixed/mixed-in"}, chains: ["direct"], download: ($t * 1000)},
|
||||
{id: "e", metadata: {host: "far.example", type: "mixed/mixed-in"}, chains: ["primary", "proxy"], download: ($t * 50000)}
|
||||
]}][]' | jq -s -r --argjson min 307200 --argjson below 153600 -f "$sample")"
|
||||
printf '%s\n' "$res"
|
||||
test "$(wc -l <<<"$res")" = 3
|
||||
grep -qx "$(printf 'i.pximg.net\tdirect\tslow\t50000')" <<<"$res"
|
||||
grep -qx "$(printf 'audio.example\tdirect\tfast\t2000000')" <<<"$res"
|
||||
# chains[0] is the exit that carried it, not the selector.
|
||||
grep -qx "$(printf 'far.example\tprimary\tslow\t50000')" <<<"$res"
|
||||
|
||||
j() {
|
||||
jq -c --argjson o "$1" --argjson now 1000 --argjson ttl 100 --argjson hits 3 -f "$judge" <<<"$2"
|
||||
}
|
||||
slow='[{"d":"pximg.net","h":"i.pximg.net","exit":"direct","slow":true,"peak":50000}]'
|
||||
onExitSlow='[{"d":"pximg.net","h":"i.pximg.net","exit":"primary","slow":true,"peak":1}]'
|
||||
onExitFast='[{"d":"pximg.net","h":"i.pximg.net","exit":"primary","slow":false,"peak":900000}]'
|
||||
s='{"domains":{},"hosts":{"x.twimg.com":{"verdict":"censor"}},"exits":{},"backlog":{}}'
|
||||
|
||||
# Three crawls within a day make the domain owed an exit; two do not.
|
||||
s="$(j "$slow" "$s")"; s="$(j "$slow" "$s")"
|
||||
jq -e '.slowWant == {}' <<<"$s" > /dev/null
|
||||
s="$(j "$slow" "$s")"
|
||||
jq -e '.slowWant["pximg.net"] == {host: "i.pximg.net", tried: []}' <<<"$s" > /dev/null
|
||||
|
||||
# Left to zapret: never moved, however slow.
|
||||
z='[{"d":"twimg.com","h":"x.twimg.com","exit":"direct","slow":true,"peak":1}]'
|
||||
t="$(j "$z" "$s")"; t="$(j "$z" "$t")"; t="$(j "$z" "$t")"
|
||||
jq -e '.slowWant["twimg.com"] == null' <<<"$t" > /dev/null
|
||||
|
||||
# Once routed -- the prober picks the exit -- judged on that exit alone.
|
||||
r='{"domains":{"pximg.net":{"verdict":"slow","exit":"primary","host":"i.pximg.net","at":0,"tried":["primary"]}},
|
||||
"hosts":{},"exits":{},"backlog":{}}'
|
||||
# Fast there: kept, and a strike against it forgotten.
|
||||
k="$(j "$onExitSlow" "$r")"; k="$(j "$onExitFast" "$k")"
|
||||
jq -e '.domains["pximg.net"] | .bad == 0 and .at == 1000' <<<"$k" > /dev/null
|
||||
# Crawling there too, twice: owed the next exit, the ones tried remembered.
|
||||
u="$(j "$onExitSlow" "$r")"; u="$(j "$onExitSlow" "$u")"
|
||||
jq -e '.domains["pximg.net"] == null and .slowWant["pximg.net"].tried == ["primary"]' <<<"$u" > /dev/null
|
||||
|
||||
# Every exit failed it: left direct until slowSkip expires, however slow.
|
||||
w='{"domains":{},"hosts":{},"exits":{},"backlog":{},"slowSkip":{"pximg.net":1100}}'
|
||||
w="$(j "$slow" "$w")"; w="$(j "$slow" "$w")"; w="$(j "$slow" "$w")"
|
||||
jq -e '.slowWant == {} and .slowSkip["pximg.net"] == 1100' <<<"$w" > /dev/null
|
||||
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
# Per-user inbound traffic: collection and `proxy-ctl inbounds stats`.
|
||||
inbound-stats =
|
||||
pkgs.runCommand "proxy-suite-inbound-stats-check"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
pkgs.bash
|
||||
pkgs.coreutils
|
||||
pkgs.gawk
|
||||
pkgs.gnugrep
|
||||
pkgs.jq
|
||||
];
|
||||
}
|
||||
''
|
||||
add=${../../modules/proxy-suite/inbound-stats-add.jq}
|
||||
now=1789135690 # 2026-09-11
|
||||
a() { jq -c --argjson q "$1" --arg day 2026-09-11 --argjson now "$now" -f "$add" <<<"$2"; }
|
||||
|
||||
# XRay gives values as strings and leaves a zero counter without one.
|
||||
r='{"stat":[{"name":"user>>>fufsob>>>traffic>>>downlink","value":"3000000"},
|
||||
{"name":"user>>>fufsob>>>traffic>>>uplink","value":"2000"},
|
||||
{"name":"user>>>phone>>>traffic>>>uplink"}]}'
|
||||
s="$(a "$r" '{}')"
|
||||
s="$(a "$r" "$s")"
|
||||
jq -e '.days["2026-09-11"].fufsob == {down: 6000000, up: 4000}
|
||||
and .days["2026-09-11"].phone.up == 0 and .at == 1789135690' <<<"$s" > /dev/null
|
||||
# Nothing counted since the last reading: nothing changes.
|
||||
jq -e --argjson s "$s" '.days == $s.days' <<<"$(a '{}' "$s")" > /dev/null
|
||||
# Days more than a year old are let go.
|
||||
old="$(jq -c '.days["2024-01-01"] = {fufsob: {up: 1}}' <<<"$s")"
|
||||
jq -e '.days["2024-01-01"] == null' <<<"$(a '{}' "$old")" > /dev/null
|
||||
|
||||
jq -c '.days["2026-09-10"] = {fufsob: {down: 1073741824, up: 1048576}}' <<<"$s" > "$TMPDIR/stats.json"
|
||||
cat > "$TMPDIR/test.sh" <<'EOF'
|
||||
set -euo pipefail
|
||||
. ${../../pkgs/proxy-ctl-lib.sh}
|
||||
id() { echo 1000; }
|
||||
date() { echo 2026-09-10; }
|
||||
export INBOUNDS_STATS_FILE="$TMPDIR/stats.json"
|
||||
out="$(_inbound_stats 2)"
|
||||
printf '%s\n' "$out"
|
||||
# Newest day first, sizes readable, then totals over the period.
|
||||
test "$(grep -oE '^ 2026-09-1[01]' <<<"$out" | head -n 1)" = " 2026-09-11"
|
||||
grep -qE '^ 2026-09-11 +fufsob +5\.7 MiB +4 KiB$' <<<"$out"
|
||||
grep -qE '^ 2026-09-11 +phone +0 B +0 B$' <<<"$out"
|
||||
grep -qE '^ 2026-09-10 +fufsob +1\.0 GiB +1\.0 MiB$' <<<"$out"
|
||||
grep -qE '^ fufsob +1\.0 GiB +1\.0 MiB$' <<<"$out"
|
||||
! (_inbound_stats 0) 2> /dev/null
|
||||
# Nothing collected yet says so, rather than printing an empty table.
|
||||
! (INBOUNDS_STATS_FILE="$TMPDIR/none.json" _inbound_stats 7) 2> "$TMPDIR/err"
|
||||
grep -q 'No traffic recorded yet' "$TMPDIR/err"
|
||||
|
||||
# --- proxy-ctl inbounds sub -----------------------------------------
|
||||
printf '%s' '[{"user":"fufsob","token":"aaa"},{"user":"teri","token":"bbb"}]' > "$TMPDIR/subs.json"
|
||||
export INBOUNDS_SUBS_FILE="$TMPDIR/subs.json"
|
||||
test "$(INBOUNDS_SUB_BASE_URL=https://vpn.example/sub/ _inbound_subscriptions teri)" = https://vpn.example/sub/bbb
|
||||
# Without a user: names only, never a token.
|
||||
out="$(INBOUNDS_SUB_BASE_URL=https://vpn.example/sub _inbound_subscriptions 2> /dev/null)"
|
||||
test "$(wc -l <<<"$out")" = 2
|
||||
! grep -qE 'aaa|bbb' <<<"$out"
|
||||
! (_inbound_subscriptions nobody) 2> /dev/null
|
||||
# Without a base URL: the file path, and no QR code.
|
||||
test "$(INBOUNDS_SUB_BASE_URL= _inbound_subscriptions fufsob 2> /dev/null)" = "$TMPDIR/subs/aaa"
|
||||
! (INBOUNDS_SUB_BASE_URL= _inbound_subscriptions fufsob --qr) 2> /dev/null
|
||||
EOF
|
||||
bash "$TMPDIR/test.sh"
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
proxy-ctl-amneziawg =
|
||||
pkgs.runCommand "proxy-suite-proxy-ctl-amneziawg-check"
|
||||
{
|
||||
@@ -134,7 +772,6 @@
|
||||
bash "$proxy_ctl" awg list > list-output
|
||||
grep -q 'home.*active' list-output
|
||||
grep -q 'work.*inactive' list-output
|
||||
test "$(bash "$proxy_ctl" awg status)" = home
|
||||
bash "$proxy_ctl" awg on work
|
||||
bash "$proxy_ctl" awg off home
|
||||
bash "$proxy_ctl" awg restart home
|
||||
|
||||
+52
-12
@@ -44,20 +44,27 @@ let
|
||||
routeModeBackendJqFilter =
|
||||
import ../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix
|
||||
{
|
||||
lib = pkgs.lib;
|
||||
pureXrayEnabled = false;
|
||||
proxyInboundsGuardPrivate = 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
|
||||
);
|
||||
routeModeControlScripts = import ../../modules/proxy-suite/service/control-scripts.nix {
|
||||
inherit pkgs;
|
||||
lib = pkgs.lib;
|
||||
proxyCfg = routeModeFixture.config.services.proxy-suite.proxy;
|
||||
clashApi = "http://127.0.0.1:9090";
|
||||
routeModeStateFile = "/run/proxy-suite/route-mode";
|
||||
priorityOutboundFile = "/var/lib/proxy-suite/priority-outbound";
|
||||
outboundInventoryFile = "/run/proxy-suite-socks/outbounds.json";
|
||||
subscriptionCacheDir = "/var/lib/proxy-suite/subscriptions/sing-box";
|
||||
subscriptionCacheHelpersBlock = "";
|
||||
mkSubscriptionFetchBlock = _: "";
|
||||
runtimeSubscriptionsFetchBlock = "";
|
||||
jq = "${pkgs.jq}/bin/jq";
|
||||
};
|
||||
routeModeSetterScript = generated.readDerivation routeModeControlScripts.setRouteModeScript;
|
||||
prioritySetterScript = generated.readDerivation routeModeControlScripts.setPriorityOutboundScript;
|
||||
routeModeRules = mkRouteModeRules routeModeFixture;
|
||||
in
|
||||
{
|
||||
@@ -73,7 +80,7 @@ in
|
||||
|
||||
# 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"
|
||||
assert pkgs.lib.hasInfix "proxy mode [default|whitelist|blacklist|all-proxy|all-bypass]"
|
||||
minimalProxyCtlScript;
|
||||
assert pkgs.lib.hasInfix ''printf 'route_mode=%s\n' "$(_route_mode_current)"''
|
||||
minimalProxyCtlScript;
|
||||
@@ -119,5 +126,38 @@ in
|
||||
assert pkgs.lib.hasInfix "all-bypass)" routeModeSetterScript;
|
||||
true
|
||||
)
|
||||
|
||||
# The outbound pin reuses the same unit-plus-state-file shape, but persists
|
||||
# across a reboot and prefers a live Clash switch over a restart.
|
||||
(
|
||||
let
|
||||
selectSvc = routeModeFixture.config.systemd.services."proxy-suite-outbound-select@";
|
||||
reloadSvc = routeModeFixture.config.systemd.services."proxy-suite-outbound-reload";
|
||||
in
|
||||
assert selectSvc.serviceConfig.RemainAfterExit == false;
|
||||
assert selectSvc.serviceConfig.StateDirectory == "proxy-suite";
|
||||
assert reloadSvc.serviceConfig.RemainAfterExit == false;
|
||||
assert pkgs.lib.hasInfix "/var/lib/proxy-suite/priority-outbound" prioritySetterScript;
|
||||
assert pkgs.lib.hasInfix ''rm -f "/var/lib/proxy-suite/priority-outbound"'' prioritySetterScript;
|
||||
assert pkgs.lib.hasInfix "/proxies/proxy" prioritySetterScript;
|
||||
assert pkgs.lib.hasInfix "systemctl restart proxy-suite-socks" prioritySetterScript;
|
||||
true
|
||||
)
|
||||
|
||||
# proxy-ctl reaches both through the wrapper environment.
|
||||
(
|
||||
assert
|
||||
shellValueByPrefix minimalProxyCtlWrapper "export OUTBOUND_INVENTORY_FILE="
|
||||
== "/run/proxy-suite-socks/outbounds.json";
|
||||
assert
|
||||
shellValueByPrefix minimalProxyCtlWrapper "export RUNTIME_OUTBOUNDS_DIR="
|
||||
== "/var/lib/proxy-suite/outbounds.d";
|
||||
assert
|
||||
shellValueByPrefix minimalProxyCtlWrapper "export RUNTIME_SUBS_DIR="
|
||||
== "/var/lib/proxy-suite/subscriptions.d";
|
||||
assert pkgs.lib.hasInfix "proxy select [<tag>|auto]" minimalProxyCtlScript;
|
||||
assert pkgs.lib.hasInfix "proxy outbounds add <tag> <url>" minimalProxyCtlScript;
|
||||
true
|
||||
)
|
||||
];
|
||||
}
|
||||
+41
-48
@@ -12,13 +12,11 @@ let
|
||||
|
||||
testHostKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
|
||||
|
||||
# The socks start script always passes proxy.tproxy.proxyMark as the routing
|
||||
# mark, so an expected outbound has to carry it to match byte for byte.
|
||||
# Expected outbounds carry proxy.tproxy.proxyMark, as the start script sets it.
|
||||
markOf = fixture: fixture.config.services.proxy-suite.proxy.tproxy.proxyMark;
|
||||
|
||||
# writeText paths are content-addressed, so asserting the store path appears
|
||||
# in the start script pins the exact generated JSON without reading it back.
|
||||
# The context has to go, or the check derivation refuses to mention the path.
|
||||
# writeText paths are content-addressed: finding one in the start script pins the
|
||||
# JSON. The context is dropped so the check may mention it.
|
||||
expectedOutboundFile =
|
||||
backend: value:
|
||||
builtins.unsafeDiscardStringContext "${
|
||||
@@ -33,15 +31,15 @@ let
|
||||
enable = true;
|
||||
sshProxy = {
|
||||
enable = true;
|
||||
user = "root";
|
||||
host = "ssh.example.com";
|
||||
server.user = "root";
|
||||
server.host = "ssh.example.com";
|
||||
asOutbound = true;
|
||||
identityFile = "/run/secrets/ssh-key";
|
||||
hostKey = [ testHostKey ];
|
||||
};
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -60,8 +58,7 @@ let
|
||||
routing_mark = markOf sshNativeSingBox;
|
||||
};
|
||||
|
||||
# hostKeyFile is read at start time, so the keys must be injected by the
|
||||
# start script rather than baked into the outbound JSON.
|
||||
# hostKeyFile keys are injected at start, not baked into the JSON.
|
||||
sshHostKeyFile = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
@@ -69,15 +66,15 @@ let
|
||||
enable = true;
|
||||
sshProxy = {
|
||||
enable = true;
|
||||
user = "root";
|
||||
host = "ssh.example.com";
|
||||
sshPort = 2222;
|
||||
server.user = "root";
|
||||
server.host = "ssh.example.com";
|
||||
server.port = 2222;
|
||||
asOutbound = true;
|
||||
hostKeyFile = "/run/secrets/ssh-known-hosts";
|
||||
};
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -86,8 +83,7 @@ let
|
||||
sshHostKeyFile.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
|
||||
# asOutbound = false is a standalone tunnel no backend knows about, so the
|
||||
# OpenSSH unit is still created even on SingBox.
|
||||
# asOutbound = false: a standalone tunnel, so the OpenSSH unit exists even on SingBox.
|
||||
sshStandalone = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
@@ -95,8 +91,8 @@ let
|
||||
enable = true;
|
||||
sshProxy = {
|
||||
enable = true;
|
||||
user = "root";
|
||||
host = "ssh.example.com";
|
||||
server.user = "root";
|
||||
server.host = "ssh.example.com";
|
||||
asOutbound = false;
|
||||
serviceUser = "proxy";
|
||||
identityFile = "/run/secrets/ssh-key";
|
||||
@@ -108,7 +104,7 @@ let
|
||||
};
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "static";
|
||||
@@ -130,8 +126,7 @@ let
|
||||
unchanged.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
|
||||
# XRay has no SSH outbound, so it keeps the unit and proxies through its
|
||||
# local SOCKS5 listener, with domainStrategy mapped onto sockopt.
|
||||
# XRay keeps the unit and proxies through its listener, domainStrategy on sockopt.
|
||||
sshXray = evalProxySuite [
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
@@ -139,14 +134,14 @@ let
|
||||
enable = true;
|
||||
sshProxy = {
|
||||
enable = true;
|
||||
user = "proxy";
|
||||
host = "ssh.example.com";
|
||||
server.user = "proxy";
|
||||
server.host = "ssh.example.com";
|
||||
asOutbound = true;
|
||||
domainStrategy = "prefer_ipv4";
|
||||
};
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
backend = "xray";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -176,15 +171,14 @@ let
|
||||
enable = true;
|
||||
sshProxy = {
|
||||
enable = true;
|
||||
user = "proxy";
|
||||
host = "ssh.example.com";
|
||||
server.user = "proxy";
|
||||
server.host = "ssh.example.com";
|
||||
asOutbound = true;
|
||||
hostKey = [ testHostKey ];
|
||||
};
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
xray.enable = true;
|
||||
backend = "hybrid";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -209,14 +203,14 @@ let
|
||||
enable = true;
|
||||
sshProxy = {
|
||||
enable = true;
|
||||
user = "proxy";
|
||||
host = "ssh.example.com";
|
||||
server.user = "proxy";
|
||||
server.host = "ssh.example.com";
|
||||
asOutbound = true;
|
||||
hostKey = [ testHostKey ];
|
||||
};
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
selection = "selector";
|
||||
outbounds = [
|
||||
{
|
||||
@@ -239,13 +233,13 @@ let
|
||||
enable = true;
|
||||
sshProxy = {
|
||||
enable = true;
|
||||
user = "proxy";
|
||||
host = "ssh.example.com";
|
||||
server.user = "proxy";
|
||||
server.host = "ssh.example.com";
|
||||
asOutbound = true;
|
||||
};
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
backend = "xray";
|
||||
selection = "urltest";
|
||||
outbounds = [
|
||||
{
|
||||
@@ -268,14 +262,14 @@ let
|
||||
enable = true;
|
||||
sshProxy = {
|
||||
enable = true;
|
||||
user = "proxy";
|
||||
host = "ssh.example.com";
|
||||
server.user = "proxy";
|
||||
server.host = "ssh.example.com";
|
||||
asOutbound = true;
|
||||
hostKey = [ testHostKey ];
|
||||
};
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
selection = "selector";
|
||||
routing.rules = [
|
||||
{
|
||||
@@ -293,8 +287,8 @@ let
|
||||
enable = true;
|
||||
sshProxy = {
|
||||
enable = true;
|
||||
user = "proxy";
|
||||
host = "ssh.example.com";
|
||||
server.user = "proxy";
|
||||
server.host = "ssh.example.com";
|
||||
asOutbound = true;
|
||||
hostKey = [ testHostKey ];
|
||||
};
|
||||
@@ -308,21 +302,21 @@ let
|
||||
};
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
};
|
||||
}
|
||||
{
|
||||
enable = true;
|
||||
sshProxy = {
|
||||
enable = true;
|
||||
user = "proxy";
|
||||
host = "ssh.example.com";
|
||||
server.user = "proxy";
|
||||
server.host = "ssh.example.com";
|
||||
asOutbound = true;
|
||||
hostKey = [ testHostKey ];
|
||||
};
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "ssh-proxy";
|
||||
@@ -331,19 +325,18 @@ let
|
||||
];
|
||||
};
|
||||
}
|
||||
# SingBox verifies host keys by value, so an empty hostKey would silently
|
||||
# accept any key.
|
||||
# An empty hostKey would accept any key on SingBox.
|
||||
{
|
||||
enable = true;
|
||||
sshProxy = {
|
||||
enable = true;
|
||||
user = "proxy";
|
||||
host = "ssh.example.com";
|
||||
server.user = "proxy";
|
||||
server.host = "ssh.example.com";
|
||||
asOutbound = true;
|
||||
};
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
@@ -67,9 +67,37 @@ in
|
||||
true
|
||||
)
|
||||
|
||||
# selection=first renames the first subscription outbound to "proxy".
|
||||
# selection=first renames the pinned outbound - or the first one, absent a
|
||||
# pin - to "proxy" at start, rather than collapsing at eval time.
|
||||
(
|
||||
assert builtins.match ".*proxy.*" subscriptionFirstSelectionStartScript != null;
|
||||
assert pkgs.lib.hasInfix ''PROXY_TAG="$PRIORITY_OUTBOUND"'' subscriptionFirstSelectionStartScript;
|
||||
assert
|
||||
pkgs.lib.hasInfix ''map(if .tag == $t then .tag = "proxy" else . end)''
|
||||
subscriptionFirstSelectionStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
# The pin is read from state, and one that names nothing is dropped.
|
||||
(
|
||||
assert
|
||||
pkgs.lib.hasInfix "/var/lib/proxy-suite/priority-outbound" subscriptionOnlyStartScript;
|
||||
assert
|
||||
pkgs.lib.hasInfix "pinned outbound '$PRIORITY_OUTBOUND' is not available"
|
||||
subscriptionOnlyStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
# proxy-ctl reads the inventory the start script leaves behind.
|
||||
(
|
||||
assert pkgs.lib.hasInfix ''> "$RUNTIME_DIR/outbounds.json"'' subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix ''chmod 644 "$RUNTIME_DIR/outbounds.json"'' subscriptionOnlyStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
# Outbounds added at runtime share the URL path with the declared ones.
|
||||
(
|
||||
assert pkgs.lib.hasInfix "_proxy_suite_runtime_outbounds" subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix "_proxy_suite_add_url_outbound" subscriptionWithStaticStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
@@ -85,26 +113,36 @@ in
|
||||
true
|
||||
)
|
||||
|
||||
# Generated cache paths use the raw validated tag, not shell-escaped quotes.
|
||||
# Cache paths are built from the tag argument, so a tag never reaches the
|
||||
# filename shell-quoted.
|
||||
(
|
||||
assert pkgs.lib.hasInfix ''CACHE_FILE="/var/lib/proxy-suite/subscriptions/sing-box/community.json"''
|
||||
assert pkgs.lib.hasInfix ''SUB_CACHE_DIR="/var/lib/proxy-suite/subscriptions/sing-box"''
|
||||
subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix "/var/lib/proxy-suite/subscriptions/sing-box/community.json.tmp"
|
||||
subscriptionOnlyUpdateScript;
|
||||
assert pkgs.lib.hasInfix ''cache="$SUB_CACHE_DIR/$1.json"'' subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix ''cache="$SUB_CACHE_DIR/$1.json"'' subscriptionOnlyUpdateScript;
|
||||
assert !(pkgs.lib.hasInfix "subscriptions/'community'.json" subscriptionOnlyStartScript);
|
||||
assert !(pkgs.lib.hasInfix "subscriptions/'community'.json" subscriptionOnlyUpdateScript);
|
||||
true
|
||||
)
|
||||
|
||||
# The fetcher's stdout has to land in the cache file. A newline between the
|
||||
# pipeline and the redirect closes the pipeline, leaving a bare redirect
|
||||
# that truncates the cache to zero bytes while the JSON goes to the journal.
|
||||
# Declared and runtime subscriptions both go through the same two entry
|
||||
# points, with the tag passed raw.
|
||||
(
|
||||
assert pkgs.lib.hasInfix ''--tag-prefix community > "$CACHE_FILE.tmp"''
|
||||
assert pkgs.lib.hasInfix "_proxy_suite_load_subscription community "
|
||||
subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix
|
||||
''--tag-prefix community > "/var/lib/proxy-suite/subscriptions/sing-box/community.json.tmp"''
|
||||
assert pkgs.lib.hasInfix "_proxy_suite_fetch_subscription community "
|
||||
subscriptionOnlyUpdateScript;
|
||||
assert pkgs.lib.hasInfix ''_proxy_suite_load_subscription "$RUNTIME_SUB_TAG"''
|
||||
subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix ''_proxy_suite_fetch_subscription "$RUNTIME_SUB_TAG"''
|
||||
subscriptionOnlyUpdateScript;
|
||||
true
|
||||
)
|
||||
|
||||
# The fetcher's output must land in the cache, not after a stray newline.
|
||||
(
|
||||
assert pkgs.lib.hasInfix ''--tag-prefix "$tag" > "$cache.tmp"'' subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix ''--tag-prefix "$tag" > "$cache.tmp"'' subscriptionOnlyUpdateScript;
|
||||
true
|
||||
)
|
||||
|
||||
@@ -133,13 +171,36 @@ in
|
||||
true
|
||||
)
|
||||
|
||||
# No update service or timer exists without subscriptions.
|
||||
# The update service and timer exist whenever the proxy does, because a
|
||||
# subscription can be added at runtime after the rebuild.
|
||||
(
|
||||
assert !(minimal.config.systemd.services ? "proxy-suite-subscription-update");
|
||||
assert minimal.config.systemd.services ? "proxy-suite-subscription-update";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert !(minimal.config.systemd.timers ? "proxy-suite-subscription-update");
|
||||
assert minimal.config.systemd.timers ? "proxy-suite-subscription-update";
|
||||
true
|
||||
)
|
||||
|
||||
# Runtime spool dirs are group-writable and setgid, so proxy-ctl needs no sudo.
|
||||
(
|
||||
assert
|
||||
builtins.any (
|
||||
rule: builtins.match "d /var/lib/proxy-suite/outbounds\\.d 2770 root .*" rule != null
|
||||
) minimal.config.systemd.tmpfiles.rules;
|
||||
assert
|
||||
builtins.any (
|
||||
rule: builtins.match "d /var/lib/proxy-suite/subscriptions\\.d 2770 root .*" rule != null
|
||||
) minimal.config.systemd.tmpfiles.rules;
|
||||
true
|
||||
)
|
||||
|
||||
# Both kinds of subscription go through one loader, and the runtime spool is
|
||||
# walked at start and on refresh.
|
||||
(
|
||||
assert pkgs.lib.hasInfix "_proxy_suite_load_subscription" subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix "_proxy_suite_runtime_subscriptions" subscriptionOnlyStartScript;
|
||||
assert pkgs.lib.hasInfix "_proxy_suite_runtime_subscriptions" subscriptionOnlyUpdateScript;
|
||||
true
|
||||
)
|
||||
];
|
||||
|
||||
@@ -13,7 +13,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
subscriptions = [
|
||||
{
|
||||
tag = "community";
|
||||
@@ -41,7 +41,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "own-vps";
|
||||
@@ -71,7 +71,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
subscriptions = [
|
||||
{
|
||||
tag = "community";
|
||||
@@ -94,16 +94,18 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
subscriptions = [
|
||||
{
|
||||
tag = "community";
|
||||
url = "https://example.com/sub/token";
|
||||
}
|
||||
];
|
||||
tun.perApp.enable = true;
|
||||
};
|
||||
perAppRouting.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
tun.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
@@ -13,7 +13,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
inherit subscriptions;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -38,11 +38,11 @@ in
|
||||
{
|
||||
assertions = [
|
||||
(
|
||||
assert tgSecretFile.config.services.proxy-suite.tgWsProxy.host == "127.0.0.1";
|
||||
assert tgSecretFile.config.services.proxy-suite.tgWsProxy.listener.address == "127.0.0.1";
|
||||
true
|
||||
)
|
||||
(
|
||||
assert minimal.config.services.proxy-suite.tgWsProxy.host == "127.0.0.1";
|
||||
assert minimal.config.services.proxy-suite.tgWsProxy.listener.address == "127.0.0.1";
|
||||
true
|
||||
)
|
||||
(
|
||||
|
||||
@@ -15,7 +15,7 @@ let
|
||||
{
|
||||
services.proxy-suite.tgWsProxy = {
|
||||
enable = true;
|
||||
host = "127.0.0.1";
|
||||
listener.address = "127.0.0.1";
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
};
|
||||
}
|
||||
@@ -27,21 +27,21 @@ let
|
||||
{
|
||||
services.proxy-suite.tgWsProxy = {
|
||||
enable = true;
|
||||
port = 2443;
|
||||
host = "0.0.0.0";
|
||||
listener.port = 2443;
|
||||
listener.address = "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;
|
||||
log.verbose = true;
|
||||
log.file = "/var/log/tg-ws-proxy.log";
|
||||
log.maxSizeMiB = 2.5;
|
||||
log.keep = 3;
|
||||
bufferKiB = 512;
|
||||
poolSize = 8;
|
||||
cfProxyDomains = [
|
||||
cloudflare.domains = [
|
||||
"cdn.example.com"
|
||||
"edge.example.net"
|
||||
];
|
||||
cfProxyWorkerDomains = [ "worker.example.com" ];
|
||||
cfProxyFallback = false;
|
||||
cloudflare.workerDomains = [ "worker.example.com" ];
|
||||
cloudflare.fallback = false;
|
||||
fakeTlsDomain = "mask.example.com";
|
||||
proxyProtocol = true;
|
||||
};
|
||||
@@ -92,7 +92,7 @@ let
|
||||
tgWsProxy = {
|
||||
enable = true;
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
routingMark = 1;
|
||||
fwmark = 1;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -102,7 +102,7 @@ let
|
||||
services.proxy-suite.tgWsProxy = {
|
||||
enable = true;
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
bufKb = 3;
|
||||
bufferKiB = 3;
|
||||
};
|
||||
}
|
||||
]
|
||||
@@ -120,7 +120,7 @@ let
|
||||
services.proxy-suite.tgWsProxy = {
|
||||
enable = true;
|
||||
secretFile = "/run/secrets/tg-ws-proxy";
|
||||
logBackups = 0;
|
||||
log.keep = 0;
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
+53
-14
@@ -9,10 +9,10 @@ let
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tun.perApp.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
tun.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -22,10 +22,7 @@ let
|
||||
userControlGlobalOnlyFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.userControl = {
|
||||
global.enable = true;
|
||||
perApp.enable = false;
|
||||
};
|
||||
services.proxy-suite.userControl.allow = [ "global" ];
|
||||
}
|
||||
];
|
||||
userControlGlobalOnlyPolkitConfig = userControlGlobalOnlyFixture.config.security.polkit.extraConfig;
|
||||
@@ -34,15 +31,12 @@ let
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.tun.perApp.enable = true;
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
tun.enable = true;
|
||||
};
|
||||
userControl = {
|
||||
global.enable = false;
|
||||
perApp.enable = true;
|
||||
};
|
||||
userControl.allow = [ "perApp" ];
|
||||
};
|
||||
}
|
||||
];
|
||||
@@ -51,12 +45,30 @@ let
|
||||
userControlDisabledFixture = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.userControl = {
|
||||
global.enable = false;
|
||||
perApp.enable = false;
|
||||
};
|
||||
services.proxy-suite.userControl.allow = [ ];
|
||||
}
|
||||
];
|
||||
|
||||
# Every unit declaring the autoProxy state directory must carry the group, or
|
||||
# the next start chowns it back and `proxy auto list|queue` loses its read.
|
||||
mkAutoProxyFixture =
|
||||
extra:
|
||||
evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
proxy.autoProxy.enable = true;
|
||||
}
|
||||
// extra;
|
||||
}
|
||||
];
|
||||
autoProxyGroups =
|
||||
fixture:
|
||||
map (unit: fixture.config.systemd.services.${unit}.serviceConfig.Group or null) [
|
||||
"proxy-suite-autoproxy"
|
||||
"proxy-suite-autoproxy-learn"
|
||||
"proxy-suite-autoproxy-sample"
|
||||
];
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
@@ -100,6 +112,33 @@ in
|
||||
true
|
||||
)
|
||||
|
||||
# -- userControl: the autoProxy state directory is group-owned, and only then --
|
||||
(
|
||||
assert
|
||||
autoProxyGroups (mkAutoProxyFixture { }) == [
|
||||
"proxy-suite"
|
||||
"proxy-suite"
|
||||
"proxy-suite"
|
||||
];
|
||||
assert
|
||||
autoProxyGroups (mkAutoProxyFixture {
|
||||
userControl.group = "vpnops";
|
||||
}) == [
|
||||
"vpnops"
|
||||
"vpnops"
|
||||
"vpnops"
|
||||
];
|
||||
assert
|
||||
autoProxyGroups (mkAutoProxyFixture {
|
||||
userControl.allow = [ ];
|
||||
}) == [
|
||||
null
|
||||
null
|
||||
null
|
||||
];
|
||||
true
|
||||
)
|
||||
|
||||
# -- userControl: disabling both scopes removes group and polkit wiring --
|
||||
(
|
||||
assert !(userControlDisabledFixture.config.users.groups ? "proxy-suite");
|
||||
|
||||
@@ -27,8 +27,9 @@ in
|
||||
{
|
||||
assertions = [
|
||||
(
|
||||
assert pkgs.lib.hasInfix ''CACHE_FILE="/var/lib/proxy-suite/subscriptions/xray/xray-sub.json"''
|
||||
assert pkgs.lib.hasInfix ''SUB_CACHE_DIR="/var/lib/proxy-suite/subscriptions/xray"''
|
||||
xraySubscriptionStartScript;
|
||||
assert pkgs.lib.hasInfix "_proxy_suite_load_subscription xray-sub" xraySubscriptionStartScript;
|
||||
assert pkgs.lib.hasInfix "--backend xray" xraySubscriptionStartScript;
|
||||
true
|
||||
)
|
||||
|
||||
@@ -22,11 +22,15 @@ let
|
||||
backend = null;
|
||||
backendArg = null;
|
||||
xraySidecarRoutingMark = null;
|
||||
priorityOutboundFile = null;
|
||||
runtimeOutboundsDir = null;
|
||||
jq = null;
|
||||
python3 = null;
|
||||
parserScriptsPythonPath = null;
|
||||
buildOutboundPy = null;
|
||||
mkSubscriptionBlock = null;
|
||||
mkSubscriptionLoadHelperBlock = null;
|
||||
runtimeSubscriptionsBlock = null;
|
||||
}).rawOutboundJson;
|
||||
|
||||
xrayRawStreamDefinition = {
|
||||
@@ -56,7 +60,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
backend = "xray";
|
||||
subscriptions = [
|
||||
{
|
||||
tag = "xray-sub";
|
||||
@@ -78,7 +82,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
backend = "xray";
|
||||
outbounds = [ xrayRawStreamDefinition ];
|
||||
};
|
||||
};
|
||||
@@ -96,7 +100,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
backend = "xray";
|
||||
dns.local = {
|
||||
type = "tcp";
|
||||
address = "9.9.9.9";
|
||||
@@ -118,7 +122,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
backend = "xray";
|
||||
dns.remote = {
|
||||
type = "tls";
|
||||
address = "1.1.1.1";
|
||||
@@ -148,7 +152,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
backend = "xray";
|
||||
selection = "selector";
|
||||
outbounds = [
|
||||
{
|
||||
@@ -162,7 +166,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
backend = "xray";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "raw";
|
||||
@@ -177,7 +181,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "raw";
|
||||
|
||||
@@ -16,7 +16,7 @@ let
|
||||
enable = true;
|
||||
proxy = {
|
||||
enable = true;
|
||||
xray.enable = true;
|
||||
backend = "xray";
|
||||
selection = "urltest";
|
||||
outbounds = [
|
||||
{
|
||||
@@ -34,15 +34,13 @@ let
|
||||
block.domains = [ "block.example" ];
|
||||
};
|
||||
tproxy.enable = true;
|
||||
tproxy.perApp.enable = true;
|
||||
tun = {
|
||||
enable = true;
|
||||
perApp.enable = true;
|
||||
};
|
||||
tun.enable = true;
|
||||
};
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
createDefaultProfiles = true;
|
||||
tun.enable = true;
|
||||
tproxy.enable = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -81,6 +79,8 @@ let
|
||||
xrayBackendJqFilter =
|
||||
import ../../../modules/proxy-suite/service/script-blocks/backend-jq-filter.nix
|
||||
{
|
||||
lib = pkgs.lib;
|
||||
proxyInboundsGuardPrivate = false;
|
||||
pureXrayEnabled = true;
|
||||
selectionMode = xrayFixture.config.services.proxy-suite.proxy.selection;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
);
|
||||
balancer = builtins.head xrayTproxyConfig.routing.balancers;
|
||||
in
|
||||
assert xrayFixture.config.services.proxy-suite.proxy.xray.enable;
|
||||
assert xrayFixture.config.services.proxy-suite.proxy.backend == "xray";
|
||||
assert xrayFixture.config.systemd.services ? "proxy-suite-socks";
|
||||
assert xrayFixture.config.systemd.services ? "proxy-suite-tproxy";
|
||||
assert xrayFixture.config.systemd.services ? "proxy-suite-tun";
|
||||
|
||||
@@ -13,7 +13,7 @@ let
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
hostlistRules = [
|
||||
zapret-discord-youtube.hostlistRules = [
|
||||
{
|
||||
name = "googlevideo";
|
||||
domains = [
|
||||
@@ -81,7 +81,7 @@ let
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
hostlistRules = [
|
||||
zapret-discord-youtube.hostlistRules = [
|
||||
{
|
||||
name = "dup";
|
||||
domains = [ "one.example" ];
|
||||
@@ -100,7 +100,7 @@ let
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
hostlistRules = [
|
||||
zapret-discord-youtube.hostlistRules = [
|
||||
{
|
||||
name = "empty";
|
||||
domains = [ ];
|
||||
@@ -114,7 +114,7 @@ let
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
hostlistRules = [
|
||||
zapret-discord-youtube.hostlistRules = [
|
||||
{
|
||||
name = "missing";
|
||||
domains = [ "missing.example" ];
|
||||
@@ -127,7 +127,7 @@ let
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
hostlistRules = [
|
||||
zapret-discord-youtube.hostlistRules = [
|
||||
{
|
||||
name = "conflict";
|
||||
defaultDomains = [ "google" ];
|
||||
@@ -142,7 +142,7 @@ let
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
enable = true;
|
||||
hostlistRules = [
|
||||
zapret-discord-youtube.hostlistRules = [
|
||||
{
|
||||
name = "missing-family";
|
||||
domains = [ "example.com" ];
|
||||
|
||||
@@ -24,58 +24,60 @@ let
|
||||
zapretSyncBase = mkZapretBase zapretSyncFixture;
|
||||
|
||||
zapretSpacedConfigAliasBase = mkZapretBase (evalZapret {
|
||||
configName = "general(ALT12)";
|
||||
zapret-discord-youtube.configName = "general(ALT12)";
|
||||
});
|
||||
|
||||
zapretUnspacedConfigAliasBase = mkZapretBase (evalZapret {
|
||||
configName = "general (ALT)";
|
||||
zapret-discord-youtube.configName = "general (ALT)";
|
||||
});
|
||||
|
||||
zapretSyncNoExtraListsFixture = evalZapret {
|
||||
includeExtraUpstreamLists = false;
|
||||
zapret-discord-youtube.includeExtraUpstreamLists = false;
|
||||
};
|
||||
zapretSyncNoExtraListsBase = mkZapretBase zapretSyncNoExtraListsFixture;
|
||||
zapretSyncNoExtraListsRules = mkRoutingRules zapretSyncNoExtraListsFixture;
|
||||
|
||||
zapretSyncExtraListsFixture = evalZapret {
|
||||
includeExtraUpstreamLists = true;
|
||||
zapret-discord-youtube.includeExtraUpstreamLists = true;
|
||||
};
|
||||
zapretSyncExtraListsBase = mkZapretBase zapretSyncExtraListsFixture;
|
||||
zapretSyncExtraListsRules = mkRoutingRules zapretSyncExtraListsFixture;
|
||||
|
||||
zapretSyncIpsRules = mkRoutingRules (evalZapret {
|
||||
syncDirectRoutingUpstreamIps = true;
|
||||
directSync.upstreamIps = true;
|
||||
});
|
||||
|
||||
zapretSyncUserIpsDisabledRules = mkRoutingRules (evalZapret {
|
||||
syncDirectRoutingUserIps = false;
|
||||
ipsetAll = [ "203.0.113.0/24" ];
|
||||
directSync.userIps = false;
|
||||
zapret-discord-youtube.ips = [ "203.0.113.0/24" ];
|
||||
});
|
||||
|
||||
zapretSyncDisabledRules = mkRoutingRules (evalZapret {
|
||||
syncDirectRouting = false;
|
||||
directSync.enable = false;
|
||||
});
|
||||
|
||||
zapretSyncDomainsOnlyRules = mkRoutingRules (evalZapret {
|
||||
syncDirectRouting = true;
|
||||
syncDirectRoutingUpstreamIps = false;
|
||||
directSync = {
|
||||
enable = true;
|
||||
upstreamIps = false;
|
||||
};
|
||||
});
|
||||
|
||||
zapretExtrasRules = mkRoutingRules (evalZapret {
|
||||
listGeneral = [ "pixiv.net" ];
|
||||
zapret-discord-youtube.domains = [ "pixiv.net" ];
|
||||
});
|
||||
|
||||
zapretIpExtrasRules = mkRoutingRules (evalZapret {
|
||||
ipsetAll = [ "203.0.113.0/24" ];
|
||||
zapret-discord-youtube.ips = [ "203.0.113.0/24" ];
|
||||
});
|
||||
|
||||
zapretExcludesRules = mkRoutingRules (evalZapret {
|
||||
listExclude = [ "discord.com" ];
|
||||
zapret-discord-youtube.excludeDomains = [ "discord.com" ];
|
||||
});
|
||||
|
||||
zapretIpExcludesRules = mkRoutingRules (evalZapret {
|
||||
ipsetExclude = [ "1.1.1.0/24" ];
|
||||
ipsetAll = [ "1.1.1.0/24" ];
|
||||
zapret-discord-youtube.excludeIps = [ "1.1.1.0/24" ];
|
||||
zapret-discord-youtube.ips = [ "1.1.1.0/24" ];
|
||||
});
|
||||
in
|
||||
{
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
{
|
||||
pkgs,
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
mkProxyCtlDerived,
|
||||
mkBadFixture,
|
||||
mkFailingAssertions,
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (pkgs) lib;
|
||||
|
||||
fixtures = import ./zapret2/fixtures.nix { inherit evalProxySuite baseModule; };
|
||||
inherit (fixtures)
|
||||
zapretDiscordYoutubeGlobal
|
||||
zapret2Global
|
||||
zapret2PerApp
|
||||
zapret2Tuned
|
||||
zapret2NoAuto
|
||||
;
|
||||
|
||||
envValue =
|
||||
fixture: serviceName: prefix:
|
||||
lib.removePrefix prefix (
|
||||
builtins.head (
|
||||
builtins.filter (
|
||||
value: lib.hasPrefix prefix value
|
||||
) fixture.config.systemd.services.${serviceName}.serviceConfig.Environment
|
||||
)
|
||||
);
|
||||
|
||||
globalService = "zapret-discord-youtube";
|
||||
perAppService = "proxy-suite-per-app-zapret";
|
||||
|
||||
zapretBase = fixture: envValue fixture globalService "ZAPRET_BASE=";
|
||||
runtimeDir = fixture: serviceName: envValue fixture serviceName "ZAPRET_RW=";
|
||||
|
||||
globalRuntime = runtimeDir zapret2Global globalService;
|
||||
perAppGlobalRuntime = runtimeDir zapret2PerApp globalService;
|
||||
perAppRuntime = runtimeDir zapret2PerApp perAppService;
|
||||
tunedRuntime = runtimeDir zapret2Tuned globalService;
|
||||
noAutoRuntime = runtimeDir zapret2NoAuto globalService;
|
||||
|
||||
proxyCtlEnv = fixture: (mkProxyCtlDerived fixture).wrapperEnv;
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
# The engine changes the implementation, not the unit names.
|
||||
(
|
||||
assert lib.hasInfix "zapret2" (zapretBase zapret2Global);
|
||||
assert !(lib.hasInfix "zapret2" (zapretBase zapretDiscordYoutubeGlobal));
|
||||
assert zapret2Global.config.systemd.services ? ${globalService};
|
||||
assert !(zapret2Global.config.systemd.services ? ${perAppService});
|
||||
true
|
||||
)
|
||||
|
||||
# Both instances share the state directory.
|
||||
(
|
||||
assert envValue zapret2Global globalService "HOSTLIST_BASE=" == "/var/lib/proxy-suite/zapret2";
|
||||
assert
|
||||
zapret2Global.config.systemd.services.${globalService}.serviceConfig.StateDirectory
|
||||
== "proxy-suite";
|
||||
assert envValue zapret2PerApp perAppService "HOSTLIST_BASE=" == "/var/lib/proxy-suite/zapret2";
|
||||
true
|
||||
)
|
||||
|
||||
# Two nfqws2 processes must not share a pidfile or a config.
|
||||
(
|
||||
assert envValue zapret2PerApp globalService "PIDDIR=" == "/run/proxy-suite-zapret";
|
||||
assert envValue zapret2PerApp perAppService "PIDDIR=" == "/run/proxy-suite-per-app-zapret";
|
||||
assert perAppGlobalRuntime != perAppRuntime;
|
||||
true
|
||||
)
|
||||
|
||||
# `proxy-ctl zapret auto` only makes sense when something is learning.
|
||||
(
|
||||
assert (proxyCtlEnv zapret2Global).ZAPRET_AUTO_ENABLED == "1";
|
||||
assert (proxyCtlEnv zapretDiscordYoutubeGlobal).ZAPRET_AUTO_ENABLED == "0";
|
||||
assert (proxyCtlEnv zapret2Global).ZAPRET_STATE_DIR == "/var/lib/proxy-suite/zapret2";
|
||||
true
|
||||
)
|
||||
];
|
||||
|
||||
runtime =
|
||||
pkgs.runCommand "proxy-suite-zapret2-config-check"
|
||||
{
|
||||
nativeBuildInputs = [ pkgs.gnugrep ];
|
||||
}
|
||||
''
|
||||
base=${zapretBase zapret2Global}
|
||||
|
||||
# --- generated config -------------------------------------------------
|
||||
grep -qx 'MODE_FILTER=autohostlist' "${globalRuntime}/config"
|
||||
grep -qx 'AUTOHOSTLIST_FAIL_THRESHOLD=3' "${globalRuntime}/config"
|
||||
grep -qx 'AUTOHOSTLIST_FAIL_TIME=300' "${globalRuntime}/config"
|
||||
grep -qx 'AUTOHOSTLIST_RETRANS_THRESHOLD=3' "${globalRuntime}/config"
|
||||
grep -qx 'QNUM=300' "${globalRuntime}/config"
|
||||
grep -qx 'FWTYPE=nftables' "${globalRuntime}/config"
|
||||
grep -qx 'WS_USER=root' "${globalRuntime}/config"
|
||||
grep -qx 'DISABLE_IPV6=1' "${globalRuntime}/config"
|
||||
|
||||
# The NFQUEUE window must exceed the retransmission threshold.
|
||||
grep -qx 'NFQWS2_TCP_PKT_OUT=9' "${globalRuntime}/config"
|
||||
grep -qx 'NFQWS2_TCP_PKT_IN=15' "${globalRuntime}/config"
|
||||
|
||||
# Learning off means list mode, not "no lists".
|
||||
grep -qx 'MODE_FILTER=hostlist' "${noAutoRuntime}/config"
|
||||
|
||||
# Tuned knobs reach the config, including the wider packet window.
|
||||
grep -qx 'AUTOHOSTLIST_FAIL_THRESHOLD=5' "${tunedRuntime}/config"
|
||||
grep -qx 'AUTOHOSTLIST_FAIL_TIME=120' "${tunedRuntime}/config"
|
||||
grep -qx 'AUTOHOSTLIST_DEBUGLOG=1' "${tunedRuntime}/config"
|
||||
grep -qx 'NFQWS2_TCP_PKT_OUT=10' "${tunedRuntime}/config"
|
||||
|
||||
# Static filters only on hostlist profiles; the UDP profile stays list-free.
|
||||
grep -qF -- '<HOSTLIST> --hostlist-domains=pinned.example --hostlist-exclude-domains=excluded.example' "${tunedRuntime}/config"
|
||||
grep -qF -- '<HOSTLIST_NOAUTO> --hostlist-domains=pinned.example --hostlist-exclude-domains=excluded.example' "${tunedRuntime}/config"
|
||||
test "$(grep -oF -- '--hostlist-domains=pinned.example' "${tunedRuntime}/config" | wc -l)" = 2
|
||||
|
||||
# --- per-app instance -------------------------------------------------
|
||||
# Wrapped apps opted in explicitly, so no hostlist gates them.
|
||||
grep -qx 'MODE_FILTER=none' "${perAppRuntime}/config"
|
||||
grep -qx 'FILTER_MARK=0x10000000' "${perAppRuntime}/config"
|
||||
grep -qx 'QNUM=201' "${perAppRuntime}/config"
|
||||
grep -qx 'DESYNC_MARK=0x8000000' "${perAppRuntime}/config"
|
||||
grep -qx 'DESYNC_MARK_POSTNAT=0x4000000' "${perAppRuntime}/config"
|
||||
grep -qx 'ZAPRET_NFT_TABLE=proxy_suite_per_app_zapret' "${perAppRuntime}/config"
|
||||
|
||||
# The global instance must keep its hands off per-app traffic.
|
||||
hook="${perAppGlobalRuntime}/init.d/sysv/custom.d/50-proxy-suite-custom.sh"
|
||||
test "$(grep -c 'mark and 0x10000000 != 0 return' "$hook")" = 4
|
||||
grep -q 'nft insert rule inet $ZAPRET_NFT_TABLE prenat mark and 0x10000000 != 0 return' "$hook"
|
||||
|
||||
# --- the command line nfqws2 receives ---
|
||||
# Expand <HOSTLIST> with zapret2's list.sh and let nfqws2 validate the result.
|
||||
export HOSTLIST_BASE="$PWD/lists"
|
||||
export ZAPRET_BASE="$base"
|
||||
mkdir -p "$HOSTLIST_BASE"
|
||||
touch "$HOSTLIST_BASE/zapret-hosts-auto.txt" \
|
||||
"$HOSTLIST_BASE/zapret-hosts-user.txt" \
|
||||
"$HOSTLIST_BASE/zapret-hosts-user-exclude.txt"
|
||||
|
||||
. "${globalRuntime}/config"
|
||||
. "$base/common/base.sh"
|
||||
. "$base/common/list.sh"
|
||||
|
||||
opt="--qnum=$QNUM $NFQWS2_OPT"
|
||||
filter_apply_hostlist_target opt
|
||||
|
||||
printf '%s\n' "$opt" | tr ' ' '\n' | grep -qx -- "--hostlist-auto=$HOSTLIST_BASE/zapret-hosts-auto.txt"
|
||||
printf '%s\n' "$opt" | tr ' ' '\n' | grep -qx -- '--hostlist-auto-fail-threshold=3'
|
||||
printf '%s\n' "$opt" | tr ' ' '\n' | grep -qx -- '--hostlist-auto-fail-time=300'
|
||||
|
||||
# --user is deliberately omitted: the sandbox is not root.
|
||||
"$base/nfq2/nfqws2" --dry-run --fwmark="$DESYNC_MARK" \
|
||||
--lua-init=@"$base/lua/zapret-lib.lua" \
|
||||
--lua-init=@"$base/lua/zapret-antidpi.lua" \
|
||||
--lua-init=@"$base/lua/zapret-auto.lua" \
|
||||
$opt
|
||||
|
||||
touch "$out"
|
||||
'';
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
{
|
||||
evalProxySuite,
|
||||
baseModule,
|
||||
}:
|
||||
|
||||
let
|
||||
mkZapret2 =
|
||||
zapret:
|
||||
evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite.zapret = {
|
||||
engine = "zapret2";
|
||||
}
|
||||
// zapret;
|
||||
}
|
||||
];
|
||||
in
|
||||
{
|
||||
zapretDiscordYoutubeGlobal = evalProxySuite [
|
||||
baseModule
|
||||
{ services.proxy-suite.zapret.enable = true; }
|
||||
];
|
||||
|
||||
zapret2Global = mkZapret2 { enable = true; };
|
||||
|
||||
zapret2PerApp = evalProxySuite [
|
||||
baseModule
|
||||
{
|
||||
services.proxy-suite = {
|
||||
perAppRouting = {
|
||||
enable = true;
|
||||
zapret.enable = true;
|
||||
};
|
||||
zapret = {
|
||||
engine = "zapret2";
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
zapret2Tuned = mkZapret2 {
|
||||
enable = true;
|
||||
zapret2 = {
|
||||
domains = [ "pinned.example" ];
|
||||
excludeDomains = [ "excluded.example" ];
|
||||
autoHostlist = {
|
||||
failThreshold = 5;
|
||||
failTime = 120;
|
||||
retransThreshold = 4;
|
||||
debugLog = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
zapret2NoAuto = mkZapret2 {
|
||||
enable = true;
|
||||
zapret2.autoHostlist.enable = false;
|
||||
};
|
||||
}
|
||||
+23
-84
@@ -13,98 +13,37 @@ let
|
||||
inherit system;
|
||||
modules = [
|
||||
proxySuiteModule
|
||||
{
|
||||
system.stateVersion = lib.trivial.release;
|
||||
}
|
||||
{ system.stateVersion = lib.trivial.release; }
|
||||
];
|
||||
};
|
||||
filterGeneratedOptions = lib.filterAttrs (name: _: name != "_module");
|
||||
singBoxPackagePlaceholder = "__proxy_suite_doc_pkg_sing_box__";
|
||||
xrayPackagePlaceholder = "__proxy_suite_doc_pkg_xray__";
|
||||
sanitizeConfigForDocs =
|
||||
config:
|
||||
builtins.removeAttrs config [ "singBox" ]
|
||||
// lib.optionalAttrs ((config.proxyInbounds or { }) ? package) {
|
||||
proxyInbounds = config.proxyInbounds // {
|
||||
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:
|
||||
lib.replaceStrings
|
||||
[
|
||||
"\"${singBoxPackagePlaceholder}\""
|
||||
"\"${xrayPackagePlaceholder}\""
|
||||
]
|
||||
[
|
||||
"pkgs.sing-box"
|
||||
"pkgs.xray"
|
||||
]
|
||||
(lib.generators.toPretty { } (sanitizeConfigForDocs config));
|
||||
mkGeneratedExampleValue =
|
||||
option:
|
||||
if (option ? _type) && option._type == "option" then
|
||||
if option ? example then
|
||||
option.example
|
||||
else if (option ? type) && ((option.type.name or null) == "submodule") then
|
||||
lib.mapAttrs (_: mkGeneratedExampleValue) (filterGeneratedOptions (option.type.getSubOptions [ ]))
|
||||
else if option ? default then
|
||||
option.default
|
||||
|
||||
# Visible options only (renamed aliases are hidden), packages shown by name.
|
||||
visibleConfig =
|
||||
opts: cfg:
|
||||
lib.mapAttrs (
|
||||
name: opt:
|
||||
if !lib.isOption opt then
|
||||
visibleConfig opt cfg.${name}
|
||||
else if lib.isDerivation cfg.${name} then
|
||||
{
|
||||
__pretty = _: "pkgs.${lib.getName cfg.${name}}";
|
||||
val = null;
|
||||
}
|
||||
else
|
||||
throw "Cannot generate example value for option ${lib.showOption option.loc}"
|
||||
else
|
||||
lib.mapAttrs (_: mkGeneratedExampleValue) (filterGeneratedOptions option);
|
||||
defaultConfigText = renderConfigText eval.config.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";
|
||||
transformDeclaration =
|
||||
decl:
|
||||
let
|
||||
declStr = toString decl;
|
||||
subpath = lib.removePrefix "/" (lib.removePrefix repoRoot declStr);
|
||||
in
|
||||
if lib.hasPrefix repoRoot declStr then
|
||||
{
|
||||
url = "${repoUrl}/${subpath}";
|
||||
name = subpath;
|
||||
}
|
||||
else
|
||||
decl;
|
||||
cfg.${name}
|
||||
) (lib.filterAttrs (name: opt: name != "_module" && (opt.visible or true) != false) opts);
|
||||
|
||||
optionDocs = pkgs.nixosOptionsDoc {
|
||||
options = {
|
||||
services = {
|
||||
"proxy-suite" = eval.options.services.proxy-suite;
|
||||
};
|
||||
};
|
||||
options.services.proxy-suite = eval.options.services.proxy-suite;
|
||||
documentType = "none";
|
||||
variablelistId = "proxy-suite-options";
|
||||
optionIdPrefix = "proxy-suite-opt-";
|
||||
transformOptions = opt: opt // { declarations = map transformDeclaration opt.declarations; };
|
||||
transformOptions = opt: opt // { declarations = [ ]; };
|
||||
};
|
||||
in
|
||||
import ./options-doc/render-options-markdown.nix {
|
||||
inherit
|
||||
pkgs
|
||||
optionDocs
|
||||
defaultConfigText
|
||||
exampleConfigText
|
||||
;
|
||||
inherit pkgs optionDocs;
|
||||
defaultConfigText = lib.generators.toPretty { allowPrettyValues = true; } (
|
||||
visibleConfig eval.options.services.proxy-suite eval.config.services.proxy-suite
|
||||
);
|
||||
}
|
||||
@@ -2,48 +2,21 @@
|
||||
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"
|
||||
# One file per top-level option group, plus an index. The single 6k-line page was
|
||||
# not navigable.
|
||||
pkgs.runCommand "proxy-suite-options-doc" { } ''
|
||||
mkdir -p "$out" "$TMPDIR/bodies"
|
||||
all="$TMPDIR/all.md"
|
||||
index_tsv="$TMPDIR/sections-index.tsv"
|
||||
|
||||
cat >"$preamble" <<'EOF'
|
||||
# proxy-suite options
|
||||
cat ${optionDocs.optionsCommonMark} >"$all"
|
||||
|
||||
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" '
|
||||
# Anchor every section and file it under its top-level group. Options directly
|
||||
# under services.proxy-suite (only `enable`) stay on the index.
|
||||
: >"$index_tsv"
|
||||
awk -v outdir="$TMPDIR/bodies" -v index_tsv="$index_tsv" '
|
||||
function slugify(text, slug) {
|
||||
slug = text
|
||||
gsub(/\\/, "", slug)
|
||||
@@ -56,141 +29,121 @@ pkgs.runCommand "proxy-suite-options.md" { } ''
|
||||
|
||||
/^## / {
|
||||
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"
|
||||
}
|
||||
if (label ~ /^<.*>$/) {
|
||||
return "`" label "`"
|
||||
}
|
||||
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)
|
||||
count = split(normalized, parts, /\./)
|
||||
group = (count <= 3) ? "index" : parts[3]
|
||||
slug = slugify(title)
|
||||
current = outdir "/" group ".md"
|
||||
|
||||
if (normalized ~ /^Complete /) {
|
||||
sampleCount++
|
||||
sampleTitle[sampleCount] = title
|
||||
sampleSlug[sampleCount] = slug
|
||||
next
|
||||
print title "\t" slug "\t" group >> index_tsv
|
||||
print "<a id=\"" slug "\"></a>" >> current
|
||||
print $0 >> current
|
||||
next
|
||||
}
|
||||
|
||||
{ if (current != "") print >> current }
|
||||
' "$all"
|
||||
|
||||
groups="$(cut -f3 "$index_tsv" | grep -v '^index$' | awk '!seen[$0]++')"
|
||||
|
||||
# Per-group table of contents, nested by option path.
|
||||
mkToc() {
|
||||
awk -F '\t' -v want="$1" '
|
||||
function indent(depth, i, prefix) {
|
||||
prefix = ""
|
||||
for (i = 0; i < depth; i++) {
|
||||
prefix = prefix " "
|
||||
}
|
||||
return prefix
|
||||
}
|
||||
|
||||
if (index(normalized, "services.proxy-suite") == 1) {
|
||||
optionRootSeen = 1
|
||||
slugByPath[normalized] = slug
|
||||
function displayLabel(label) {
|
||||
if (label == "*") {
|
||||
return "item"
|
||||
}
|
||||
if (label ~ /^<.*>$/) {
|
||||
return "`" label "`"
|
||||
}
|
||||
return label
|
||||
}
|
||||
|
||||
function addChild(parent, child, key) {
|
||||
key = parent SUBSEP child
|
||||
if (!(key in seenChild)) {
|
||||
seenChild[key] = 1
|
||||
childCount[parent]++
|
||||
childOrder[parent, childCount[parent]] = child
|
||||
}
|
||||
}
|
||||
|
||||
function printNode(path, label, depth, i, child, childPath, text) {
|
||||
text = displayLabel(label)
|
||||
if (path in slugByPath) {
|
||||
text = "[" text "](#" slugByPath[path] ")"
|
||||
}
|
||||
print indent(depth) "- " text
|
||||
for (i = 1; i <= childCount[path]; i++) {
|
||||
child = childOrder[path, i]
|
||||
childPath = path "." child
|
||||
printNode(childPath, child, depth + 1)
|
||||
}
|
||||
}
|
||||
|
||||
$3 == want {
|
||||
normalized = $1
|
||||
gsub(/\\/, "", normalized)
|
||||
slugByPath[normalized] = $2
|
||||
|
||||
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
|
||||
}
|
||||
END { printNode("services.proxy-suite." want, want, 0) }
|
||||
' "$index_tsv"
|
||||
}
|
||||
|
||||
for group in $groups; do
|
||||
{
|
||||
blanks++
|
||||
}
|
||||
' "$raw" >"$out"
|
||||
printf '# services.proxy-suite.%s\n\n' "$group"
|
||||
printf 'Part of the [proxy-suite options reference](./index.md).\n\n'
|
||||
printf '## Options\n\n'
|
||||
mkToc "$group"
|
||||
printf '\n'
|
||||
cat "$TMPDIR/bodies/$group.md"
|
||||
} >"$TMPDIR/$group.out"
|
||||
done
|
||||
|
||||
{
|
||||
printf '# proxy-suite options\n\n'
|
||||
printf 'Generated from the `services.proxy-suite` option descriptions under\n'
|
||||
printf '[`modules/proxy-suite/options/`](/modules/proxy-suite/options/).\n'
|
||||
printf 'Update the module option docs there instead of editing these files by hand.\n\n'
|
||||
|
||||
printf '## Option groups\n\n'
|
||||
for group in $groups; do
|
||||
printf -- '- [%s](./%s.md)\n' "$group" "$group"
|
||||
done
|
||||
printf '\n'
|
||||
|
||||
printf '## Complete default config\n\n'
|
||||
printf '```nix\n'
|
||||
printf 'services.proxy-suite = %s;\n' ${pkgs.lib.escapeShellArg defaultConfigText}
|
||||
printf '```\n\n'
|
||||
|
||||
if [ -f "$TMPDIR/bodies/index.md" ]; then
|
||||
cat "$TMPDIR/bodies/index.md"
|
||||
fi
|
||||
} >"$TMPDIR/index.out"
|
||||
|
||||
# Collapse runs of blank lines, drop trailing ones.
|
||||
for group in $groups index; do
|
||||
awk 'NF { if (blank) print ""; blank = 0; print; next } { blank = 1 }' \
|
||||
"$TMPDIR/$group.out" >"$out/$group.md"
|
||||
done
|
||||
''
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
proxy = {
|
||||
enable = true;
|
||||
singBox.enable = true;
|
||||
backend = "sing-box";
|
||||
outbounds = [
|
||||
{
|
||||
tag = "primary";
|
||||
|
||||
Reference in new issue
Block a user