chore: collapse packages
This commit is contained in:
29 files changed
+151
-111
No files matched your search
@@ -25,7 +25,7 @@ let
|
||||
profile.settings
|
||||
]
|
||||
);
|
||||
inlineVpnFile = name: profile: pkgs.writeText "proxy-suite-awg-${name}.vpn" profile.vpn;
|
||||
inlineVpnFile = name: profile: pkgs.writeText "proxy-suite-awg" profile.vpn;
|
||||
sourceKind =
|
||||
profile:
|
||||
if profile.configFile != null then
|
||||
@@ -48,7 +48,7 @@ let
|
||||
null;
|
||||
manifestFor =
|
||||
name: profile:
|
||||
pkgs.writeText "proxy-suite-awg-${name}-manifest.json" (
|
||||
pkgs.writeText "proxy-suite-awg" (
|
||||
builtins.toJSON (
|
||||
{
|
||||
kind = sourceKind profile;
|
||||
@@ -59,7 +59,12 @@ let
|
||||
// lib.optionalAttrs (profile.settings != null) { settings = profile.settings; }
|
||||
)
|
||||
);
|
||||
configTool = ../../scripts/amneziawg_config.py;
|
||||
configTool = "${
|
||||
builtins.path {
|
||||
name = "proxy-suite-scripts";
|
||||
path = ../../scripts;
|
||||
}
|
||||
}/amneziawg_config.py";
|
||||
runtimeDir = name: "/run/${serviceName name}";
|
||||
runtimeConfig = name: profile: "${runtimeDir name}/${profile.interfaceName}.conf";
|
||||
# Keep proxy backend sockets (proxyMark) out of AWG's default-route table.
|
||||
@@ -70,13 +75,13 @@ let
|
||||
let
|
||||
manifest = manifestFor name profile;
|
||||
configPath = runtimeConfig name profile;
|
||||
prepare = pkgs.writeShellScript "proxy-suite-awg-${name}-prepare" ''
|
||||
prepare = pkgs.writeShellScript "proxy-suite-awg" ''
|
||||
set -euo pipefail
|
||||
${pkgs.python3}/bin/python3 ${configTool} \
|
||||
--manifest ${lib.escapeShellArg (toString manifest)} \
|
||||
--output ${lib.escapeShellArg configPath}
|
||||
'';
|
||||
proxyBypassUp = pkgs.writeShellScript "proxy-suite-awg-${name}-proxy-bypass-up" ''
|
||||
proxyBypassUp = pkgs.writeShellScript "proxy-suite-awg" ''
|
||||
set -euo pipefail
|
||||
|
||||
add_bypass_rule() {
|
||||
@@ -99,7 +104,7 @@ let
|
||||
add_bypass_rule -4
|
||||
add_bypass_rule -6
|
||||
'';
|
||||
proxyBypassDown = pkgs.writeShellScript "proxy-suite-awg-${name}-proxy-bypass-down" ''
|
||||
proxyBypassDown = pkgs.writeShellScript "proxy-suite-awg" ''
|
||||
set +e
|
||||
|
||||
while ${pkgs.iproute2}/bin/ip -4 rule del \
|
||||
@@ -109,7 +114,7 @@ let
|
||||
pref ${toString proxyBypassRulePriority} \
|
||||
fwmark ${toString cfg.proxy.tproxy.proxyMark} lookup main 2>/dev/null; do :; done
|
||||
'';
|
||||
start = pkgs.writeShellScript "proxy-suite-awg-${name}-start" ''
|
||||
start = pkgs.writeShellScript "proxy-suite-awg" ''
|
||||
set -Eeuo pipefail
|
||||
|
||||
cleanup() {
|
||||
@@ -170,7 +175,7 @@ let
|
||||
echo "proxy-suite: AmneziaWG profile '${name}' did not complete a handshake; rolling back routes" >&2
|
||||
false
|
||||
'';
|
||||
stop = pkgs.writeShellScript "proxy-suite-awg-${name}-stop" ''
|
||||
stop = pkgs.writeShellScript "proxy-suite-awg" ''
|
||||
set -euo pipefail
|
||||
exec ${awgCfg.toolsPackage}/bin/awg-quick down ${lib.escapeShellArg configPath}
|
||||
'';
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# publish what it learns, which sing-box then picks up without a restart.
|
||||
{ pkgs }:
|
||||
|
||||
pkgs.writeShellScript "proxy-suite-autoproxy-render" ''
|
||||
pkgs.writeShellScript "proxy-suite-autoproxy" ''
|
||||
set -euo pipefail
|
||||
# $1 - probe-exits.json (index -> tag -> path), $2 - state.json
|
||||
export PATH=${pkgs.lib.makeBinPath [
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
let
|
||||
apCfg = cfg.proxy.autoProxy;
|
||||
render = import ./autoproxy-render.nix { inherit pkgs; };
|
||||
jqFile =
|
||||
path:
|
||||
builtins.path {
|
||||
name = "proxy-suite-autoproxy";
|
||||
inherit path;
|
||||
};
|
||||
|
||||
bin = lib.makeBinPath [
|
||||
pkgs.coreutils
|
||||
@@ -36,7 +42,7 @@ let
|
||||
[ -z "$clash_secret" ] || clash_auth=(-H "Authorization: Bearer $clash_secret")
|
||||
'';
|
||||
|
||||
sampler = pkgs.writeShellScript "proxy-suite-autoproxy-sample" ''
|
||||
sampler = pkgs.writeShellScript "proxy-suite-autoproxy" ''
|
||||
set -euo pipefail
|
||||
export PATH=${bin}
|
||||
state_dir=''${AUTOPROXY_STATE_DIR:-${lib.escapeShellArg autoProxyStateDir}}
|
||||
@@ -55,12 +61,12 @@ let
|
||||
curl -sS --noproxy '*' --max-time 1 "''${clash_auth[@]}" "http://$clash_api/connections" 2>/dev/null ||
|
||||
echo '{}'
|
||||
done | jq -s -r --argjson min ${toString (300 * 1024)} \
|
||||
--argjson below ${toString (apCfg.slowBelowKiBps * 1024)} -f ${./autoproxy-slow-sample.jq} || true
|
||||
--argjson below ${toString (apCfg.slowBelowKiBps * 1024)} -f ${jqFile ./autoproxy-slow-sample.jq} || true
|
||||
)
|
||||
[ -z "$lines" ] || printf '%s\n' "$lines" >> "$state_dir/samples"
|
||||
'';
|
||||
|
||||
runner = pkgs.writeShellScript "proxy-suite-autoproxy-run" ''
|
||||
runner = pkgs.writeShellScript "proxy-suite-autoproxy" ''
|
||||
set -euo pipefail
|
||||
export PATH=${bin}
|
||||
|
||||
@@ -116,7 +122,7 @@ let
|
||||
# $1 JSON array of exit tags, $2 registrable domain, $3 wall:<page>|refused|slow.
|
||||
strike() {
|
||||
update --argjson tags "$1" --arg d "$2" --arg why "$3" --argjson now "$now" --argjson ttl "$ttl" \
|
||||
-f ${./autoproxy-strike.jq}
|
||||
-f ${jqFile ./autoproxy-strike.jq}
|
||||
}
|
||||
|
||||
# $1 registrable domain, $2 host probed, $3 probe JSON. Routes apply to the
|
||||
@@ -198,7 +204,7 @@ let
|
||||
strike '[]' "" ""
|
||||
|
||||
# See autoproxy-rounds.jq: one exit per AS, then the rest, bad exits last.
|
||||
rounds=$(jq -c --slurpfile s "$state" -f ${./autoproxy-rounds.jq} "$index")
|
||||
rounds=$(jq -c --slurpfile s "$state" -f ${jqFile ./autoproxy-rounds.jq} "$index")
|
||||
round1=$(jq -r .r1 <<<"$rounds")
|
||||
round2=$(jq -r .r2 <<<"$rounds")
|
||||
|
||||
@@ -293,7 +299,7 @@ let
|
||||
rm -f "$state_dir/samples.taking"
|
||||
before=$(jq -c '.domains' "$state")
|
||||
update --argjson o "$obs" --argjson now "$now" --argjson ttl "$ttl" --argjson hits 3 \
|
||||
-f ${./autoproxy-slow-judge.jq}
|
||||
-f ${jqFile ./autoproxy-slow-judge.jq}
|
||||
|
||||
# Each crawling destination gets the next exit, in probe order, that
|
||||
# answers it as well as direct does (`probe --via`). None left: it
|
||||
|
||||
@@ -63,22 +63,22 @@ let
|
||||
routeModeRules =
|
||||
if derived.pureXrayEnabled then rules.xrayRouteModeRules else rules.singBoxRouteModeRules;
|
||||
|
||||
tproxyFile = pkgs.writeText "proxy-suite-tproxy-template.json" (
|
||||
tproxyFile = pkgs.writeText "proxy-suite-core" (
|
||||
builtins.toJSON selectedTemplates.tproxy
|
||||
);
|
||||
tunFile = pkgs.writeText "proxy-suite-tun-template.json" (
|
||||
tunFile = pkgs.writeText "proxy-suite-core" (
|
||||
builtins.toJSON selectedTemplates.tun
|
||||
);
|
||||
perAppTunFile = pkgs.writeText "proxy-suite-per-app-tun-template.json" (
|
||||
perAppTunFile = pkgs.writeText "proxy-suite-core" (
|
||||
builtins.toJSON selectedTemplates.perAppTun
|
||||
);
|
||||
routeModeRulesFile = pkgs.writeText "proxy-suite-route-mode-rules.json" (
|
||||
routeModeRulesFile = pkgs.writeText "proxy-suite-core" (
|
||||
builtins.toJSON routeModeRules
|
||||
);
|
||||
proxyInboundsFile = pkgs.writeText "proxy-suite-inbounds-template.json" (
|
||||
proxyInboundsFile = pkgs.writeText "proxy-suite-inbounds" (
|
||||
builtins.toJSON proxyInboundsTemplate
|
||||
);
|
||||
proxyInboundsSpecFile = pkgs.writeText "proxy-suite-inbounds-spec.json" (
|
||||
proxyInboundsSpecFile = pkgs.writeText "proxy-suite-inbounds" (
|
||||
builtins.toJSON proxyInboundsSpec
|
||||
);
|
||||
in
|
||||
|
||||
@@ -20,12 +20,30 @@ let
|
||||
packages = import ../../pkgs/default.nix { inherit pkgs; };
|
||||
nftr = import ./nftables.nix { inherit lib pkgs cfg; };
|
||||
derived = import ./derived.nix { inherit lib cfg; };
|
||||
|
||||
# Scripts share one store name per block, and journald names a unit's output
|
||||
# after its ExecStart basename; tag each unit with its own name instead.
|
||||
unitsWithOwnSyslogIdentifier = lib.mkOption {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{ name, ... }:
|
||||
{
|
||||
config.serviceConfig.SyslogIdentifier = lib.mkIf (
|
||||
lib.hasPrefix "proxy-suite-" name || name == "zapret-discord-youtube"
|
||||
) (lib.mkDefault (lib.removeSuffix "@" name));
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./options
|
||||
];
|
||||
|
||||
options.systemd.services = unitsWithOwnSyslogIdentifier;
|
||||
options.systemd.user.services = unitsWithOwnSyslogIdentifier;
|
||||
|
||||
config = lib.mkMerge [
|
||||
{
|
||||
# xray and sing-box default to this flake's own nixpkgs (redirect it
|
||||
|
||||
@@ -42,7 +42,7 @@ let
|
||||
tproxyLocalSubnetLines = mkLocalSubnetLines globalTproxy.localSubnets;
|
||||
perAppTproxyLocalSubnetLines = mkLocalSubnetLines perAppTproxy.localSubnets;
|
||||
|
||||
nftablesRulesFile = pkgs.writeText "proxy-suite-tproxy.nft" ''
|
||||
nftablesRulesFile = pkgs.writeText "proxy-suite-routing" ''
|
||||
${reservedIpBlock}
|
||||
table ip singbox {
|
||||
chain prerouting {
|
||||
@@ -66,7 +66,7 @@ let
|
||||
}
|
||||
'';
|
||||
|
||||
perAppTproxyRulesFile = pkgs.writeText "proxy-suite-per-app-tproxy.nft" ''
|
||||
perAppTproxyRulesFile = pkgs.writeText "proxy-suite-routing" ''
|
||||
${reservedIpBlock}
|
||||
table ip proxy_suite_per_app_tproxy {
|
||||
chain prerouting {
|
||||
@@ -90,7 +90,7 @@ let
|
||||
}
|
||||
'';
|
||||
|
||||
perAppZapretRulesFile = pkgs.writeText "proxy-suite-per-app-zapret.nft" ''
|
||||
perAppZapretRulesFile = pkgs.writeText "proxy-suite-routing" ''
|
||||
table inet proxy_suite_per_app_zapret_mark {
|
||||
chain prerouting {
|
||||
type filter hook prerouting priority -103; policy accept;
|
||||
@@ -105,7 +105,7 @@ let
|
||||
}
|
||||
'';
|
||||
|
||||
perAppTunChainFile = pkgs.writeText "proxy-suite-per-app-tun-chain.nft" ''
|
||||
perAppTunChainFile = pkgs.writeText "proxy-suite-routing" ''
|
||||
${reservedIpBlock}
|
||||
table inet proxy_suite_per_app_tun {
|
||||
chain output {
|
||||
|
||||
@@ -69,11 +69,14 @@ let
|
||||
headBin = "${pkgs.coreutils}/bin/head";
|
||||
seqBin = "${pkgs.coreutils}/bin/seq";
|
||||
findBin = "${pkgs.findutils}/bin/find";
|
||||
amneziaWgProfileNamesFile = pkgs.writeText "proxy-suite-awg-profiles.json" (
|
||||
amneziaWgProfileNamesFile = pkgs.writeText "proxy-suite-core" (
|
||||
builtins.toJSON (builtins.attrNames cfg.amneziaWg.profiles)
|
||||
);
|
||||
|
||||
proxySuiteScriptsDir = ../../../scripts;
|
||||
proxySuiteScriptsDir = builtins.path {
|
||||
name = "proxy-suite-scripts";
|
||||
path = ../../../scripts;
|
||||
};
|
||||
parserScriptsPythonPath = proxySuiteScriptsDir;
|
||||
buildOutboundPy = "${proxySuiteScriptsDir}/build-outbound.py";
|
||||
buildInboundPy = "${proxySuiteScriptsDir}/build-inbound.py";
|
||||
|
||||
@@ -31,7 +31,7 @@ let
|
||||
"proxy-suite-per-app-tun"
|
||||
];
|
||||
|
||||
subscriptionUpdateScript = pkgs.writeShellScript "proxy-suite-subscription-update" ''
|
||||
subscriptionUpdateScript = pkgs.writeShellScript "proxy-suite-core" ''
|
||||
set -euo pipefail
|
||||
CACHE_DIR="${subscriptionCacheDir}"
|
||||
mkdir -p "$CACHE_DIR"
|
||||
@@ -46,7 +46,7 @@ let
|
||||
exit "$FAILED"
|
||||
'';
|
||||
|
||||
setRouteModeScript = pkgs.writeShellScript "proxy-suite-set-route-mode" ''
|
||||
setRouteModeScript = pkgs.writeShellScript "proxy-suite-core" ''
|
||||
set -euo pipefail
|
||||
mode="''${1:-}"
|
||||
|
||||
@@ -80,7 +80,7 @@ let
|
||||
# Pins the outbound the proxy prefers, or "auto" to hand the choice back to the
|
||||
# configured selection. The pin is persisted either way; a live Clash API switch
|
||||
# only saves the restart.
|
||||
setPriorityOutboundScript = pkgs.writeShellScript "proxy-suite-set-priority-outbound" ''
|
||||
setPriorityOutboundScript = pkgs.writeShellScript "proxy-suite-core" ''
|
||||
set -euo pipefail
|
||||
tag="''${1:-}"
|
||||
|
||||
@@ -117,7 +117,7 @@ let
|
||||
# Applies whatever is now in the runtime spool directories. A removed runtime
|
||||
# subscription leaves a root-owned cache behind that the group cannot unlink,
|
||||
# so the cache dir is reconciled against the sources here.
|
||||
reloadOutboundsScript = pkgs.writeShellScript "proxy-suite-reload-outbounds" ''
|
||||
reloadOutboundsScript = pkgs.writeShellScript "proxy-suite-core" ''
|
||||
set -euo pipefail
|
||||
${subscriptionCacheHelpersBlock}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ let
|
||||
xrayPerAppTunIPv6RoutePrefix
|
||||
;
|
||||
|
||||
perAppTunWaitForInterface = pkgs.writeShellScript "proxy-suite-per-app-tun-wait-for-interface" ''
|
||||
perAppTunWaitForInterface = pkgs.writeShellScript "proxy-suite-per-app" ''
|
||||
set -euo pipefail
|
||||
for _ in $(${seqBin} 1 50); do
|
||||
if ${ip} link show dev ${lib.escapeShellArg perAppRoutingTun.interface} >/dev/null 2>&1; then
|
||||
@@ -39,7 +39,7 @@ let
|
||||
exit 1
|
||||
'';
|
||||
|
||||
perAppTunUpScript = pkgs.writeShellScript "proxy-suite-per-app-tun-up" ''
|
||||
perAppTunUpScript = pkgs.writeShellScript "proxy-suite-per-app" ''
|
||||
set -euo pipefail
|
||||
|
||||
tun_cidr=${lib.escapeShellArg perAppRoutingTun.address}
|
||||
@@ -83,7 +83,7 @@ let
|
||||
''}
|
||||
'';
|
||||
|
||||
perAppTunDownScript = pkgs.writeShellScript "proxy-suite-per-app-tun-down" ''
|
||||
perAppTunDownScript = pkgs.writeShellScript "proxy-suite-per-app" ''
|
||||
set +e
|
||||
|
||||
# Best-effort cleanup for graceful stops and for unclean previous exits.
|
||||
@@ -106,7 +106,7 @@ let
|
||||
${builders.flushResolvedCaches}
|
||||
'';
|
||||
|
||||
perAppTproxyUpScript = pkgs.writeShellScript "proxy-suite-per-app-tproxy-up" ''
|
||||
perAppTproxyUpScript = pkgs.writeShellScript "proxy-suite-per-app" ''
|
||||
set -euo pipefail
|
||||
|
||||
${builders.mkNftDeleteTable { inherit nft; family = "ip"; table = "proxy_suite_per_app_tproxy"; }}
|
||||
@@ -122,7 +122,7 @@ let
|
||||
${ip} rule add fwmark ${toString perAppRoutingTproxy.fwmark} table ${toString perAppRoutingTproxy.routeTable}
|
||||
'';
|
||||
|
||||
perAppTproxyDownScript = pkgs.writeShellScript "proxy-suite-per-app-tproxy-down" ''
|
||||
perAppTproxyDownScript = pkgs.writeShellScript "proxy-suite-per-app" ''
|
||||
set +e
|
||||
|
||||
${builders.mkNftDeleteTable { inherit nft; family = "ip"; table = "proxy_suite_per_app_tproxy"; }}
|
||||
|
||||
@@ -49,7 +49,7 @@ let
|
||||
localProxyAuth.username != null
|
||||
&& (localProxyAuth.password != null || localProxyAuth.passwordFile != null);
|
||||
|
||||
perAppRoutingProfilesFile = pkgs.writeText "proxy-suite-per-app-routing-profiles.json" (
|
||||
perAppRoutingProfilesFile = pkgs.writeText "proxy-suite-per-app" (
|
||||
builtins.toJSON effectivePerAppRoutingProfiles
|
||||
);
|
||||
|
||||
@@ -57,7 +57,7 @@ let
|
||||
if localProxyAuthEnabled then
|
||||
"/run/proxy-suite-socks/proxychains.conf"
|
||||
else
|
||||
pkgs.writeText "proxy-suite-proxychains.conf" ''
|
||||
pkgs.writeText "proxy-suite-per-app" ''
|
||||
strict_chain
|
||||
${lib.optionalString perAppRoutingCfg.proxychains.quiet "quiet_mode"}
|
||||
${lib.optionalString perAppRoutingCfg.proxychains.proxyDns "proxy_dns"}
|
||||
|
||||
@@ -26,7 +26,7 @@ let
|
||||
sliceLabel,
|
||||
markRule,
|
||||
}:
|
||||
pkgs.writeShellScript "proxy-suite-${name}-user-start" ''
|
||||
pkgs.writeShellScript "proxy-suite-per-app" ''
|
||||
set -euo pipefail
|
||||
uid="$1"
|
||||
rule_comment_prefix="proxy-suite-${name}-user-$uid"
|
||||
@@ -67,7 +67,7 @@ let
|
||||
nftTable,
|
||||
nftChain,
|
||||
}:
|
||||
pkgs.writeShellScript "proxy-suite-${name}-user-stop" ''
|
||||
pkgs.writeShellScript "proxy-suite-per-app" ''
|
||||
set -euo pipefail
|
||||
uid="$1"
|
||||
rule_comment_prefix="proxy-suite-${name}-user-$uid"
|
||||
|
||||
@@ -56,7 +56,7 @@ let
|
||||
if ob.urlFile != null then
|
||||
ob.urlFile
|
||||
else if ob.url != null then
|
||||
pkgs.writeText "proxy-suite-inbound-via-url-${ob.tag}" ob.url
|
||||
pkgs.writeText "proxy-suite-inbounds" ob.url
|
||||
else
|
||||
null;
|
||||
in
|
||||
@@ -64,7 +64,7 @@ let
|
||||
''
|
||||
# via outbound: ${ob.tag} (static xray json)
|
||||
OB_JSON=$(cat ${
|
||||
pkgs.writeText "proxy-suite-inbound-via-${ob.tag}.json" (
|
||||
pkgs.writeText "proxy-suite-inbounds" (
|
||||
builtins.toJSON (ob.xrayJson // { inherit (ob) tag; })
|
||||
)
|
||||
})
|
||||
@@ -111,7 +111,7 @@ let
|
||||
chmod ${if userControlEnabled then "640" else "600"} "${subscriptionsFile}"
|
||||
'';
|
||||
|
||||
startInbounds = pkgs.writeShellScript "proxy-suite-start-inbounds" ''
|
||||
startInbounds = pkgs.writeShellScript "proxy-suite-inbounds" ''
|
||||
set -euo pipefail
|
||||
umask 077
|
||||
RUNTIME_DIR="${runtimeDir}"
|
||||
@@ -156,7 +156,7 @@ let
|
||||
# Adds XRay's per-user counters to the daily totals, read and reset in one call.
|
||||
# ponytail: a restart of the inbounds loses what was counted since the last run, at
|
||||
# most one timer interval; collect from ExecStop if that matters.
|
||||
collectInboundStats = pkgs.writeShellScript "proxy-suite-inbound-stats" ''
|
||||
collectInboundStats = pkgs.writeShellScript "proxy-suite-inbounds" ''
|
||||
set -euo pipefail
|
||||
file=${lib.escapeShellArg constants.inboundStatsFile}
|
||||
if ! reading=$(${xray} api statsquery --server=127.0.0.1:${toString constants.inboundStatsApiPort} \
|
||||
@@ -170,7 +170,12 @@ let
|
||||
${jq} --argjson q "$reading" \
|
||||
--arg day "$(${pkgs.coreutils}/bin/date +%F)" \
|
||||
--argjson now "$(${pkgs.coreutils}/bin/date +%s)" \
|
||||
-f ${../inbound-stats-add.jq} "$file" > "$tmp"
|
||||
-f ${
|
||||
builtins.path {
|
||||
name = "proxy-suite-inbounds";
|
||||
path = ../inbound-stats-add.jq;
|
||||
}
|
||||
} "$file" > "$tmp"
|
||||
${lib.optionalString userControlEnabled ''
|
||||
${pkgs.coreutils}/bin/chgrp ${lib.escapeShellArg userControlCfg.group} "$tmp" ||
|
||||
echo "proxy-suite: group ${userControlCfg.group} cannot read the stats; they stay root-only" >&2
|
||||
|
||||
@@ -29,7 +29,7 @@ let
|
||||
};
|
||||
in
|
||||
{
|
||||
xrayTunUpScript = pkgs.writeShellScript "proxy-suite-xray-tun-up" ''
|
||||
xrayTunUpScript = pkgs.writeShellScript "proxy-suite-routing" ''
|
||||
set -euo pipefail
|
||||
|
||||
tun_cidr=${lib.escapeShellArg globalTun.address}
|
||||
@@ -81,7 +81,7 @@ in
|
||||
${ip} -6 rule add pref ${toString tunAutoRouteRulePriority} not fwmark ${toString globalTproxy.proxyMark} table ${toString tunAutoRouteTableIndex}
|
||||
'';
|
||||
|
||||
tproxyUpScript = pkgs.writeShellScript "proxy-suite-tproxy-up" ''
|
||||
tproxyUpScript = pkgs.writeShellScript "proxy-suite-routing" ''
|
||||
set -euo pipefail
|
||||
|
||||
# Start from a clean policy-routing state. `ip rule add` permits duplicate
|
||||
@@ -100,7 +100,7 @@ in
|
||||
${ip} rule add fwmark ${toString globalTproxy.fwmark} table ${toString globalTproxy.routeTable}
|
||||
'';
|
||||
|
||||
tproxyDownScript = pkgs.writeShellScript "proxy-suite-tproxy-down" ''
|
||||
tproxyDownScript = pkgs.writeShellScript "proxy-suite-routing" ''
|
||||
set +e
|
||||
|
||||
${builders.mkNftDeleteTable { inherit nft; family = "ip"; table = "singbox"; }}
|
||||
@@ -112,7 +112,7 @@ in
|
||||
${builders.mkIpLocalDefaultRouteDelete { inherit ip; table = globalTproxy.routeTable; }}
|
||||
'';
|
||||
|
||||
tunCleanupScript = pkgs.writeShellScript "proxy-suite-tun-cleanup" ''
|
||||
tunCleanupScript = pkgs.writeShellScript "proxy-suite-routing" ''
|
||||
set +e
|
||||
|
||||
# SingBox normally removes these on graceful shutdown, but stale
|
||||
|
||||
@@ -179,7 +179,7 @@ let
|
||||
if backendRaw != null then
|
||||
let
|
||||
outboundJson = builtins.toJSON (rawOutboundJson ob tag routingMark);
|
||||
jsonFile = pkgs.writeText "proxy-suite-ob-${tag}.json" outboundJson;
|
||||
jsonFile = pkgs.writeText "proxy-suite-core" outboundJson;
|
||||
in
|
||||
''
|
||||
# outbound: ${tag} (static ${backend} json)
|
||||
@@ -189,8 +189,7 @@ let
|
||||
''
|
||||
else
|
||||
let
|
||||
urlSource =
|
||||
if ob.urlFile != null then ob.urlFile else pkgs.writeText "proxy-suite-url-${ob.tag}" ob.url;
|
||||
urlSource = if ob.urlFile != null then ob.urlFile else pkgs.writeText "proxy-suite-core" ob.url;
|
||||
in
|
||||
''
|
||||
# outbound: ${tag}
|
||||
@@ -219,7 +218,7 @@ let
|
||||
if ob.xrayJson != null then
|
||||
let
|
||||
outboundJson = builtins.toJSON (xrayRawOutboundJson ob tag);
|
||||
jsonFile = pkgs.writeText "proxy-suite-xray-sidecar-ob-${tag}.json" outboundJson;
|
||||
jsonFile = pkgs.writeText "proxy-suite-core" outboundJson;
|
||||
in
|
||||
''
|
||||
# outbound: ${tag} (hybrid XRay json sidecar)
|
||||
@@ -230,7 +229,7 @@ let
|
||||
else if ob.singBoxJson != null || ob.json != null then
|
||||
let
|
||||
outboundJson = builtins.toJSON (singBoxRawOutboundJson ob tag routingMark);
|
||||
jsonFile = pkgs.writeText "proxy-suite-sing-box-ob-${tag}.json" outboundJson;
|
||||
jsonFile = pkgs.writeText "proxy-suite-core" outboundJson;
|
||||
in
|
||||
''
|
||||
# outbound: ${tag} (hybrid SingBox json)
|
||||
@@ -240,8 +239,7 @@ let
|
||||
''
|
||||
else
|
||||
let
|
||||
urlSource =
|
||||
if ob.urlFile != null then ob.urlFile else pkgs.writeText "proxy-suite-url-${ob.tag}" ob.url;
|
||||
urlSource = if ob.urlFile != null then ob.urlFile else pkgs.writeText "proxy-suite-core" ob.url;
|
||||
in
|
||||
''
|
||||
# outbound: ${tag} (hybrid ${ob.backend})
|
||||
@@ -286,7 +284,7 @@ let
|
||||
};
|
||||
outbound = if pureXrayEnabled then xrayOutbound else singBoxOutbound;
|
||||
outboundJson = builtins.toJSON outbound;
|
||||
jsonFile = pkgs.writeText "proxy-suite-ob-ssh-proxy-${backend}.json" outboundJson;
|
||||
jsonFile = pkgs.writeText "proxy-suite-core" outboundJson;
|
||||
|
||||
# Read at start so the known-hosts file stays out of the store.
|
||||
knownHostsTarget =
|
||||
|
||||
@@ -28,7 +28,7 @@ let
|
||||
if sub.urlFile != null then
|
||||
sub.urlFile
|
||||
else
|
||||
pkgs.writeText "proxy-suite-sub-url-${sub.tag}" sub.url;
|
||||
pkgs.writeText "proxy-suite-core" sub.url;
|
||||
|
||||
# Defined in every script that touches a cache: the start scripts and the
|
||||
# update unit.
|
||||
@@ -181,7 +181,7 @@ let
|
||||
done < <(_proxy_suite_runtime_subscriptions)
|
||||
'';
|
||||
|
||||
subscriptionTagsFile = pkgs.writeText "proxy-suite-subscription-tags.json" (
|
||||
subscriptionTagsFile = pkgs.writeText "proxy-suite-core" (
|
||||
builtins.toJSON (map (sub: sub.tag) proxyCfg.subscriptions)
|
||||
);
|
||||
in
|
||||
|
||||
@@ -52,7 +52,7 @@ let
|
||||
if localProxyAuth.passwordFile != null then
|
||||
localProxyAuth.passwordFile
|
||||
else if localProxyAuth.password != null then
|
||||
pkgs.writeText "proxy-suite-local-proxy-password" localProxyAuth.password
|
||||
pkgs.writeText "proxy-suite-core" localProxyAuth.password
|
||||
else
|
||||
null;
|
||||
routeModeStateFile = "/run/proxy-suite/route-mode";
|
||||
@@ -148,7 +148,7 @@ let
|
||||
proxyInboundsGuardPrivate
|
||||
;
|
||||
};
|
||||
backendJqFilterFile = pkgs.writeText "proxy-suite-${backend}-backend-filter.jq" backendJqFilter;
|
||||
backendJqFilterFile = pkgs.writeText "proxy-suite-core" backendJqFilter;
|
||||
|
||||
startScripts = import ./start-scripts.nix {
|
||||
inherit
|
||||
|
||||
@@ -135,7 +135,6 @@ let
|
||||
|
||||
mkStartScript =
|
||||
{
|
||||
name,
|
||||
runtimeDir,
|
||||
configFile,
|
||||
routingMark ? null,
|
||||
@@ -148,7 +147,7 @@ let
|
||||
enableOutboundTest ? false,
|
||||
enableZapretCutoff ? false,
|
||||
}:
|
||||
pkgs.writeShellScript name ''
|
||||
pkgs.writeShellScript "proxy-suite-core" ''
|
||||
set -euo pipefail
|
||||
RUNTIME_DIR="${runtimeDir}"
|
||||
ROUTE_MODE_STATE_FILE="${routeModeStateFile}"
|
||||
@@ -370,7 +369,6 @@ let
|
||||
'';
|
||||
|
||||
startSocks = mkStartScript {
|
||||
name = "proxy-suite-start-socks";
|
||||
runtimeDir = "/run/proxy-suite-socks";
|
||||
configFile = tproxyFile;
|
||||
routingMark = globalTproxy.proxyMark;
|
||||
@@ -384,7 +382,6 @@ let
|
||||
};
|
||||
|
||||
startTun = mkStartScript {
|
||||
name = "proxy-suite-start-tun";
|
||||
runtimeDir = "/run/proxy-suite-tun";
|
||||
configFile = tunFile;
|
||||
routingMark = if pureXrayEnabled then globalTproxy.proxyMark else null;
|
||||
@@ -395,7 +392,6 @@ let
|
||||
};
|
||||
|
||||
startPerAppTun = mkStartScript {
|
||||
name = "proxy-suite-start-per-app-tun";
|
||||
runtimeDir = "/run/proxy-suite-per-app-tun";
|
||||
configFile = perAppTunFile;
|
||||
routingMark = if xrayEnabled || globalTproxy.enable then globalTproxy.proxyMark else null;
|
||||
|
||||
@@ -9,7 +9,7 @@ let
|
||||
s = cfg.sshProxy;
|
||||
destination = if s.server.user == null then s.server.host else "${s.server.user}@${s.server.host}";
|
||||
extraArgs = lib.concatMapStrings (arg: " args+=(${lib.escapeShellArg arg})\n") s.extraArgs;
|
||||
startScript = pkgs.writeShellScript "proxy-suite-ssh-proxy-start" ''
|
||||
startScript = pkgs.writeShellScript "proxy-suite-ssh-proxy" ''
|
||||
set -euo pipefail
|
||||
|
||||
args=(
|
||||
|
||||
@@ -25,7 +25,7 @@ let
|
||||
dcArgs = lib.concatMapStrings (id: mkValueArg "--dc-ip" "${id}:${t.dcIps.${id}}") (
|
||||
builtins.attrNames t.dcIps
|
||||
);
|
||||
startScript = pkgs.writeShellScript "proxy-suite-tg-ws-proxy-start" ''
|
||||
startScript = pkgs.writeShellScript "proxy-suite-tg-ws-proxy" ''
|
||||
args=(
|
||||
--port=${toString t.listener.port}
|
||||
--host=${lib.escapeShellArg t.listener.address}
|
||||
@@ -48,7 +48,7 @@ let
|
||||
exec ${tgPkg}/bin/tg-ws-proxy "''${args[@]}"
|
||||
'';
|
||||
|
||||
bypassUpScript = pkgs.writeShellScript "proxy-suite-tg-ws-proxy-bypass-up" ''
|
||||
bypassUpScript = pkgs.writeShellScript "proxy-suite-tg-ws-proxy" ''
|
||||
set -euo pipefail
|
||||
|
||||
add_bypass_rule() {
|
||||
@@ -61,7 +61,7 @@ let
|
||||
add_bypass_rule -6
|
||||
'';
|
||||
|
||||
bypassDownScript = pkgs.writeShellScript "proxy-suite-tg-ws-proxy-bypass-down" ''
|
||||
bypassDownScript = pkgs.writeShellScript "proxy-suite-tg-ws-proxy" ''
|
||||
set +e
|
||||
|
||||
while ${ip} -4 rule del pref ${toString bypassRulePriority} fwmark ${toString t.fwmark} lookup main 2>/dev/null; do :; done
|
||||
|
||||
@@ -11,6 +11,10 @@ let
|
||||
w = derived.warpCfg;
|
||||
listener = cfg.proxy.listener;
|
||||
auth = listener.auth;
|
||||
scriptsDir = builtins.path {
|
||||
name = "proxy-suite-scripts";
|
||||
path = ../../scripts;
|
||||
};
|
||||
host =
|
||||
if
|
||||
builtins.elem listener.address [
|
||||
@@ -26,7 +30,7 @@ let
|
||||
if auth.passwordFile != null then
|
||||
auth.passwordFile
|
||||
else if auth.password != null then
|
||||
pkgs.writeText "proxy-suite-warp-proxy-password" auth.password
|
||||
pkgs.writeText "proxy-suite-warp" auth.password
|
||||
else
|
||||
null;
|
||||
userinfo = lib.optionalString (auth.username != null && passwordSource != null) ''
|
||||
@@ -34,7 +38,7 @@ let
|
||||
--rawfile p ${lib.escapeShellArg passwordSource} '"\($u | @uri):\($p | rtrimstr("\n") | @uri)@"')
|
||||
'';
|
||||
|
||||
registerScript = pkgs.writeShellScript "proxy-suite-warp-register" ''
|
||||
registerScript = pkgs.writeShellScript "proxy-suite-warp" ''
|
||||
set -euo pipefail
|
||||
[ -s wgcf-profile.conf ] && exit 0
|
||||
|
||||
@@ -73,7 +77,7 @@ let
|
||||
# Some lines drop a share of fresh WARP handshakes for good, and sing-box retries on the
|
||||
# same source port forever. A new process binds a new port, so the probe exits after
|
||||
# repeated failures and systemd starts the tunnel again.
|
||||
tunnelScript = pkgs.writeShellScript "proxy-suite-warp-tunnel" ''
|
||||
tunnelScript = pkgs.writeShellScript "proxy-suite-warp" ''
|
||||
set -euo pipefail
|
||||
profile=${lib.escapeShellArg w.profilePath}
|
||||
if [ ! -s "$profile" ]; then
|
||||
@@ -82,7 +86,7 @@ let
|
||||
fi
|
||||
|
||||
# The profile is a secret, so it is converted here rather than baked into the store.
|
||||
endpoint=$(${pkgs.python3}/bin/python3 ${../../scripts/warp_outbound.py} --tag warp --routing-mark ${toString cfg.proxy.tproxy.proxyMark} < "$profile")
|
||||
endpoint=$(${pkgs.python3}/bin/python3 ${scriptsDir}/warp_outbound.py --tag warp --routing-mark ${toString cfg.proxy.tproxy.proxyMark} < "$profile")
|
||||
${pkgs.jq}/bin/jq -n --argjson ep "$endpoint" '{
|
||||
log: {level: "warn"},
|
||||
dns: {servers: [${builtins.toJSON dnsServer}]},
|
||||
|
||||
@@ -46,13 +46,13 @@ let
|
||||
fi
|
||||
'';
|
||||
|
||||
perAppZapretMarkUpScript = pkgs.writeShellScript "proxy-suite-per-app-zapret-mark-up" ''
|
||||
perAppZapretMarkUpScript = pkgs.writeShellScript "proxy-suite-zapret" ''
|
||||
set -euo pipefail
|
||||
${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true
|
||||
${nft} -f ${perAppZapretRulesFile}
|
||||
'';
|
||||
|
||||
perAppZapretMarkDownScript = pkgs.writeShellScript "proxy-suite-per-app-zapret-mark-down" ''
|
||||
perAppZapretMarkDownScript = pkgs.writeShellScript "proxy-suite-zapret" ''
|
||||
set -euo pipefail
|
||||
${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true
|
||||
'';
|
||||
@@ -125,7 +125,7 @@ in
|
||||
wants = [ "zapret-discord-youtube.service" ];
|
||||
conflicts = awgServiceNames;
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
execStart = pkgs.writeShellScript "proxy-suite-zapret-vm-exempt-start" exemptStart;
|
||||
execStop = pkgs.writeShellScript "proxy-suite-zapret-vm-exempt-stop" exemptStop;
|
||||
execStart = pkgs.writeShellScript "proxy-suite-zapret" exemptStart;
|
||||
execStop = pkgs.writeShellScript "proxy-suite-zapret" exemptStop;
|
||||
});
|
||||
}
|
||||
@@ -20,7 +20,7 @@ let
|
||||
tunInterfaces ? [ ],
|
||||
scope ? "global",
|
||||
}:
|
||||
pkgs.writeText "proxy-suite-zapret-bypass.sh" ''
|
||||
pkgs.writeText "proxy-suite-zapret" ''
|
||||
# Upstream presets can select iptables explicitly, in which case the nft
|
||||
# hook below is never called. Use upstream helpers for idempotent start
|
||||
# and stop, and distinct comments so each service owns its exemptions.
|
||||
@@ -205,10 +205,10 @@ let
|
||||
${lib.concatMapStrings (
|
||||
rule:
|
||||
let
|
||||
domainsFile = pkgs.writeText "proxy-suite-zapret-hostlist-${rule.name}.txt" (
|
||||
domainsFile = pkgs.writeText "proxy-suite-zapret" (
|
||||
lib.concatStringsSep "\n" (lib.unique rule.domains) + "\n"
|
||||
);
|
||||
ipsetFile = pkgs.writeText "proxy-suite-zapret-ipset-${rule.name}.txt" (
|
||||
ipsetFile = pkgs.writeText "proxy-suite-zapret" (
|
||||
lib.concatStringsSep "\n" (lib.unique rule.ips) + "\n"
|
||||
);
|
||||
in
|
||||
|
||||
@@ -54,15 +54,18 @@ let
|
||||
if upstreamPackages ? zapret then upstreamPackages.zapret else upstreamPackages.default;
|
||||
|
||||
mkOptionalHostlistFile =
|
||||
fileName: entries:
|
||||
if entries != [ ] then pkgs.writeText fileName (lib.concatStringsSep "\n" entries + "\n") else null;
|
||||
entries:
|
||||
if entries != [ ] then
|
||||
pkgs.writeText "proxy-suite-zapret" (lib.concatStringsSep "\n" entries + "\n")
|
||||
else
|
||||
null;
|
||||
|
||||
listGeneralFile = mkOptionalHostlistFile "proxy-suite-zapret-list-general-user.txt" zapretCfg.zapret-discord-youtube.domains;
|
||||
listExcludeFile = mkOptionalHostlistFile "proxy-suite-zapret-list-exclude-user.txt" zapretCfg.zapret-discord-youtube.excludeDomains;
|
||||
ipsetAllFile = mkOptionalHostlistFile "proxy-suite-zapret-ipset-all.txt" zapretCfg.zapret-discord-youtube.ips;
|
||||
ipsetExcludeFile = mkOptionalHostlistFile "proxy-suite-zapret-ipset-exclude-user.txt" zapretCfg.zapret-discord-youtube.excludeIps;
|
||||
listGeneralFile = mkOptionalHostlistFile zapretCfg.zapret-discord-youtube.domains;
|
||||
listExcludeFile = mkOptionalHostlistFile zapretCfg.zapret-discord-youtube.excludeDomains;
|
||||
ipsetAllFile = mkOptionalHostlistFile zapretCfg.zapret-discord-youtube.ips;
|
||||
ipsetExcludeFile = mkOptionalHostlistFile zapretCfg.zapret-discord-youtube.excludeIps;
|
||||
|
||||
hostlistRuleSpec = pkgs.writeText "proxy-suite-zapret-hostlist-rules.json" (
|
||||
hostlistRuleSpec = pkgs.writeText "proxy-suite-zapret" (
|
||||
builtins.toJSON {
|
||||
includeExtraUpstreamLists = zapretCfg.zapret-discord-youtube.includeExtraUpstreamLists;
|
||||
entries = map (rule: {
|
||||
@@ -81,10 +84,12 @@ let
|
||||
);
|
||||
|
||||
selectedConfigName = lib.strings.sanitizeDerivationName zapretCfg.zapret-discord-youtube.configName;
|
||||
patchConfigScriptSrc = builtins.path {
|
||||
path = ../../../scripts/patch-zapret-config.py;
|
||||
name = "patch-zapret-config.py";
|
||||
};
|
||||
patchConfigScriptSrc = "${
|
||||
builtins.path {
|
||||
name = "proxy-suite-scripts";
|
||||
path = ../../../scripts;
|
||||
}
|
||||
}/patch-zapret-config.py";
|
||||
patchConfigScript = "${pkgs.python3}/bin/python3 ${patchConfigScriptSrc}";
|
||||
|
||||
packageBuilder = import ./package-builder.nix {
|
||||
|
||||
@@ -59,7 +59,7 @@ let
|
||||
|
||||
# Wrapped apps opted in: MODE_FILTER=none applies every profile to all their traffic.
|
||||
perAppRuntime = runtime.mkRuntime {
|
||||
name = "proxy-suite-per-app-zapret2";
|
||||
name = "proxy-suite-zapret2";
|
||||
qnum = perAppZapretCfg.qnum;
|
||||
desyncMark = 134217728; # 0x8000000
|
||||
desyncMarkPostnat = 67108864; # 0x4000000
|
||||
@@ -87,13 +87,13 @@ let
|
||||
;
|
||||
};
|
||||
|
||||
perAppZapretMarkUpScript = pkgs.writeShellScript "proxy-suite-per-app-zapret2-mark-up" ''
|
||||
perAppZapretMarkUpScript = pkgs.writeShellScript "proxy-suite-zapret2" ''
|
||||
set -euo pipefail
|
||||
${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true
|
||||
${nft} -f ${perAppZapretRulesFile}
|
||||
'';
|
||||
|
||||
perAppZapretMarkDownScript = pkgs.writeShellScript "proxy-suite-per-app-zapret2-mark-down" ''
|
||||
perAppZapretMarkDownScript = pkgs.writeShellScript "proxy-suite-zapret2" ''
|
||||
set -euo pipefail
|
||||
${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true
|
||||
'';
|
||||
|
||||
@@ -36,7 +36,7 @@ let
|
||||
|
||||
# $1 asn.txt, $2 sni.txt, $3 AS-to-prefix map; prints a sing-box source rule-set
|
||||
# with the prefixes of every cut-off network that no whitelisted name fixes.
|
||||
proxyRules = pkgs.writeShellScript "proxy-suite-zapret2-cutoff-rules" ''
|
||||
proxyRules = pkgs.writeShellScript "proxy-suite-zapret2" ''
|
||||
set -euo pipefail
|
||||
${pkgs.gawk}/bin/awk -F'\t' '
|
||||
FILENAME == ARGV[1] { if ($1 ~ /^[0-9]+$/) cut[$1] = 1; next }
|
||||
@@ -48,7 +48,7 @@ let
|
||||
| {version: 1, rules: (if length > 0 then [{ip_cidr: .}] else [] end)}'
|
||||
'';
|
||||
|
||||
probe = pkgs.writeShellScript unit ''
|
||||
probe = pkgs.writeShellScript "proxy-suite-zapret2" ''
|
||||
set -euo pipefail
|
||||
export PATH=${
|
||||
lib.makeBinPath [
|
||||
@@ -130,7 +130,7 @@ let
|
||||
# The probe measures this line, so its traffic leaves directly: proxyMark keeps it
|
||||
# out of TUN/TProxy like the backend's own, and the conntrack bit keeps zapret2 from
|
||||
# touching or learning it.
|
||||
exempt = pkgs.writeShellScript "${unit}-exempt" ''
|
||||
exempt = pkgs.writeShellScript "proxy-suite-zapret2" ''
|
||||
set -euo pipefail
|
||||
${nft} delete table inet ${table} 2>/dev/null || true
|
||||
${nft} -f - <<EOF
|
||||
|
||||
@@ -83,7 +83,7 @@ let
|
||||
if zapret2Cfg.profiles == null && isZ2k then
|
||||
"${z2kGenerated}/profiles"
|
||||
else
|
||||
pkgs.writeText "proxy-suite-zapret2-profiles" (
|
||||
pkgs.writeText "proxy-suite-zapret2" (
|
||||
lib.concatStringsSep " --new " (map renderProfile (orSource zapret2Cfg.profiles source.profiles))
|
||||
);
|
||||
|
||||
@@ -91,7 +91,7 @@ let
|
||||
if isZ2k then
|
||||
"${z2kGenerated}/blobs"
|
||||
else
|
||||
pkgs.writeText "proxy-suite-zapret2-blobs" (lib.concatStringsSep " " source.blobArgs);
|
||||
pkgs.writeText "proxy-suite-zapret2" (lib.concatStringsSep " " source.blobArgs);
|
||||
|
||||
# The state layer wraps circular, so it loads after the source's Lua. z2k-tcp16
|
||||
# does nothing until the cutoff probe has written its maps.
|
||||
@@ -138,7 +138,7 @@ let
|
||||
modeFilter,
|
||||
}:
|
||||
let
|
||||
header = pkgs.writeText "proxy-suite-zapret2-config-header" (
|
||||
header = pkgs.writeText "proxy-suite-zapret2" (
|
||||
lib.concatStringsSep "\n" (
|
||||
[
|
||||
"# Generated by proxy-suite. Do not edit."
|
||||
@@ -175,7 +175,7 @@ let
|
||||
)
|
||||
);
|
||||
in
|
||||
pkgs.runCommand "proxy-suite-zapret2-config"
|
||||
pkgs.runCommand "proxy-suite-zapret2"
|
||||
{
|
||||
nativeBuildInputs = [ pkgs.gawk ];
|
||||
inherit circularFill optPrefix;
|
||||
@@ -259,7 +259,7 @@ let
|
||||
) exemptCidrs
|
||||
) chains;
|
||||
in
|
||||
pkgs.writeText "proxy-suite-zapret2-custom.sh" (
|
||||
pkgs.writeText "proxy-suite-zapret2" (
|
||||
lib.concatStringsSep "\n" (
|
||||
[ "zapret_custom_firewall_nft() {" ]
|
||||
++ rules
|
||||
|
||||
@@ -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("grep -r '${uuid}' /nix/store/*proxy-suite-inbounds-*.json")
|
||||
server.fail("grep -r '${uuid}' /nix/store/*-proxy-suite-inbounds")
|
||||
|
||||
with subtest("safety rules are present and ordered first"):
|
||||
cfg = "/run/proxy-suite-inbounds/config.json"
|
||||
|
||||
@@ -18,9 +18,9 @@ let
|
||||
# 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:
|
||||
value:
|
||||
builtins.unsafeDiscardStringContext "${
|
||||
pkgs.writeText "proxy-suite-ob-ssh-proxy-${backend}.json" (builtins.toJSON value)
|
||||
pkgs.writeText "proxy-suite-core" (builtins.toJSON value)
|
||||
}";
|
||||
|
||||
# SingBox dials SSH natively: no unit, no local SOCKS listener.
|
||||
@@ -47,7 +47,7 @@ let
|
||||
sshNativeSingBoxStart = generated.readDerivation (
|
||||
sshNativeSingBox.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
expectedNativeSingBoxOutbound = expectedOutboundFile "sing-box" {
|
||||
expectedNativeSingBoxOutbound = expectedOutboundFile {
|
||||
type = "ssh";
|
||||
tag = "ssh-proxy";
|
||||
server = "ssh.example.com";
|
||||
@@ -151,7 +151,7 @@ let
|
||||
);
|
||||
xrayService = sshXray.config.systemd.services."proxy-suite-ssh-proxy";
|
||||
xrayStartScript = generated.readDerivation xrayService.serviceConfig.ExecStart;
|
||||
expectedXrayOutbound = expectedOutboundFile "xray" {
|
||||
expectedXrayOutbound = expectedOutboundFile {
|
||||
protocol = "socks";
|
||||
tag = "ssh-proxy";
|
||||
settings = {
|
||||
@@ -186,7 +186,7 @@ let
|
||||
sshHybridStart = generated.readDerivation (
|
||||
sshHybrid.config.systemd.services."proxy-suite-socks".serviceConfig.ExecStart
|
||||
);
|
||||
expectedHybridOutbound = expectedOutboundFile "hybrid" {
|
||||
expectedHybridOutbound = expectedOutboundFile {
|
||||
type = "ssh";
|
||||
tag = "ssh-proxy";
|
||||
server = "ssh.example.com";
|
||||
@@ -512,7 +512,7 @@ let
|
||||
true
|
||||
)
|
||||
(
|
||||
assert pkgs.lib.hasInfix "proxy-suite-ob-ssh-proxy-xray.json" sshUrltestStart;
|
||||
assert pkgs.lib.hasInfix "# outbound: ssh-proxy (OpenSSH SOCKS5 listener)" sshUrltestStart;
|
||||
true
|
||||
)
|
||||
(
|
||||
|
||||
@@ -162,7 +162,7 @@ in
|
||||
test "$(grep -c 'ct mark and 0x2000000 != 0 return' "${globalRuntime}/init.d/sysv/custom.d/50-proxy-suite-custom.sh")" = 4
|
||||
|
||||
# Cut-off networks without a name become the proxy's rule-set; named ones stay with zapret2.
|
||||
rules=$(grep -o '/nix/store/[^ ]*-proxy-suite-zapret2-cutoff-rules' ${cutoffProbe} | head -n1)
|
||||
rules=$(grep -oE '/nix/store/[^ ]+-proxy-suite-zapret2 asn.txt' ${cutoffProbe} | cut -d' ' -f1)
|
||||
printf '# networks\n24940\n14061\n' >asn.txt
|
||||
printf '24940\t300.ya.ru\n' >sni.txt
|
||||
printf '# map\n24940\t5.9.0.0/16\n14061\t104.131.0.0/16\n14061\t2604:a880::/32\n7777\t1.2.0.0/16\n' >nets.txt
|
||||
|
||||
Reference in new issue
Block a user