breaking options changes, refactor

This commit is contained in:
FUFSoB committed 2026-04-16 23:27:05 +05:00
1 parent ba7560bfac
commit 93e792f2e5
18 files changed
+1995 -1752

No files matched your search

-231
View File
@@ -1,231 +0,0 @@
# Per-app routing options (backends and profiles).
{ lib, ... }:
let
inherit (lib) mkOption mkEnableOption types;
t = import ./types.nix { inherit lib; };
in
{
options.services.proxy-suite.appRouting = {
enable = mkEnableOption "per-app routing helpers via proxy-ctl wrap";
createDefaultProfiles = mkOption {
type = types.bool;
default = false;
description = ''
Whether to automatically add curated appRouting profiles.
This is opt-in. Generated defaults are appended only when no
user-defined profile with the same name already exists.
Current curated defaults:
- `proxychains`: route = "proxychains"
- `tun`: route = "tun" when appRouting.backends.tun.enable = true
- `tproxy`: route = "tproxy" when appRouting.backends.tproxy.enable = true
- `zapret`: route = "zapret" when appRouting.backends.zapret.enable = true
and zapret.enable = true
This makes `proxy-ctl wrap proxychains -- <command>` available
without defining the profile manually, and similarly exposes
`proxy-ctl wrap tun -- <command>` or
`proxy-ctl wrap tproxy -- <command>` or
`proxy-ctl wrap zapret -- <command>` when the corresponding backend
is enabled.
'';
example = true;
};
profiles = mkOption {
type = types.listOf t.appRoutingProfileType;
default = [ ];
description = ''
Named per-app route profiles consumed by `proxy-ctl wrap`.
This initial implementation supports:
- "direct" for running a command unchanged
- "proxychains" for TCP apps that can use an LD_PRELOAD wrapper
instead of global TUN or TProxy interception
- "tun" for app-scoped policy routing into the dedicated app TUN
backend
- "tproxy" for app-scoped transparent interception through the
dedicated app TProxy backend
- "zapret" for app-scoped zapret handling through a separate
zapret instance without changing the app's network path or exit IP
proxychains-based wrapping depends on the local proxy-suite mixed
proxy listener provided by sing-box. The "tun" route depends on
appRouting.backends.tun.enable = true. The "tproxy" route depends on
appRouting.backends.tproxy.enable = true. The "zapret" route depends
on appRouting.backends.zapret.enable = true and zapret.enable = true.
When createDefaultProfiles = true, curated defaults are added on top
of this list unless a user-defined profile already uses the same
name.
'';
example = [
{
name = "steam-browser";
route = "proxychains";
}
{
name = "native-direct";
route = "direct";
}
];
};
proxychains = {
enable = mkEnableOption "proxychains-backed appRouting profiles";
quiet = mkOption {
type = types.bool;
default = true;
description = ''
Whether generated proxychains wrappers should suppress their normal
startup chatter. This maps to proxychains-ng quiet_mode.
'';
example = true;
};
proxyDns = mkOption {
type = types.bool;
default = true;
description = ''
Whether generated proxychains wrappers should resolve DNS through
the proxy instead of the local resolver. This maps to proxychains-ng
proxy_dns.
'';
example = true;
};
};
backends = {
tun = {
enable = mkEnableOption "app-scoped TUN backend for appRouting profiles";
interface = mkOption {
type = types.str;
default = "psapptun0";
description = ''
Name of the dedicated app-routing TUN interface used by
proxy-suite-app-tun.
'';
example = "psapptun0";
};
address = mkOption {
type = types.str;
default = "172.20.0.1/30";
description = ''
Address assigned to the app-routing TUN interface in CIDR
notation.
'';
example = "172.20.0.1/30";
};
mtu = mkOption {
type = types.int;
default = 1400;
description = ''
MTU for the app-routing TUN interface.
'';
example = 1400;
};
fwmark = mkOption {
type = types.int;
default = 16;
description = ''
Packet mark used to steer wrapped app traffic into the app-routing
TUN policy-routing table.
'';
example = 16;
};
routeTable = mkOption {
type = types.int;
default = 101;
description = ''
Policy-routing table used by the app-routing TUN backend.
'';
example = 101;
};
localSubnets = mkOption {
type = types.listOf types.str;
default = [ "192.168.0.0/16" ];
description = ''
Destination subnets that should bypass the app-routing TUN mark,
so wrapped apps can still reach local LAN resources directly.
'';
example = [
"192.168.0.0/16"
"10.0.0.0/8"
];
};
};
tproxy = {
enable = mkEnableOption "app-scoped TProxy backend for appRouting profiles";
fwmark = mkOption {
type = types.int;
default = 17;
description = ''
Packet mark used to steer wrapped app traffic into the app-routing
TProxy policy-routing table.
'';
example = 17;
};
routeTable = mkOption {
type = types.int;
default = 102;
description = ''
Policy-routing table used by the app-routing TProxy backend.
'';
example = 102;
};
localSubnets = mkOption {
type = types.listOf types.str;
default = [ "192.168.0.0/16" ];
description = ''
Destination subnets that should bypass app-routing TProxy
interception, except DNS traffic on port 53.
'';
example = [
"192.168.0.0/16"
"10.0.0.0/8"
];
};
};
zapret = {
enable = mkEnableOption "app-scoped zapret backend for appRouting profiles";
filterMark = mkOption {
type = types.int;
default = 268435456;
description = ''
Packet mark bit used to mark wrapped app traffic for the
dedicated app-scoped zapret instance.
'';
example = 268435456;
};
qnum = mkOption {
type = types.int;
default = 201;
description = ''
NFQUEUE number used by the dedicated app-scoped zapret instance.
This backend runs as a second zapret daemon and should use a
queue distinct from the global zapret instance.
'';
example = 201;
};
};
};
};
}
+1 -1
View File
@@ -4,7 +4,7 @@
imports = [
./other.nix
./sing-box.nix
./app-routing.nix
./per-app-routing.nix
./zapret.nix
];
}
@@ -0,0 +1,102 @@
# Per-app routing options (backends and profiles).
{ lib, ... }:
let
inherit (lib) mkOption mkEnableOption types;
t = import ./types.nix { inherit lib; };
in
{
options.services.proxy-suite.perAppRouting = {
enable = mkEnableOption "per-app routing helpers via proxy-ctl wrap";
createDefaultProfiles = mkOption {
type = types.bool;
default = false;
description = ''
Whether to automatically add curated perAppRouting profiles.
This is opt-in. Generated defaults are appended only when no
user-defined profile with the same name already exists.
Current curated defaults:
- `proxychains`: route = "proxychains"
- `tun`: route = "tun" when singBox.tun.perApp.enable = true
- `tproxy`: route = "tproxy" when singBox.tproxy.perApp.enable = true
- `zapret`: route = "zapret" when zapret.perApp.enable = true and
zapret.enable = true
This makes `proxy-ctl wrap proxychains -- <command>` available
without defining the profile manually, and similarly exposes
`proxy-ctl wrap tun -- <command>` or
`proxy-ctl wrap tproxy -- <command>` or
`proxy-ctl wrap zapret -- <command>` when the corresponding backend
is enabled.
'';
example = true;
};
profiles = mkOption {
type = types.listOf t.perAppRoutingProfileType;
default = [ ];
description = ''
Named per-app route profiles consumed by `proxy-ctl wrap`.
This initial implementation supports:
- "direct" for running a command unchanged
- "proxychains" for TCP apps that can use an LD_PRELOAD wrapper
instead of global TUN or TProxy interception
- "tun" for per-app-scoped policy routing into the dedicated app TUN
backend
- "tproxy" for per-app-scoped transparent interception through the
dedicated app TProxy backend
- "zapret" for per-app-scoped zapret handling through a separate
zapret instance without changing the app's network path or exit IP
proxychains-based wrapping depends on singBox.enable = true and the
local proxy-suite mixed proxy listener provided by sing-box. The
"tun" route depends on singBox.tun.perApp.enable = true. The "tproxy"
route depends on singBox.tproxy.perApp.enable = true. The "zapret"
route depends on zapret.perApp.enable = true and zapret.enable = true.
When createDefaultProfiles = true, curated defaults are added on top
of this list unless a user-defined profile already uses the same
name.
'';
example = [
{
name = "steam-browser";
route = "proxychains";
}
{
name = "native-direct";
route = "direct";
}
];
};
proxychains = {
enable = mkEnableOption "proxychains-backed perAppRouting profiles";
quiet = mkOption {
type = types.bool;
default = true;
description = ''
Whether generated proxychains wrappers should suppress their normal
startup chatter. This maps to proxychains-ng quiet_mode.
'';
example = true;
};
proxyDns = mkOption {
type = types.bool;
default = true;
description = ''
Whether generated proxychains wrappers should resolve DNS through
the proxy instead of the local resolver. This maps to proxychains-ng
proxy_dns.
'';
example = true;
};
};
};
}
+174 -66
View File
@@ -4,6 +4,38 @@
let
inherit (lib) mkOption mkEnableOption types;
t = import ./types.nix { inherit lib; };
mkTunCommonFields =
{
interfaceDefault,
interfaceDescription,
addressDefault,
addressDescription,
mtuDefault,
mtuDescription,
}:
{
interface = mkOption {
type = types.str;
default = interfaceDefault;
description = interfaceDescription;
example = interfaceDefault;
};
address = mkOption {
type = types.str;
default = addressDefault;
description = addressDescription;
example = addressDefault;
};
mtu = mkOption {
type = types.int;
default = mtuDefault;
description = mtuDescription;
example = mtuDefault;
};
};
in
{
options.services.proxy-suite.singBox = {
@@ -12,8 +44,8 @@ in
default = true;
description = ''
Whether to configure and run sing-box services for proxy-suite.
When disabled, singBox.* options are ignored even if proxy-suite itself
is enabled.
When disabled, sing-box services and generated sing-box configs are
skipped even if proxy-suite itself is enabled.
'';
};
@@ -183,49 +215,6 @@ in
example = 1080;
};
tproxyPort = mkOption {
type = types.port;
default = 1081;
description = ''
Local listen port for sing-box's TProxy inbound.
nftables redirection created by proxy-suite-tproxy sends intercepted
TCP/UDP traffic to this port.
'';
example = 1081;
};
fwmark = mkOption {
type = types.int;
default = 1;
description = ''
Mark applied to intercepted packets in TProxy mode.
A matching `ip rule` routes this mark to singBox.routeTable, which
points traffic to loopback for local proxy processing.
'';
example = 1;
};
proxyMark = mkOption {
type = types.int;
default = 2;
description = ''
Mark applied to sing-box egress packets in TProxy mode so they bypass
re-interception and do not loop back into the transparent proxy path.
'';
example = 2;
};
routeTable = mkOption {
type = types.int;
default = 100;
description = ''
Policy-routing table number used for TProxy interception flow.
The module installs a local default route in this table and binds it
to singBox.fwmark.
'';
example = 100;
};
proxyByDefault = mkOption {
type = types.bool;
default = true;
@@ -252,7 +241,7 @@ in
This resolver is also used as sing-box route.default_domain_resolver.
The module keeps detour policy automatic: in mixed/TProxy mode and
app-routing TUN mode, "local" stays on the direct path (without an
per-app-routing TUN mode, "local" stays on the direct path (without an
explicit detour); in global TUN mode, it is forced through the proxy to avoid
auto_redirect conflicts.
'';
@@ -285,7 +274,7 @@ in
};
tun = {
enable = mkEnableOption "TUN mode service (opt-in, mutually exclusive with proxy-suite-tproxy)";
enable = mkEnableOption "global sing-box TUN mode service";
autostart = mkOption {
type = types.bool;
@@ -298,30 +287,67 @@ in
example = true;
};
interface = mkOption {
type = types.str;
default = "singtun0";
description = "Name of the TUN interface created by proxy-suite-tun.";
example = "singtun0";
};
perApp = {
enable = mkEnableOption "per-app-scoped sing-box TUN backend for perAppRouting profiles";
address = mkOption {
type = types.str;
default = "172.19.0.1/30";
description = "Address assigned to the TUN interface in CIDR notation.";
example = "172.19.0.1/30";
};
fwmark = mkOption {
type = types.int;
default = 16;
description = ''
Packet mark used to steer wrapped app traffic into the per-app-scoped
TUN policy-routing table.
'';
example = 16;
};
mtu = mkOption {
type = types.int;
default = 1400;
description = "MTU for the TUN interface created by proxy-suite-tun.";
example = 1400;
routeTable = mkOption {
type = types.int;
default = 101;
description = ''
Policy-routing table used by the per-app-scoped TUN backend.
'';
example = 101;
};
localSubnets = mkOption {
type = types.listOf types.str;
default = [ "192.168.0.0/16" ];
description = ''
Destination subnets that should bypass the per-app-scoped TUN mark,
so wrapped apps can still reach local LAN resources directly.
'';
example = [
"192.168.0.0/16"
"10.0.0.0/8"
];
};
}
// mkTunCommonFields {
interfaceDefault = "psperapptun0";
interfaceDescription = ''
Name of the dedicated per-app-routing TUN interface used by
proxy-suite-per-app-tun.
'';
addressDefault = "172.20.0.1/30";
addressDescription = ''
Address assigned to the dedicated per-app-routing TUN interface in CIDR
notation.
'';
mtuDefault = 1400;
mtuDescription = "MTU for the dedicated per-app-routing TUN interface.";
};
}
// mkTunCommonFields {
interfaceDefault = "singtun0";
interfaceDescription = "Name of the TUN interface created by proxy-suite-tun.";
addressDefault = "172.19.0.1/30";
addressDescription = "Address assigned to the global TUN interface in CIDR notation.";
mtuDefault = 1400;
mtuDescription = "MTU for the global TUN interface created by proxy-suite-tun.";
};
tproxy = {
enable = mkEnableOption "TProxy mode service (opt-in, transparent proxy via nftables)";
enable = mkEnableOption "global sing-box TProxy mode service";
autostart = mkOption {
type = types.bool;
@@ -334,11 +360,57 @@ in
example = true;
};
port = mkOption {
type = types.port;
default = 1081;
description = ''
Local listen port for sing-box's TProxy inbound.
nftables redirection created by proxy-suite-tproxy sends intercepted
TCP/UDP traffic to this port.
'';
example = 1081;
};
fwmark = mkOption {
type = types.int;
default = 1;
description = ''
Mark applied to intercepted packets in global TProxy mode.
A matching `ip rule` routes this mark to
singBox.tproxy.routeTable, which points traffic to
loopback for local proxy processing.
'';
example = 1;
};
proxyMark = mkOption {
type = types.int;
default = 2;
description = ''
Mark applied to sing-box egress packets in global TProxy mode so
they bypass re-interception and do not loop back into the
transparent proxy path.
'';
example = 2;
};
routeTable = mkOption {
type = types.int;
default = 100;
description = ''
Policy-routing table number used for global TProxy interception flow.
The module installs a local default route in this table and binds it
to singBox.tproxy.fwmark.
'';
example = 100;
};
localSubnets = mkOption {
type = types.listOf types.str;
default = [ "192.168.0.0/16" ];
description = ''
Subnets whose traffic bypasses TProxy interception, except DNS (port 53).
Subnets whose traffic bypasses global TProxy interception, except
DNS (port 53).
Typically this should include your LAN subnet(s). VM bridge networks
should usually go here too, or use zapret.cidrExemption for
@@ -349,6 +421,42 @@ in
"10.0.0.0/8"
];
};
perApp = {
enable = mkEnableOption "per-app-scoped sing-box TProxy backend for perAppRouting profiles";
fwmark = mkOption {
type = types.int;
default = 17;
description = ''
Packet mark used to steer wrapped app traffic into the per-app-scoped
TProxy policy-routing table.
'';
example = 17;
};
routeTable = mkOption {
type = types.int;
default = 102;
description = ''
Policy-routing table used by the per-app-scoped TProxy backend.
'';
example = 102;
};
localSubnets = mkOption {
type = types.listOf types.str;
default = [ "192.168.0.0/16" ];
description = ''
Subnets whose traffic bypasses per-app-scoped TProxy interception,
except DNS (port 53).
'';
example = [
"192.168.0.0/16"
"10.0.0.0/8"
];
};
};
};
routing = {
+7 -7
View File
@@ -284,13 +284,13 @@ let
};
};
appRoutingProfileType = types.submodule {
perAppRoutingProfileType = types.submodule {
options = {
name = mkOption {
type = types.strMatching "^[a-z0-9][a-z0-9-]*$";
description = ''
Profile name used by `proxy-ctl wrap <name> -- <command>`.
Must be unique within appRouting.profiles.
Must be unique within perAppRouting.profiles.
'';
example = "steam-browser";
};
@@ -310,14 +310,14 @@ let
- "direct": run the command unchanged.
- "proxychains": run the command through proxychains-ng using the
local proxy-suite mixed SOCKS endpoint.
- "tun": launch the command in the dedicated app-routing TUN slice so
- "tun": launch the command in the dedicated per-app-routing TUN slice so
only that app's traffic is policy-routed into the app TUN backend.
- "tproxy": launch the command in the dedicated app-routing TProxy
- "tproxy": launch the command in the dedicated per-app-routing TProxy
slice so only that app's traffic is transparently intercepted by
the local sing-box TProxy inbound.
- "zapret": launch the command in the dedicated app-routing zapret
- "zapret": launch the command in the dedicated per-app-routing zapret
slice so only that app's traffic is handled by the separate
app-scoped zapret instance.
per-app-scoped zapret instance.
Additional route backends may be added in the future.
'';
@@ -336,6 +336,6 @@ in
dnsUpstreamType
zapretPresetType
zapretHostlistRuleType
appRoutingProfileType
perAppRoutingProfileType
;
}
+25
View File
@@ -9,6 +9,31 @@ in
options.services.proxy-suite.zapret = {
enable = mkEnableOption "zapret DPI bypass";
perApp = {
enable = mkEnableOption "per-app-scoped zapret backend for perAppRouting profiles";
filterMark = mkOption {
type = types.int;
default = 268435456;
description = ''
Packet mark bit used to mark wrapped app traffic for the
dedicated per-app-scoped zapret instance.
'';
example = 268435456;
};
qnum = mkOption {
type = types.int;
default = 201;
description = ''
NFQUEUE number used by the dedicated per-app-scoped zapret instance.
This backend runs as a second zapret daemon and should use a
queue distinct from the global zapret instance.
'';
example = 201;
};
};
syncDirectRouting = mkOption {
type = types.bool;
default = true;