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:
FUFSoB committed 2026-09-13 22:37:45 +05:00
1 parent b892384527
commit fdb2b08790
144 files changed
+13198 -14066

No files matched your search

+2
View File
@@ -3,6 +3,7 @@ let
amneziaWg = import ./amneziawg.nix { inherit pkgs; };
mkTgWsProxy = _args: import ./tg-ws-proxy.nix { inherit pkgs; };
mkProxySuiteTray = args: import ./proxy-suite-tray.nix ({ inherit pkgs; } // args);
zapret2 = import ./zapret2.nix { inherit pkgs; };
mkProxyCtl = import ./proxy-ctl.nix {
lib = pkgs.lib;
inherit pkgs;
@@ -16,6 +17,7 @@ in
mkTgWsProxy
mkProxySuiteTray
mkProxyCtl
zapret2
;
tg-ws-proxy = mkTgWsProxy { };
proxy-suite-tray = mkProxySuiteTray { };
+7
View File
@@ -0,0 +1,7 @@
# proxy-ctl knows its own verbs, tags, profiles and units: ask it.
_proxy_ctl() {
mapfile -t COMPREPLY < <(
compgen -W "$(proxy-ctl __complete "${COMP_WORDS[@]:1:COMP_CWORD-1}" 2>/dev/null)" \
-- "${COMP_WORDS[COMP_CWORD]}")
}
complete -F _proxy_ctl proxy-ctl
+1330 -492
View File
File diff suppressed because it is too large. Load diff
+42 -18
View File
@@ -21,6 +21,19 @@
amneziaWgProfileNamesFile,
inboundsEnabled,
inboundsLinksFile,
inboundsStatsFile,
inboundsSubscriptionsFile,
inboundsSubscriptionsBaseUrl,
zapretAutoEnabled,
zapretStateDir,
priorityOutboundFile,
outboundInventoryFile,
runtimeOutboundsDir,
runtimeSubscriptionsDir,
userControlGroup,
localProxyUrl,
autoProxyEnabled,
autoProxyStateDir,
}:
let
@@ -45,6 +58,19 @@ let
AWG_PROFILES_FILE = toString amneziaWgProfileNamesFile;
INBOUNDS_ENABLED = inboundsEnabled;
INBOUNDS_LINKS_FILE = inboundsLinksFile;
INBOUNDS_STATS_FILE = inboundsStatsFile;
INBOUNDS_SUBS_FILE = inboundsSubscriptionsFile;
INBOUNDS_SUB_BASE_URL = inboundsSubscriptionsBaseUrl;
ZAPRET_AUTO_ENABLED = zapretAutoEnabled;
ZAPRET_STATE_DIR = zapretStateDir;
PRIORITY_OUTBOUND_FILE = priorityOutboundFile;
OUTBOUND_INVENTORY_FILE = outboundInventoryFile;
RUNTIME_OUTBOUNDS_DIR = runtimeOutboundsDir;
RUNTIME_SUBS_DIR = runtimeSubscriptionsDir;
USER_CONTROL_GROUP = userControlGroup;
LOCAL_PROXY_URL = localProxyUrl;
AUTOPROXY_ENABLED = autoProxyEnabled;
AUTOPROXY_STATE_DIR = autoProxyStateDir;
};
in
pkgs.symlinkJoin {
@@ -61,12 +87,23 @@ pkgs.symlinkJoin {
;
script = unwrapped.drvAttrs.text;
};
# Probes present a browser's TLS fingerprint: bot protection refuses plain
# curl. The newest Chrome profile the package ships, since the set varies by
# version; the build fails if there is none.
postBuild = ''
install -Dm644 ${./proxy-ctl-completion.bash} \
"$out/share/bash-completion/completions/proxy-ctl"
probe_curl=$(ls ${pkgs.curl-impersonate}/bin/curl_chrome[0-9]* | grep -E '/curl_chrome[0-9]+$' | sort -V | tail -n 1)
[ -x "$probe_curl" ]
wrapProgram "$out/bin/proxy-ctl" \
--set PROBE_CURL "$probe_curl" \
--prefix PATH : "${
lib.makeBinPath [
# curl-impersonate's curl_chrome* wrappers are `#!/usr/bin/env bash`.
pkgs.bash
pkgs.coreutils
pkgs.curl
pkgs.fzf
pkgs.gawk
pkgs.gnugrep
pkgs.jq
@@ -74,23 +111,10 @@ pkgs.symlinkJoin {
pkgs.qrencode
pkgs.systemd
]
}" \
--set CLASH_API ${lib.escapeShellArg clashApi} \
--set SELECTION ${lib.escapeShellArg selection} \
--set SUB_TAGS_FILE ${lib.escapeShellArg (toString subscriptionTagsFile)} \
--set SUB_CACHE_DIR ${lib.escapeShellArg subscriptionCacheDir} \
--set PER_APP_ROUTING_ENABLED ${lib.escapeShellArg perAppRoutingEnabled} \
--set PER_APP_ROUTING_PROXYCHAINS_ENABLED ${lib.escapeShellArg perAppRoutingProxychainsEnabled} \
--set PER_APP_ROUTING_TUN_ENABLED ${lib.escapeShellArg perAppRoutingTunEnabled} \
--set PER_APP_ROUTING_TPROXY_ENABLED ${lib.escapeShellArg perAppRoutingTproxyEnabled} \
--set PER_APP_ROUTING_ZAPRET_ENABLED ${lib.escapeShellArg perAppRoutingZapretEnabled} \
--set PER_APP_ROUTING_PROFILES_FILE ${lib.escapeShellArg (toString perAppRoutingProfilesFile)} \
--set PROXYCHAINS_CONFIG ${lib.escapeShellArg (toString proxychainsConfigFile)} \
--set PROXYCHAINS_QUIET_ARG ${lib.escapeShellArg (lib.removeSuffix " " proxychainsQuietArg)} \
--set ROUTE_MODE_STATE_FILE ${lib.escapeShellArg routeModeStateFile} \
--set DEFAULT_ROUTE_MODE ${lib.escapeShellArg defaultRouteMode} \
--set AWG_PROFILES_FILE ${lib.escapeShellArg (toString amneziaWgProfileNamesFile)} \
--set INBOUNDS_ENABLED ${lib.escapeShellArg inboundsEnabled} \
--set INBOUNDS_LINKS_FILE ${lib.escapeShellArg inboundsLinksFile}
}" ${
lib.concatStringsSep " " (
lib.mapAttrsToList (name: value: "--set ${name} ${lib.escapeShellArg value}") wrapperEnv
)
}
'';
}
+26 -76
View File
@@ -1,95 +1,45 @@
set -euo pipefail
# Wrapped binary provides runtime config through env vars.
SUB_TAGS_FILE="${SUB_TAGS_FILE:-}"
AWG_PROFILES_FILE="${AWG_PROFILES_FILE:-}"
PROXYCHAINS_QUIET_ARG="${PROXYCHAINS_QUIET_ARG:-}"
SUB_TAGS=()
AWG_PROFILES=()
if [ -n "$SUB_TAGS_FILE" ] && [ -f "$SUB_TAGS_FILE" ]; then
if [ -f "${SUB_TAGS_FILE:-}" ]; then
mapfile -t SUB_TAGS < <(jq -r '.[]' "$SUB_TAGS_FILE")
fi
if [ -n "$AWG_PROFILES_FILE" ] && [ -f "$AWG_PROFILES_FILE" ]; then
if [ -f "${AWG_PROFILES_FILE:-}" ]; then
mapfile -t AWG_PROFILES < <(jq -r '.[]' "$AWG_PROFILES_FILE")
fi
# Old spellings: still accepted, not in the help.
case "${1:-}" in
tun | tproxy | outbounds | select) set -- proxy "$@" ;;
route-mode) shift; set -- proxy mode "$@" ;;
subscription) shift; set -- proxy subs "$@" ;;
wrap) shift; set -- apps run "$@" ;;
esac
cmd="${1:-status}"
shift || true
case "$cmd" in
help)
_usage 0
;;
status)
cmd_status "$@"
;;
proxy)
cmd_proxy "$@"
;;
tproxy)
cmd_mode_toggle proxy-suite-tproxy on "${1:-}"
;;
tun)
cmd_mode_toggle proxy-suite-tun on "${1:-}"
;;
ssh)
cmd_mode_toggle proxy-suite-ssh-proxy on "${1:-}" ssh
;;
awg)
cmd_awg "$@"
;;
route-mode)
cmd_route_mode "$@"
;;
zapret)
cmd_zapret "$@"
;;
restart)
cmd_restart
;;
help | -h | --help) _help ;;
status) cmd_status "$@" ;;
restart) cmd_restart ;;
logs)
svc="${1:-proxy-suite-socks}"
shift || true
exec journalctl -fu "$svc" "$@"
if [ "$#" -gt 0 ]; then exec journalctl -fu "$@"; fi
# journalctl takes unit globs, so the default needs no unit list of its own.
exec journalctl -f -u 'proxy-suite-*' -u zapret-discord-youtube
;;
outbounds)
cmd_outbounds
;;
select)
cmd_select "$@"
;;
apps)
cmd_apps
;;
wrap)
cmd_wrap "$@"
;;
inbounds)
cmd_inbounds "$@"
;;
subscription)
cmd_subscription "$@"
;;
proxy) cmd_proxy "$@" ;;
zapret) cmd_zapret "$@" ;;
awg) cmd_awg "$@" ;;
ssh) _toggle proxy-suite-ssh-proxy ssh "$@" ;;
apps) cmd_apps "$@" ;;
inbounds) cmd_inbounds "$@" ;;
where) cmd_where "$@" ;;
__complete) cmd_complete "$@" ;;
*)
_usage 1
_help >&2
exit 1
;;
esac
+7 -7
View File
@@ -753,11 +753,11 @@ static void on_tproxy_toggle(GtkWidget *item, gpointer data)
ServiceState state = get_service_state();
if (state.tproxy)
{
run_proxy_ctl("tproxy", "off");
run_proxy_ctl3("proxy", "tproxy", "off");
}
else
{
run_proxy_ctl("tproxy", "on");
run_proxy_ctl3("proxy", "tproxy", "on");
}
update_status();
}
@@ -774,7 +774,7 @@ static void on_route_mode_menu_toggled(GtkCheckMenuItem *item, gpointer data)
{
return;
}
run_proxy_ctl("route-mode", mode);
run_proxy_ctl3("proxy", "mode", mode);
update_status();
}
@@ -798,7 +798,7 @@ static void on_route_mode_combo_changed(GtkComboBox *combo, gpointer data)
{
return;
}
run_proxy_ctl("route-mode", mode);
run_proxy_ctl3("proxy", "mode", mode);
update_status();
}
@@ -809,11 +809,11 @@ static void on_tun_toggle(GtkWidget *item, gpointer data)
ServiceState state = get_service_state();
if (state.tun)
{
run_proxy_ctl("tun", "off");
run_proxy_ctl3("proxy", "tun", "off");
}
else
{
run_proxy_ctl("tun", "on");
run_proxy_ctl3("proxy", "tun", "on");
}
update_status();
}
@@ -884,7 +884,7 @@ static void on_subscription_update(GtkWidget *item, gpointer data)
{
(void)item;
(void)data;
run_proxy_ctl("subscription", "update");
run_proxy_ctl3("proxy", "subs", "update");
}
static void on_open_controls(GtkWidget *item, gpointer data)
+2 -2
View File
@@ -4,8 +4,8 @@ let
src = pkgs.fetchFromGitHub {
owner = "Flowseal";
repo = "tg-ws-proxy";
rev = "v1.10.1";
hash = "sha256-/X0dGXnyxVSQOgpETzvw+jBEjSSgj5tMHzwPxVenKII=";
rev = "v1.10.2";
hash = "sha256-XpO0Hmi0Hotu5TdOZ6+Cg/YBaF31RHJ5MfPJ1JKpPr8=";
};
pythonEnv = pkgs.python3.withPackages (
+27
View File
@@ -0,0 +1,27 @@
# Xray-core ahead of nixpkgs, which still ships 26.3.27. From 26.9.8 its go.mod
# asks for Go 1.27, so the builder is swapped along with the source. Steps
# aside once nixpkgs has caught up.
{ pkgs }:
let
inherit (pkgs) lib;
version = "26.9.9";
in
if lib.versionAtLeast pkgs.xray.version version then
pkgs.xray
else
(pkgs.xray.override (
args: lib.optionalAttrs (args ? buildGo126Module) { buildGo126Module = pkgs.buildGo127Module; }
)).overrideAttrs
(
finalAttrs: _: {
inherit version;
src = pkgs.fetchFromGitHub {
owner = "XTLS";
repo = "Xray-core";
rev = "v${finalAttrs.version}";
hash = "sha256-GqPEAgWM9Wx19uxMj0LGeOyHreLbU0IMSmalwLe/SIc=";
};
vendorHash = "sha256-6Qa05hFdvfLlH8WQd426IU7MScmeevIgrgP5037pNek=";
}
)
+68
View File
@@ -0,0 +1,68 @@
# zapret2 / nfqws2 - the Lua-strategy successor to zapret's nfqws.
#
# Unlike the zapret v1 packaging, nothing here is patched for NixOS beyond making
# PIDDIR overridable: the init scripts already take ZAPRET_BASE, ZAPRET_RW,
# ZAPRET_CONFIG and HOSTLIST_BASE from the environment, and the unit supplies PATH.
{ pkgs }:
let
version = "1.0.5.1";
in
pkgs.stdenv.mkDerivation {
pname = "zapret2";
inherit version;
src = pkgs.fetchFromGitHub {
owner = "bol-van";
repo = "zapret2";
tag = "v${version}";
hash = "sha256-cb83DXeHExdLPjB283i1sU+GtqrwVtUXBbTloXsnvlA=";
};
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [
pkgs.libcap
pkgs.libmnl
pkgs.libnetfilter_queue
pkgs.libnfnetlink
pkgs.luajit
pkgs.systemdLibs
pkgs.zlib
];
# "systemd" is the plain linux target plus -DUSE_SYSTEMD; ip2net and mdig are
# only used by the ipset list-download scripts, which this suite does not run.
buildPhase = ''
runHook preBuild
make -C nfq2 systemd
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p "$out/opt/zapret2" "$out/bin"
cp -r common init.d ipset lua files config.default "$out/opt/zapret2/"
install -Dm755 nfq2/nfqws2 "$out/opt/zapret2/nfq2/nfqws2"
ln -s "$out/opt/zapret2/nfq2/nfqws2" "$out/bin/nfqws2"
chmod +x "$out/opt/zapret2/init.d/sysv/zapret2"
find "$out/opt/zapret2" -name '*.sh' -exec chmod +x {} +
# Everything else the init scripts need is already env-overridable; PIDDIR is
# not, and two instances (global + per-app) must not share a pidfile.
substituteInPlace "$out/opt/zapret2/init.d/sysv/functions" \
--replace-fail 'PIDDIR=/var/run' 'PIDDIR=''${PIDDIR:-/var/run}'
runHook postInstall
'';
meta = with pkgs.lib; {
description = "DPI bypass utility with Lua-scripted desync strategies (nfqws2)";
homepage = "https://github.com/bol-van/zapret2";
license = licenses.mit;
platforms = platforms.linux;
mainProgram = "nfqws2";
};
}