chore: collapse packages
This commit is contained in:
29 files changed
+151
-111
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user