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
@@ -11,7 +11,7 @@ let
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
awgTypes = import ./types/amnezia-wg.nix { inherit lib; };
|
||||
t = import ./types.nix { inherit lib; };
|
||||
awgPackages = import ../../../pkgs/amneziawg.nix { inherit pkgs; };
|
||||
in
|
||||
{
|
||||
@@ -37,7 +37,7 @@ in
|
||||
};
|
||||
|
||||
profiles = mkOption {
|
||||
type = types.attrsOf awgTypes.profileType;
|
||||
type = types.attrsOf t.profileType;
|
||||
default = { };
|
||||
description = "Named AmneziaWG client profiles. Only one global profile can be active.";
|
||||
};
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
# All option declarations for services.proxy-suite, split by feature area.
|
||||
{ ... }:
|
||||
{ lib, ... }:
|
||||
{
|
||||
imports = [
|
||||
./other.nix
|
||||
./ssh-proxy.nix
|
||||
./proxy-inbounds.nix
|
||||
./amnezia-wg.nix
|
||||
./legacy-sing-box.nix
|
||||
./sing-box.nix
|
||||
./sing-box-outbounds.nix
|
||||
./sing-box-dns.nix
|
||||
./sing-box-tun.nix
|
||||
./sing-box-tproxy.nix
|
||||
./sing-box-routing.nix
|
||||
./removed.nix
|
||||
./proxy.nix
|
||||
./proxy-outbounds.nix
|
||||
./proxy-dns.nix
|
||||
./proxy-routing.nix
|
||||
./proxy-tun.nix
|
||||
./proxy-tproxy.nix
|
||||
./inbounds.nix
|
||||
./per-app-routing.nix
|
||||
./zapret.nix
|
||||
./zapret2.nix
|
||||
./amnezia-wg.nix
|
||||
./ssh-proxy.nix
|
||||
./tg-ws-proxy.nix
|
||||
./geodata.nix
|
||||
./tray.nix
|
||||
./user-control.nix
|
||||
];
|
||||
|
||||
options.services.proxy-suite.enable = lib.mkEnableOption "proxy-suite";
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{ lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) literalExpression mkOption types;
|
||||
in
|
||||
{
|
||||
# Shared by the client backends and the inbound service, so not under proxy.
|
||||
options.services.proxy-suite.geodata = {
|
||||
xray.assets = mkOption {
|
||||
type = types.nullOr types.package;
|
||||
default = pkgs.v2ray-rules-dat;
|
||||
defaultText = literalExpression "pkgs.v2ray-rules-dat";
|
||||
description = ''
|
||||
Package with share/v2ray/{geoip,geosite}.dat for every XRay process. Null uses XRay's own
|
||||
country-only data, where a tag like "geoip:telegram" stops XRay from starting.
|
||||
'';
|
||||
};
|
||||
|
||||
singBox = {
|
||||
geoip = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.sing-geoip;
|
||||
defaultText = literalExpression "pkgs.sing-geoip";
|
||||
description = "Package with share/sing-box/rule-set/geoip-NAME.srs (country codes by default).";
|
||||
};
|
||||
|
||||
geosite = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.sing-geosite;
|
||||
defaultText = literalExpression "pkgs.sing-geosite";
|
||||
description = "Package with share/sing-box/rule-set/geosite-NAME.srs.";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
{ lib, proxySuiteUpstream, ... }:
|
||||
|
||||
let
|
||||
inherit (lib)
|
||||
literalExpression
|
||||
literalMD
|
||||
mkEnableOption
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
t = import ./types.nix { inherit lib; };
|
||||
bool =
|
||||
default: description:
|
||||
mkOption {
|
||||
type = types.bool;
|
||||
inherit default description;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.inbounds = {
|
||||
enable = mkEnableOption "server inbounds that accept proxy connections from outside";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = proxySuiteUpstream.xray;
|
||||
defaultText = literalMD "proxy-suite's `xray` (`pkgs/xray.nix`)";
|
||||
example = literalExpression "pkgs.xray";
|
||||
description = "XRay package serving the inbounds, whatever the client-side backend.";
|
||||
};
|
||||
|
||||
serverAddress = mkOption {
|
||||
type = types.nullOr (types.strMatching "[^[:space:]]+");
|
||||
default = null;
|
||||
description = "Public address clients connect to, used in share links. Null detects the uplink IPv4.";
|
||||
example = "vpn.example.com";
|
||||
};
|
||||
|
||||
openFirewall = bool true "Open every non-loopback listener port.";
|
||||
shareLinks = bool true "Write client share links for `proxy-ctl inbounds link` (root and userControl.group only).";
|
||||
|
||||
subscriptions = {
|
||||
enable = mkEnableOption "" // {
|
||||
description = ''
|
||||
Write one subscription file per user (their links from every listener, base64) to
|
||||
/run/proxy-suite-inbounds/subscriptions/<token>. Serve that directory with a web server;
|
||||
see the README.
|
||||
'';
|
||||
};
|
||||
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = "nginx";
|
||||
description = "Group allowed to read the subscription files: the web server serving them.";
|
||||
example = "caddy";
|
||||
};
|
||||
|
||||
baseUrl = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = "URL the subscription directory is served at, for `proxy-ctl inbounds sub`.";
|
||||
example = "https://vpn.example.com/sub";
|
||||
};
|
||||
};
|
||||
|
||||
# Mirrors proxy.routing, for traffic arriving from outside instead of from this host.
|
||||
routing = {
|
||||
via = mkOption {
|
||||
type = types.str;
|
||||
default = "proxy";
|
||||
description = ''
|
||||
Default egress of inbound traffic; listeners can override it:
|
||||
- "proxy": through the local proxy and its current selection (needs proxy.enable).
|
||||
- a proxy.outbounds tag: pinned to that server (url, urlFile or xrayJson outbounds only).
|
||||
- "direct": out from this machine.
|
||||
- "block": dropped.
|
||||
'';
|
||||
example = "direct";
|
||||
};
|
||||
|
||||
proxy = t.routingFields;
|
||||
|
||||
blockRu = bool true ''Block Russian destinations (geosite "category-ru", geoip "ru").'';
|
||||
blockPrivate = bool true "Block private and loopback destinations, so clients cannot reach this host's LAN or local services.";
|
||||
|
||||
zapretDirect = bool true "Send zapret's hostlist destinations direct, so this host's zapret unblocks them (default via only).";
|
||||
};
|
||||
|
||||
listeners = mkOption {
|
||||
type = types.attrsOf t.inboundType;
|
||||
default = { };
|
||||
description = "Listeners by tag.";
|
||||
example = literalExpression ''
|
||||
{
|
||||
vless-reality = {
|
||||
type = "vless";
|
||||
port = 443;
|
||||
users = [ { uuidFile = "/run/secrets/proxy-inbound-uuid"; } ];
|
||||
flow = "xtls-rprx-vision";
|
||||
reality = {
|
||||
enable = true;
|
||||
serverNames = [ "www.microsoft.com" ];
|
||||
privateKeyFile = "/run/secrets/proxy-inbound-reality-key";
|
||||
publicKey = "jNXH...";
|
||||
shortIds = [ "0123abcd" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
{ lib, config, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkIf mkOption types;
|
||||
cfg = config.services.proxy-suite;
|
||||
legacy = cfg.singBox or { };
|
||||
legacyUsed = legacy != { };
|
||||
|
||||
has = name: builtins.hasAttr name legacy;
|
||||
hasNested = path: lib.hasAttrByPath path legacy;
|
||||
getNested = path: lib.getAttrFromPath path legacy;
|
||||
setIf = condition: value: lib.optionalAttrs condition value;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.singBox = mkOption {
|
||||
type = types.submodule {
|
||||
freeformType = types.anything;
|
||||
};
|
||||
default = { };
|
||||
visible = false;
|
||||
description = ''
|
||||
Deprecated compatibility tree for the old services.proxy-suite.singBox
|
||||
options. Use services.proxy-suite.proxy instead.
|
||||
'';
|
||||
};
|
||||
|
||||
config = mkIf legacyUsed {
|
||||
warnings = [
|
||||
''
|
||||
services.proxy-suite.singBox is deprecated. Move shared options to
|
||||
services.proxy-suite.proxy and SingBox-specific options to
|
||||
services.proxy-suite.proxy.singBox.
|
||||
''
|
||||
];
|
||||
|
||||
services.proxy-suite.proxy = lib.mkMerge [
|
||||
(setIf (!has "enable") {
|
||||
enable = lib.mkDefault true;
|
||||
singBox.enable = lib.mkDefault true;
|
||||
})
|
||||
(setIf (has "enable") {
|
||||
enable = lib.mkDefault legacy.enable;
|
||||
singBox.enable = lib.mkDefault legacy.enable;
|
||||
})
|
||||
(setIf (has "listenAddress") { listenAddress = lib.mkDefault legacy.listenAddress; })
|
||||
(setIf (has "port") { port = lib.mkDefault legacy.port; })
|
||||
(setIf (has "auth") { auth = lib.mkDefault legacy.auth; })
|
||||
(setIf (has "proxyByDefault") { proxyByDefault = lib.mkDefault legacy.proxyByDefault; })
|
||||
(setIf (has "outbounds") { outbounds = lib.mkDefault legacy.outbounds; })
|
||||
(setIf (has "subscriptions") { subscriptions = lib.mkDefault legacy.subscriptions; })
|
||||
(setIf (has "subscriptionUpdateInterval") {
|
||||
subscriptionUpdateInterval = lib.mkDefault legacy.subscriptionUpdateInterval;
|
||||
})
|
||||
(setIf (has "selection") { selection = lib.mkDefault legacy.selection; })
|
||||
(setIf (has "dns") { dns = lib.mkDefault legacy.dns; })
|
||||
(setIf (has "routing") { routing = lib.mkDefault legacy.routing; })
|
||||
(setIf (has "tun") { tun = lib.mkDefault legacy.tun; })
|
||||
(setIf (has "tproxy") { tproxy = lib.mkDefault legacy.tproxy; })
|
||||
(setIf (hasNested [ "urlTest" "url" ]) {
|
||||
urlTest.url = lib.mkDefault (getNested [ "urlTest" "url" ]);
|
||||
})
|
||||
(setIf (hasNested [ "urlTest" "interval" ]) {
|
||||
urlTest.interval = lib.mkDefault (getNested [ "urlTest" "interval" ]);
|
||||
})
|
||||
(setIf (hasNested [ "urlTest" "tolerance" ]) {
|
||||
singBox.urlTest.tolerance = lib.mkDefault (getNested [ "urlTest" "tolerance" ]);
|
||||
})
|
||||
(setIf (has "package") { singBox.package = lib.mkDefault legacy.package; })
|
||||
(setIf (has "clashApiPort") { singBox.clashApiPort = lib.mkDefault legacy.clashApiPort; })
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
# Miscellaneous top-level proxy-suite options.
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption mkEnableOption types;
|
||||
|
||||
tgWsProxyOptions = import ./other/tg-ws-proxy.nix { inherit lib; };
|
||||
|
||||
userControlOptions = {
|
||||
userControl = {
|
||||
group = mkOption {
|
||||
type = types.strMatching "^[a-z_][a-z0-9_-]*$";
|
||||
default = "proxy-suite";
|
||||
description = ''
|
||||
Local group allowed to use passwordless polkit-backed `proxy-ctl`
|
||||
commands when userControl.global.enable or userControl.perApp.enable
|
||||
is turned on.
|
||||
'';
|
||||
example = "proxy-suite";
|
||||
};
|
||||
|
||||
global.enable = (mkEnableOption "passwordless proxy-ctl control over global proxy-suite units") // {
|
||||
default = true;
|
||||
description = ''
|
||||
Whether members of userControl.group may manage global
|
||||
proxy-suite units without password prompts via commands like
|
||||
`proxy-ctl tun on|off`, `proxy-ctl tproxy on|off`,
|
||||
`proxy-ctl restart`, or `proxy-ctl subscription update`.
|
||||
'';
|
||||
};
|
||||
|
||||
perApp.enable = (mkEnableOption "passwordless proxy-ctl control over per-app routing helpers") // {
|
||||
default = true;
|
||||
description = ''
|
||||
Whether members of userControl.group may start and stop the
|
||||
app-scoped backend units used by `proxy-ctl wrap ...` for
|
||||
route = "tun", route = "tproxy", or route = "zapret" profiles
|
||||
without password prompts.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
trayOptions = {
|
||||
tray = {
|
||||
enable = mkEnableOption "system tray indicator for proxy-suite";
|
||||
|
||||
pollInterval = mkOption {
|
||||
type = types.int;
|
||||
default = 5;
|
||||
description = ''
|
||||
Tray status refresh interval in seconds.
|
||||
Lower values make UI state changes appear faster, while higher values
|
||||
reduce background polling overhead.
|
||||
'';
|
||||
example = 5;
|
||||
};
|
||||
|
||||
autostart = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to install an XDG autostart entry for the tray application
|
||||
for graphical users.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite = {
|
||||
enable = lib.mkEnableOption "proxy suite (proxy backend + AmneziaWG + zapret + tg-ws-proxy)";
|
||||
}
|
||||
// userControlOptions
|
||||
// trayOptions
|
||||
// tgWsProxyOptions;
|
||||
}
|
||||
@@ -1,212 +0,0 @@
|
||||
# Telegram MTProto WebSocket proxy options.
|
||||
{ lib }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption mkEnableOption types;
|
||||
in
|
||||
{
|
||||
tgWsProxy = {
|
||||
enable = mkEnableOption "Telegram MTProto WebSocket proxy";
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 1443;
|
||||
description = ''
|
||||
TCP listen port for tg-ws-proxy.
|
||||
Telegram clients connect to this endpoint when using the local MTProto
|
||||
WebSocket proxy.
|
||||
'';
|
||||
example = 1076;
|
||||
};
|
||||
|
||||
host = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = ''
|
||||
Bind address for tg-ws-proxy.
|
||||
Keep `127.0.0.1` for local-only usage; bind to `0.0.0.0` only when you
|
||||
intentionally expose the proxy to other hosts.
|
||||
'';
|
||||
example = "127.0.0.1";
|
||||
};
|
||||
|
||||
secret = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
MTProto proxy secret (hex string). Legacy inline form; this value ends up
|
||||
in the Nix store. Prefer secretFile for real deployments.
|
||||
|
||||
Set exactly one of secret or secretFile when tgWsProxy.enable = true.
|
||||
Generate one with: openssl rand -hex 16
|
||||
'';
|
||||
example = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
};
|
||||
|
||||
secretFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to a file containing the MTProto proxy secret.
|
||||
Intended for use with secret managers so the secret stays out of the Nix store.
|
||||
|
||||
Set exactly one of secretFile or secret when tgWsProxy.enable = true.
|
||||
'';
|
||||
example = "/run/secrets/tg-ws-proxy-secret";
|
||||
};
|
||||
|
||||
dcIps = mkOption {
|
||||
type = types.attrsOf types.str;
|
||||
default = { };
|
||||
description = ''
|
||||
Mapping of Telegram DC IDs to relay IPs.
|
||||
Keys are DC IDs as strings and values are IPv4/IPv6 addresses used by
|
||||
tg-ws-proxy for MTProto relay selection.
|
||||
'';
|
||||
example = {
|
||||
"2" = "149.154.167.220";
|
||||
"4" = "149.154.167.220";
|
||||
"203" = "149.154.167.220";
|
||||
};
|
||||
};
|
||||
|
||||
verbose = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to enable debug logging in tg-ws-proxy.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
logFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Optional path where tg-ws-proxy writes rotating logs.
|
||||
When unset, tg-ws-proxy logs to stderr only.
|
||||
'';
|
||||
example = "/var/log/tg-ws-proxy.log";
|
||||
};
|
||||
|
||||
logMaxMb = mkOption {
|
||||
type = types.numbers.positive;
|
||||
default = 5.0;
|
||||
description = ''
|
||||
Maximum tg-ws-proxy log file size in MiB before rotation.
|
||||
Only used when tgWsProxy.logFile is set.
|
||||
'';
|
||||
example = 10.0;
|
||||
};
|
||||
|
||||
logBackups = mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 1;
|
||||
description = ''
|
||||
Number of rotated tg-ws-proxy log files to keep.
|
||||
Only used when tgWsProxy.logFile is set.
|
||||
'';
|
||||
example = 3;
|
||||
};
|
||||
|
||||
bufKb = mkOption {
|
||||
type = types.ints.between 4 2147483647;
|
||||
default = 256;
|
||||
description = ''
|
||||
Socket send and receive buffer size for tg-ws-proxy, in KiB.
|
||||
'';
|
||||
example = 512;
|
||||
};
|
||||
|
||||
poolSize = mkOption {
|
||||
type = types.ints.unsigned;
|
||||
default = 4;
|
||||
description = ''
|
||||
WebSocket connection pool size per Telegram DC.
|
||||
Set to 0 to disable connection pooling.
|
||||
'';
|
||||
example = 8;
|
||||
};
|
||||
|
||||
cfProxyDomains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
User-defined Cloudflare-proxied domains used by tg-ws-proxy for
|
||||
WebSocket fallback. Each entry is passed as a separate
|
||||
--cfproxy-domain argument.
|
||||
'';
|
||||
example = [
|
||||
"cdn.example.com"
|
||||
"edge.example.net"
|
||||
];
|
||||
};
|
||||
|
||||
cfProxyWorkerDomains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Cloudflare Worker domains used by tg-ws-proxy for WebSocket fallback.
|
||||
These are tried before other fallback methods.
|
||||
'';
|
||||
example = [ "worker.example.com" ];
|
||||
};
|
||||
|
||||
cfProxyFallback = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to allow tg-ws-proxy to use Cloudflare proxy fallback when
|
||||
direct WebSocket routing is unavailable.
|
||||
'';
|
||||
example = false;
|
||||
};
|
||||
|
||||
fakeTlsDomain = mkOption {
|
||||
type = types.nullOr (types.strMatching ".+");
|
||||
default = null;
|
||||
description = ''
|
||||
Optional SNI domain used to enable tg-ws-proxy Fake TLS masking.
|
||||
When set, tg-ws-proxy emits an ee-secret connection link.
|
||||
'';
|
||||
example = "www.example.com";
|
||||
};
|
||||
|
||||
proxyProtocol = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether tg-ws-proxy should accept a PROXY protocol v1 header from a
|
||||
fronting reverse proxy such as nginx or HAProxy.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
bypassTransparentProxy = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to keep tg-ws-proxy's own relay connections out of proxy-suite
|
||||
transparent routing backends.
|
||||
|
||||
When enabled and global TUN or TProxy mode is configured, the
|
||||
tg-ws-proxy systemd service receives a packet mark and an earlier
|
||||
policy-routing rule back to the main table. This prevents global TUN
|
||||
from routing the local Telegram MTProto relay through the proxy backend again,
|
||||
which can otherwise break tg-ws-proxy after enabling TUN mode.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
routingMark = mkOption {
|
||||
type = types.int;
|
||||
default = 4;
|
||||
description = ''
|
||||
Packet mark used by tgWsProxy.bypassTransparentProxy to bypass
|
||||
proxy-suite transparent routing. Override this only if it collides
|
||||
with another local policy-routing mark on your host.
|
||||
'';
|
||||
example = 4;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,101 +1,99 @@
|
||||
# Per-app routing options (backends and profiles).
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption mkEnableOption types;
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
t = import ./types.nix { inherit lib; };
|
||||
int =
|
||||
default: description:
|
||||
mkOption {
|
||||
type = types.int;
|
||||
inherit default description;
|
||||
};
|
||||
localSubnets =
|
||||
description:
|
||||
mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ "192.168.0.0/16" ];
|
||||
inherit description;
|
||||
example = [
|
||||
"192.168.0.0/16"
|
||||
"10.0.0.0/8"
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.perAppRouting = {
|
||||
enable = mkEnableOption "per-app routing helpers via proxy-ctl wrap";
|
||||
enable = mkEnableOption "per-app routing (`proxy-ctl apps run`)";
|
||||
|
||||
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 proxy.tun.perApp.enable = true
|
||||
- `tproxy`: route = "tproxy" when proxy.tproxy.perApp.enable = true
|
||||
- `zapret`: route = "zapret" when zapret.perApp.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.
|
||||
Add a profile named after each enabled backend (proxychains, tun, tproxy, zapret) unless
|
||||
one with that name already exists.
|
||||
'';
|
||||
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 proxy.enable = true and the
|
||||
local proxy-suite proxy listener provided by the active backend. The
|
||||
"tun" route depends on proxy.tun.perApp.enable = true. The "tproxy"
|
||||
route depends on proxy.tproxy.perApp.enable = true. The "zapret"
|
||||
route depends on zapret.perApp.enable = true.
|
||||
|
||||
When createDefaultProfiles = true, curated defaults are added on top
|
||||
of this list unless a user-defined profile already uses the same
|
||||
name.
|
||||
'';
|
||||
description = "Profiles for `proxy-ctl apps run <name> -- <command>`.";
|
||||
example = [
|
||||
{
|
||||
name = "steam-browser";
|
||||
route = "proxychains";
|
||||
}
|
||||
{
|
||||
name = "native-direct";
|
||||
route = "direct";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
proxychains = {
|
||||
enable = mkEnableOption "proxychains-backed perAppRouting profiles";
|
||||
enable = mkEnableOption "the proxychains backend (TCP apps, through LD_PRELOAD)";
|
||||
|
||||
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;
|
||||
description = "Silence proxychains (quiet_mode).";
|
||||
};
|
||||
|
||||
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;
|
||||
description = "Resolve DNS through the proxy (proxy_dns).";
|
||||
};
|
||||
};
|
||||
|
||||
tun = {
|
||||
enable = mkEnableOption "the per-app TUN backend";
|
||||
fwmark = int 16 "Mark that steers wrapped apps into routeTable.";
|
||||
routeTable = int 101 "Policy-routing table of the per-app TUN.";
|
||||
localSubnets = localSubnets "Subnets wrapped apps reach directly.";
|
||||
|
||||
interface = mkOption {
|
||||
type = types.str;
|
||||
default = "psperapptun0";
|
||||
description = "Per-app TUN interface name.";
|
||||
};
|
||||
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "172.20.0.1/30";
|
||||
description = "Per-app TUN interface address (CIDR).";
|
||||
};
|
||||
|
||||
mtu = int 1400 "Per-app TUN interface MTU.";
|
||||
};
|
||||
|
||||
tproxy = {
|
||||
enable = mkEnableOption "the per-app TProxy backend";
|
||||
fwmark = int 17 "Mark that steers wrapped apps into routeTable.";
|
||||
routeTable = int 102 "Policy-routing table of the per-app TProxy.";
|
||||
localSubnets = localSubnets "Subnets that bypass interception (DNS excepted).";
|
||||
};
|
||||
|
||||
zapret = {
|
||||
enable = mkEnableOption "the per-app zapret backend: a second zapret instance for wrapped apps only";
|
||||
filterMark = int 268435456 "Mark bit that selects wrapped app traffic.";
|
||||
qnum = int 201 "NFQUEUE number. Must differ from the global instance's.";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption;
|
||||
t = import ./types.nix { inherit lib; };
|
||||
cloudflare = {
|
||||
type = "udp";
|
||||
address = "1.1.1.1";
|
||||
port = 53;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxy.dns = {
|
||||
local = mkOption {
|
||||
type = t.dnsUpstreamType;
|
||||
default = cloudflare;
|
||||
description = "Resolver for direct traffic and the default domain resolver. Goes through the proxy in global TUN mode.";
|
||||
example = {
|
||||
type = "tcp";
|
||||
address = "9.9.9.9";
|
||||
};
|
||||
};
|
||||
|
||||
remote = mkOption {
|
||||
type = t.dnsUpstreamType;
|
||||
default = cloudflare;
|
||||
description = "Resolver used through the proxy; the DNS default when proxy.routing.default is proxy.";
|
||||
example = {
|
||||
type = "tls";
|
||||
address = "1.1.1.1";
|
||||
port = 853;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
# Server-side proxy inbound options.
|
||||
{ lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
inherit (lib)
|
||||
literalExpression
|
||||
mkEnableOption
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
inboundTypes = import ./types/proxy-inbounds.nix { inherit lib; };
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxyInbounds = {
|
||||
enable = mkEnableOption "server-side proxy inbounds (accept connections from outside)";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.xray;
|
||||
defaultText = literalExpression "pkgs.xray";
|
||||
example = literalExpression "pkgs.xray";
|
||||
description = ''
|
||||
XRay package serving the inbounds.
|
||||
|
||||
This is independent of proxy.xray.package: the inbound service always
|
||||
runs XRay, whichever backend the client side uses, and works with
|
||||
proxy.enable = false.
|
||||
'';
|
||||
};
|
||||
|
||||
serverAddress = mkOption {
|
||||
type = types.nullOr (types.strMatching "[^[:space:]]+");
|
||||
default = null;
|
||||
description = ''
|
||||
Public hostname or address clients connect to. Used for generated share
|
||||
links only; it does not affect what the listeners bind.
|
||||
|
||||
Leave null to detect the machine's uplink IPv4 address at service start
|
||||
time. Set it explicitly when the server is behind NAT or reached by a
|
||||
domain name.
|
||||
'';
|
||||
example = "vpn.example.com";
|
||||
};
|
||||
|
||||
openFirewall = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Add every listener port to networking.firewall. Disable to manage the
|
||||
firewall yourself.
|
||||
'';
|
||||
example = false;
|
||||
};
|
||||
|
||||
shareLinks = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Write client share links to /run/proxy-suite-inbounds/links.json at
|
||||
service start, for `proxy-ctl inbounds link` and
|
||||
`proxy-ctl inbounds qr`.
|
||||
|
||||
The file is readable by root and the userControl group only, because
|
||||
the links carry the listener credentials.
|
||||
'';
|
||||
example = false;
|
||||
};
|
||||
|
||||
via = mkOption {
|
||||
type = types.str;
|
||||
default = "proxy";
|
||||
description = ''
|
||||
Default egress for traffic arriving on the inbounds. Individual
|
||||
listeners can override it with their own via option, which is how two
|
||||
listeners can leave through two different servers.
|
||||
|
||||
- "proxy": chain out through the local proxy stack, so the machine
|
||||
relays rather than exits. Requires proxy.enable. The inbound service
|
||||
hands traffic to the SOCKS listener on proxy.listenAddress, so it
|
||||
follows whatever the client side is currently doing: the selected
|
||||
outbound, subscriptions, urltest, and `proxy-ctl select` all apply,
|
||||
with no second copy of that machinery.
|
||||
- A proxy.outbounds tag: pin this traffic to that specific server,
|
||||
independently of what the client side has selected. The outbound is
|
||||
built into the inbound service's own config, so it must be one XRay
|
||||
can represent (a url/urlFile entry, or xrayJson). Subscription
|
||||
proxies cannot be named here, because their tags only exist at
|
||||
runtime; use "proxy" to reach those.
|
||||
- "direct": leave from this machine, making it a plain exit node. Needs
|
||||
no client-side proxy configuration at all.
|
||||
- "block": drop the traffic.
|
||||
'';
|
||||
example = "direct";
|
||||
};
|
||||
|
||||
zapretDirect = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Route zapret's hostlist domains and IPs to the direct outbound instead
|
||||
of through the proxy, so this host's own zapret unblocks them for
|
||||
inbound clients.
|
||||
|
||||
Has no effect unless zapret.enable and zapret.syncDirectRouting are on:
|
||||
the rules are built from the same hostlists that already feed
|
||||
routing.direct on the client side, so they are empty when zapret is not
|
||||
running here.
|
||||
|
||||
On by default because a zapret host is by definition inside the filtered
|
||||
network, and paying for a proxy hop to reach something zapret already
|
||||
unblocks locally is pure latency. Only applies to listeners using the
|
||||
default via; an explicit per-listener via still wins.
|
||||
'';
|
||||
example = false;
|
||||
};
|
||||
|
||||
blockRu = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Send traffic destined for Russian domains and IP ranges
|
||||
("category-ru" geosite, "ru" geoip) to the block outbound.
|
||||
|
||||
On by default: a relay whose whole point is leaving the RKN-filtered
|
||||
network has no reason to carry traffic back into it, and it keeps the
|
||||
server out of the way of domestic services that geo-check.
|
||||
'';
|
||||
example = false;
|
||||
};
|
||||
|
||||
blockPrivate = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Send traffic destined for private and loopback addresses to the block
|
||||
outbound.
|
||||
|
||||
On by default: without it, anyone holding an inbound credential can
|
||||
reach the server's LAN, its localhost services, and the local proxy
|
||||
ports of proxy-suite itself.
|
||||
'';
|
||||
example = false;
|
||||
};
|
||||
|
||||
listeners = mkOption {
|
||||
type = types.attrsOf inboundTypes.inboundType;
|
||||
default = { };
|
||||
description = ''
|
||||
Named inbound listeners. The attribute name becomes the inbound tag
|
||||
used in routing rules and in `proxy-ctl inbounds`.
|
||||
'';
|
||||
example = literalExpression ''
|
||||
{
|
||||
vless-reality = {
|
||||
type = "vless";
|
||||
port = 443;
|
||||
users = [ { uuidFile = "/run/secrets/proxy-inbound-uuid"; } ];
|
||||
flow = "xtls-rprx-vision";
|
||||
reality = {
|
||||
enable = true;
|
||||
dest = "www.microsoft.com:443";
|
||||
serverNames = [ "www.microsoft.com" ];
|
||||
privateKeyFile = "/run/secrets/proxy-inbound-reality-key";
|
||||
publicKey = "jNXH...";
|
||||
shortIds = [ "0123abcd" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
t = import ./types.nix { inherit lib; };
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxy = {
|
||||
outbounds = mkOption {
|
||||
type = types.listOf t.outboundType;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Static proxy outbounds. The proxy needs at least one outbound or subscription to start;
|
||||
`proxy-ctl proxy outbounds add` supplies one at runtime if none is declared here.
|
||||
'';
|
||||
example = [
|
||||
{
|
||||
tag = "de-vps";
|
||||
urlFile = "/run/secrets/proxy-de-url";
|
||||
}
|
||||
{
|
||||
tag = "nl-vps";
|
||||
url = "hy2://password@example.com:443?sni=example.com";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
subscriptions = mkOption {
|
||||
type = types.listOf t.subscriptionType;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Subscription URLs serving a base64 or plain list of proxy URIs. Fetched on first start,
|
||||
cached under /var/lib/proxy-suite/subscriptions, refreshed by a timer. Ones added with
|
||||
`proxy-ctl proxy subs add` live in /var/lib/proxy-suite/subscriptions.d and refresh alongside.
|
||||
'';
|
||||
example = [
|
||||
{
|
||||
tag = "private";
|
||||
urlFile = "/run/secrets/private-sub-url";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
subscriptionUpdateInterval = mkOption {
|
||||
type = types.str;
|
||||
default = "1d";
|
||||
description = "How often subscriptions are refreshed (systemd time span).";
|
||||
example = "6h";
|
||||
};
|
||||
|
||||
selection = mkOption {
|
||||
type = types.enum [
|
||||
"first"
|
||||
"selector"
|
||||
"urltest"
|
||||
];
|
||||
default = "first";
|
||||
description = ''
|
||||
How to pick among outbounds:
|
||||
- "first": one at a time - the pinned outbound, or the first available.
|
||||
- "selector": all of them, pick by hand.
|
||||
- "urltest": all of them, ranked by latency unless one is pinned.
|
||||
|
||||
`proxy-ctl proxy select` pins an outbound in every mode, and the pin outlives a restart.
|
||||
"selector" and "urltest" switch without restarting the backend (sing-box only); "first"
|
||||
and XRay restart it.
|
||||
'';
|
||||
example = "urltest";
|
||||
};
|
||||
|
||||
urlTest = {
|
||||
url = mkOption {
|
||||
type = types.str;
|
||||
default = "https://www.gstatic.com/generate_204";
|
||||
description = "URL fetched through each outbound to rank them. Pick one blocked in your region.";
|
||||
example = "https://telegram.org";
|
||||
};
|
||||
|
||||
interval = mkOption {
|
||||
type = types.str;
|
||||
default = "3m";
|
||||
description = "How often outbounds are re-tested (Go duration).";
|
||||
example = "1m";
|
||||
};
|
||||
|
||||
tolerance = mkOption {
|
||||
type = types.int;
|
||||
default = 50;
|
||||
description = "Milliseconds a faster outbound must win by to replace the current one (sing-box only).";
|
||||
example = 100;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
t = import ./types.nix { inherit lib; };
|
||||
list =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
inherit description example;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxy.routing = {
|
||||
default = mkOption {
|
||||
type = types.enum [
|
||||
"proxy"
|
||||
"direct"
|
||||
];
|
||||
default = "proxy";
|
||||
description = "Where traffic no routing rule matches goes.";
|
||||
example = "direct";
|
||||
};
|
||||
|
||||
directRu = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''Send geosite "category-ru" and geoip "ru" direct.'';
|
||||
};
|
||||
|
||||
proxy = {
|
||||
domains = list "Domain suffixes sent through the proxy." [ "youtube.com" ];
|
||||
ips = list "IP CIDRs sent through the proxy." [ "1.1.1.0/24" ];
|
||||
geosites = list "Geosite names sent through the proxy." [ "netflix" ];
|
||||
geoips = list "Geoip names sent through the proxy." [ "us" ];
|
||||
};
|
||||
|
||||
direct = {
|
||||
domains = list "Domain suffixes sent direct. zapret hostlists join them when zapret.directSync.enable is on." [
|
||||
"internal.example"
|
||||
];
|
||||
ips = list "IP CIDRs sent direct." [ "10.10.0.0/16" ];
|
||||
geosites = list "Geosite names sent direct." [ "category-ru" ];
|
||||
geoips = list "Geoip names sent direct." [ "ru" ];
|
||||
};
|
||||
|
||||
block = {
|
||||
domains = list "Domain suffixes blocked." [ "ads.example.com" ];
|
||||
ips = list "IP CIDRs blocked." [ "203.0.113.0/24" ];
|
||||
geosites = list "Geosite names blocked." [ "category-ads-all" ];
|
||||
geoips = list "Geoip names blocked." [ "cn" ];
|
||||
};
|
||||
|
||||
rules = mkOption {
|
||||
type = types.listOf t.routingRuleType;
|
||||
default = [ ];
|
||||
description = "Rules checked before the proxy/direct/block lists, in order; the first match wins.";
|
||||
example = [
|
||||
{
|
||||
outbound = "vps-de";
|
||||
geosites = [ "netflix" ];
|
||||
}
|
||||
{
|
||||
outbound = "direct";
|
||||
domains = [ "internal.corp" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxy.tproxy = {
|
||||
enable = mkEnableOption "global TProxy mode (proxy-suite-tproxy)";
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 1085;
|
||||
description = "Port of the TProxy inbound.";
|
||||
};
|
||||
|
||||
fwmark = mkOption {
|
||||
type = types.int;
|
||||
default = 1;
|
||||
description = "Mark of intercepted packets, routed through routeTable.";
|
||||
};
|
||||
|
||||
proxyMark = mkOption {
|
||||
type = types.int;
|
||||
default = 2;
|
||||
description = "Mark of the backend's own traffic, so it is not intercepted again.";
|
||||
};
|
||||
|
||||
routeTable = mkOption {
|
||||
type = types.int;
|
||||
default = 100;
|
||||
description = "Policy-routing table for intercepted traffic.";
|
||||
};
|
||||
|
||||
localSubnets = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ "192.168.0.0/16" ];
|
||||
description = "Subnets that bypass interception (DNS excepted): your LAN, VM bridges.";
|
||||
example = [
|
||||
"192.168.0.0/16"
|
||||
"10.0.0.0/8"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxy.tun = {
|
||||
enable = mkEnableOption "global TUN mode (proxy-suite-tun)";
|
||||
|
||||
interface = mkOption {
|
||||
type = types.str;
|
||||
default = "singtun0";
|
||||
description = "TUN interface name.";
|
||||
};
|
||||
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "172.19.0.1/30";
|
||||
description = "TUN interface address (CIDR).";
|
||||
};
|
||||
|
||||
mtu = mkOption {
|
||||
type = types.int;
|
||||
default = 1400;
|
||||
description = "TUN interface MTU.";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
{
|
||||
lib,
|
||||
proxySuiteUpstream,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (lib)
|
||||
literalExpression
|
||||
literalMD
|
||||
mkEnableOption
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxy = {
|
||||
enable = mkEnableOption "the local proxy";
|
||||
|
||||
backend = mkOption {
|
||||
type = types.enum [
|
||||
"sing-box"
|
||||
"xray"
|
||||
"hybrid"
|
||||
];
|
||||
default = "sing-box";
|
||||
description = ''
|
||||
Proxy backend. "hybrid" runs sing-box in front and hands XRay-only outbounds
|
||||
(XHTTP, ECH) to XRay.
|
||||
'';
|
||||
example = "hybrid";
|
||||
};
|
||||
|
||||
autostart = mkOption {
|
||||
type = types.nullOr (
|
||||
types.enum [
|
||||
"tun"
|
||||
"tproxy"
|
||||
]
|
||||
);
|
||||
default = null;
|
||||
description = ''
|
||||
Transparent mode started at boot, or null for neither. The mode named here must
|
||||
also be enabled (proxy.tun.enable or proxy.tproxy.enable).
|
||||
'';
|
||||
example = "tun";
|
||||
};
|
||||
|
||||
listener = {
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = ''Bind address of the local SOCKS5/HTTP proxy. Use "0.0.0.0" only to expose it to the network.'';
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 1080;
|
||||
description = "Port of the local SOCKS5/HTTP proxy.";
|
||||
};
|
||||
|
||||
auth = {
|
||||
username = mkOption {
|
||||
type = types.nullOr (types.strMatching "[^[:space:]]+");
|
||||
default = null;
|
||||
description = "Username the local proxy requires. Set together with password or passwordFile.";
|
||||
example = "proxy-user";
|
||||
};
|
||||
|
||||
password = mkOption {
|
||||
type = types.nullOr (types.strMatching "[^[:space:]]+");
|
||||
default = null;
|
||||
description = "Inline local proxy password. Ends up in the Nix store; prefer passwordFile.";
|
||||
example = "change-me";
|
||||
};
|
||||
|
||||
passwordFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to the local proxy password. With perAppRouting.proxychains it must be a
|
||||
single token, and it is readable by userControl.group through the proxychains config.
|
||||
'';
|
||||
example = "/run/secrets/proxy-suite-local-proxy-password";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
autoProxy = {
|
||||
enable = mkEnableOption "autoProxy" // {
|
||||
description = ''
|
||||
Probe each exit for the destinations clients dial, and route each one through the first
|
||||
exit that reaches it for as long as it keeps working (`proxy-ctl proxy auto probe` shows a
|
||||
verdict). Censor-side failures stay direct for zapret. Needs the sing-box backend, and
|
||||
makes this host fetch every new destination itself.
|
||||
'';
|
||||
};
|
||||
|
||||
interval = mkOption {
|
||||
type = types.str;
|
||||
default = "10m";
|
||||
description = "Time between probe runs. `proxy-ctl proxy auto learn` does not wait for it.";
|
||||
example = "30m";
|
||||
};
|
||||
|
||||
probesPerRun = mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 200;
|
||||
description = "Most destinations probed per run; the rest wait in a backlog, most-dialled first.";
|
||||
};
|
||||
|
||||
maxExits = mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 12;
|
||||
description = ''
|
||||
Most exits probed, direct included. The first round tries one exit per network (AS), a
|
||||
second round the rest.
|
||||
'';
|
||||
};
|
||||
|
||||
ttlDays = mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 30;
|
||||
description = ''
|
||||
Days a verdict stands, routed destinations included: a route is re-probed once this long
|
||||
has passed. Everything is relearned when this host's public address changes, and
|
||||
`proxy-ctl proxy auto learn <domain>` re-probes one destination right away.
|
||||
'';
|
||||
};
|
||||
|
||||
slowBelowKiBps = mkOption {
|
||||
type = types.ints.unsigned;
|
||||
default = 150;
|
||||
description = ''
|
||||
Also route destinations that work directly but crawl: at least 300 KiB in a 10 s sample,
|
||||
never faster than this. 0 disables. Needs `selection` other than "first".
|
||||
'';
|
||||
example = 0;
|
||||
};
|
||||
|
||||
exclude = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "Domain suffixes never probed or auto-routed.";
|
||||
example = [ "internal.example" ];
|
||||
};
|
||||
|
||||
probeBasePort = mkOption {
|
||||
type = types.port;
|
||||
default = 18540;
|
||||
description = ''
|
||||
First loopback port of the per-exit probe listeners (one per exit, maxExits in total).
|
||||
They are unauthenticated even when proxy.listener.auth is set.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
singBox = {
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = proxySuiteUpstream.sing-box;
|
||||
defaultText = literalMD "`sing-box` from proxy-suite's own `nixpkgs` input";
|
||||
example = literalExpression "pkgs.sing-box";
|
||||
description = ''sing-box package, used when backend is "sing-box" or "hybrid".'';
|
||||
};
|
||||
|
||||
clashApiPort = mkOption {
|
||||
type = types.port;
|
||||
default = 9090;
|
||||
description = ''Port of sing-box's Clash API, used with selection "selector" or "urltest".'';
|
||||
};
|
||||
};
|
||||
|
||||
xray = {
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = proxySuiteUpstream.xray;
|
||||
defaultText = literalMD "proxy-suite's `xray` (`pkgs/xray.nix`)";
|
||||
example = literalExpression "pkgs.xray";
|
||||
description = ''XRay package, used when backend is "xray" or "hybrid".'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
p = path: [ "services" "proxy-suite" ] ++ lib.splitString "." path;
|
||||
rm = path: replacement: lib.mkRemovedOptionModule (p path) replacement;
|
||||
# Top-level zapret options that moved under the engine namespace; the value is
|
||||
# the leaf name they carry there.
|
||||
zapretMoved = {
|
||||
configName = "configName";
|
||||
gameFilter = "gameFilter";
|
||||
hostlistRules = "hostlistRules";
|
||||
includeExtraUpstreamLists = "includeExtraUpstreamLists";
|
||||
listGeneral = "domains";
|
||||
listExclude = "excludeDomains";
|
||||
ipsetAll = "ips";
|
||||
ipsetExclude = "excludeIps";
|
||||
};
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
# These were aliases; they are removal notices now, so there is one
|
||||
# compatibility policy instead of two.
|
||||
(rm "proxyInbounds" "Use services.proxy-suite.inbounds.")
|
||||
(rm "proxy.tun.perApp" "Use services.proxy-suite.perAppRouting.tun.")
|
||||
(rm "proxy.tproxy.perApp" "Use services.proxy-suite.perAppRouting.tproxy.")
|
||||
(rm "zapret.perApp" "Use services.proxy-suite.perAppRouting.zapret.")
|
||||
(rm "proxy.singBox.urlTest.tolerance" "Use services.proxy-suite.proxy.urlTest.tolerance.")
|
||||
(rm "tgWsProxy.host" "Use services.proxy-suite.tgWsProxy.listener.address.")
|
||||
(rm "singBox" "Use services.proxy-suite.proxy, with sing-box-specific options under proxy.singBox.")
|
||||
|
||||
# proxy.
|
||||
(rm "proxy.singBox.enable" ''Use services.proxy-suite.proxy.backend = "sing-box" (or "hybrid").'')
|
||||
(rm "proxy.xray.enable" ''Use services.proxy-suite.proxy.backend = "xray" (or "hybrid").'')
|
||||
(rm "proxy.listenAddress" "Use services.proxy-suite.proxy.listener.address.")
|
||||
(rm "proxy.port" "Use services.proxy-suite.proxy.listener.port.")
|
||||
(rm "proxy.auth.username" "Use services.proxy-suite.proxy.listener.auth.username.")
|
||||
(rm "proxy.auth.password" "Use services.proxy-suite.proxy.listener.auth.password.")
|
||||
(rm "proxy.auth.passwordFile" "Use services.proxy-suite.proxy.listener.auth.passwordFile.")
|
||||
(rm "proxy.proxyByDefault" ''Use services.proxy-suite.proxy.routing.default = "proxy" or "direct".'')
|
||||
(rm "proxy.routing.enableRuDirect" "Use services.proxy-suite.proxy.routing.directRu.")
|
||||
(rm "proxy.tun.autostart" ''Use services.proxy-suite.proxy.autostart = "tun".'')
|
||||
(rm "proxy.tproxy.autostart" ''Use services.proxy-suite.proxy.autostart = "tproxy".'')
|
||||
|
||||
# zapret. Both engines now spell their lists the same way.
|
||||
(rm "zapret.syncDirectRouting" "Use services.proxy-suite.zapret.directSync.enable.")
|
||||
(rm "zapret.syncDirectRoutingUpstreamIps" "Use services.proxy-suite.zapret.directSync.upstreamIps.")
|
||||
(rm "zapret.syncDirectRoutingUserIps" "Use services.proxy-suite.zapret.directSync.userIps.")
|
||||
|
||||
# sshProxy splits into server (where it dials) and listener (what it opens).
|
||||
(rm "sshProxy.user" "Use services.proxy-suite.sshProxy.server.user.")
|
||||
(rm "sshProxy.host" "Use services.proxy-suite.sshProxy.server.host.")
|
||||
(rm "sshProxy.sshPort" "Use services.proxy-suite.sshProxy.server.port.")
|
||||
(rm "sshProxy.listenAddress" "Use services.proxy-suite.sshProxy.listener.address.")
|
||||
(rm "sshProxy.listenPort" "Use services.proxy-suite.sshProxy.listener.port.")
|
||||
|
||||
# tgWsProxy groups its listener, Cloudflare and logging knobs.
|
||||
(rm "tgWsProxy.port" "Use services.proxy-suite.tgWsProxy.listener.port.")
|
||||
(rm "tgWsProxy.cfProxyDomains" "Use services.proxy-suite.tgWsProxy.cloudflare.domains.")
|
||||
(rm "tgWsProxy.cfProxyWorkerDomains" "Use services.proxy-suite.tgWsProxy.cloudflare.workerDomains.")
|
||||
(rm "tgWsProxy.cfProxyFallback" "Use services.proxy-suite.tgWsProxy.cloudflare.fallback.")
|
||||
(rm "tgWsProxy.bufKb" "Use services.proxy-suite.tgWsProxy.bufferKiB.")
|
||||
(rm "tgWsProxy.routingMark" "Use services.proxy-suite.tgWsProxy.fwmark.")
|
||||
(rm "tgWsProxy.verbose" "Use services.proxy-suite.tgWsProxy.log.verbose.")
|
||||
(rm "tgWsProxy.logFile" "Use services.proxy-suite.tgWsProxy.log.file.")
|
||||
(rm "tgWsProxy.logMaxMb" "Use services.proxy-suite.tgWsProxy.log.maxSizeMiB.")
|
||||
(rm "tgWsProxy.logBackups" "Use services.proxy-suite.tgWsProxy.log.keep.")
|
||||
|
||||
# userControl.
|
||||
(rm "userControl.global.enable" ''Use services.proxy-suite.userControl.allow, which lists "global" by default.'')
|
||||
(rm "userControl.perApp.enable" ''Use services.proxy-suite.userControl.allow, which lists "perApp" by default.'')
|
||||
]
|
||||
++ lib.mapAttrsToList (
|
||||
old: new: rm "zapret.${old}" "Use services.proxy-suite.zapret.zapret-discord-youtube.${new}."
|
||||
) zapretMoved;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption;
|
||||
t = import ./types.nix { inherit lib; };
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxy.dns = {
|
||||
local = mkOption {
|
||||
type = t.dnsUpstreamType;
|
||||
default = {
|
||||
type = "udp";
|
||||
address = "1.1.1.1";
|
||||
port = 53;
|
||||
};
|
||||
description = ''
|
||||
DNS upstream used for the built-in "local" resolver role.
|
||||
This resolver is also used as the backend's default domain resolver.
|
||||
|
||||
The module keeps detour policy automatic: in mixed/TProxy mode and
|
||||
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.
|
||||
'';
|
||||
example = {
|
||||
type = "tcp";
|
||||
address = "9.9.9.9";
|
||||
port = 53;
|
||||
};
|
||||
};
|
||||
|
||||
remote = mkOption {
|
||||
type = t.dnsUpstreamType;
|
||||
default = {
|
||||
type = "udp";
|
||||
address = "1.1.1.1";
|
||||
port = 53;
|
||||
};
|
||||
description = ''
|
||||
DNS upstream used for the built-in "remote" resolver role.
|
||||
|
||||
This resolver always detours through the proxy and becomes the
|
||||
generated dns.final target when proxy.proxyByDefault = true.
|
||||
'';
|
||||
example = {
|
||||
type = "tls";
|
||||
address = "1.1.1.1";
|
||||
port = 853;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
t = import ./types.nix { inherit lib; };
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxy = {
|
||||
outbounds = mkOption {
|
||||
type = types.listOf t.outboundType;
|
||||
default = [ ];
|
||||
description = ''
|
||||
List of static proxy outbounds.
|
||||
Set exactly one of urlFile, url, singBoxJson, xrayJson, or the
|
||||
deprecated json field per entry. Backend-specific raw JSON fields are
|
||||
only valid with their matching backend.
|
||||
|
||||
At least one outbound or one subscription is required when
|
||||
proxy.enable = true.
|
||||
'';
|
||||
example = [
|
||||
{
|
||||
tag = "de-vps";
|
||||
urlFile = "/run/secrets/proxy-de-url";
|
||||
}
|
||||
{
|
||||
tag = "nl-vps";
|
||||
url = "hy2://password@example.com:443?sni=example.com";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
subscriptions = mkOption {
|
||||
type = types.listOf t.subscriptionType;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Subscription URLs that provide dynamic lists of proxy outbounds.
|
||||
Each URL must return a base64-encoded newline-separated list of proxy URIs
|
||||
(standard v2rayN / Clash subscription format) or plain text of the same.
|
||||
|
||||
On first service start, each subscription is fetched live and cached
|
||||
under /var/lib/proxy-suite/subscriptions/<backend>/<tag>.json. Later restarts
|
||||
reuse the cache, so ordinary service restarts do not need network access.
|
||||
|
||||
A systemd timer (proxy-suite-subscription-update) refreshes all caches
|
||||
on the interval set by subscriptionUpdateInterval and restarts the
|
||||
running proxy services after a successful refresh.
|
||||
'';
|
||||
example = [
|
||||
{
|
||||
tag = "community";
|
||||
url = "https://example.com/sub/token";
|
||||
}
|
||||
{
|
||||
tag = "private";
|
||||
urlFile = "/run/secrets/private-sub-url";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
subscriptionUpdateInterval = mkOption {
|
||||
type = types.str;
|
||||
default = "1d";
|
||||
description = ''
|
||||
How often the proxy-suite-subscription-update timer fires and refreshes
|
||||
all subscription caches. Accepts any systemd time span string
|
||||
(e.g. "1h", "6h", "1d", "12h").
|
||||
|
||||
Only used when proxy.subscriptions is non-empty. The timer also runs
|
||||
once shortly after boot.
|
||||
'';
|
||||
example = "6h";
|
||||
};
|
||||
|
||||
selection = mkOption {
|
||||
type = types.enum [
|
||||
"first"
|
||||
"selector"
|
||||
"urltest"
|
||||
];
|
||||
default = "first";
|
||||
description = ''
|
||||
How to pick between multiple proxy outbounds:
|
||||
|
||||
- "first": route through a single active outbound tagged "proxy".
|
||||
The first static outbound is used, or the first subscription
|
||||
outbound if only subscriptions are configured.
|
||||
- "selector": create a Clash-compatible selector outbound tagged
|
||||
"proxy" and keep all configured outbounds available for manual
|
||||
switching via the Clash API.
|
||||
- "urltest": create automatic latency testing tagged "proxy" and
|
||||
keep all configured outbounds available so the active backend can
|
||||
periodically probe and switch to a faster one.
|
||||
|
||||
proxy.singBox.clashApiPort is only used with "selector" or "urltest"
|
||||
on the SingBox backend. "selector" is SingBox-only. "urltest" maps to
|
||||
SingBox urltest or XRay observatory/balancer depending on backend.
|
||||
urlTest.* options are only used with "urltest".
|
||||
Per-outbound tags are only individually meaningful with "selector"
|
||||
or "urltest".
|
||||
'';
|
||||
example = "urltest";
|
||||
};
|
||||
|
||||
urlTest = {
|
||||
url = mkOption {
|
||||
type = types.str;
|
||||
default = "https://www.gstatic.com/generate_204";
|
||||
description = ''
|
||||
URL that the active backend fetches through each proxy to measure latency.
|
||||
Only used when selection = "urltest".
|
||||
|
||||
Set this to a URL that is actually blocked in your region (e.g.
|
||||
"https://telegram.org") so that only proxies that bypass the
|
||||
blocking get selected. If left at the default, any responding proxy
|
||||
wins – including ones that might not unblock your target site.
|
||||
'';
|
||||
example = "https://telegram.org";
|
||||
};
|
||||
|
||||
interval = mkOption {
|
||||
type = types.str;
|
||||
default = "3m";
|
||||
description = ''
|
||||
How often the active backend re-tests all outbounds. Accepts a Go
|
||||
duration string (e.g. "1m", "3m", "10m").
|
||||
Only used when selection = "urltest".
|
||||
'';
|
||||
example = "1m";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
t = import ./types.nix { inherit lib; };
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxy.routing = {
|
||||
enableRuDirect = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Automatically append "category-ru" to routing.direct.geosites and
|
||||
"ru" to routing.direct.geoips.
|
||||
|
||||
This is additive: user-defined routing.direct.* entries still apply.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
proxy = t.routingFields;
|
||||
|
||||
direct = {
|
||||
domains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Domain suffixes to send direct (bypass proxy).
|
||||
Merged with zapret-synced direct domains when zapret direct sync
|
||||
options are enabled.
|
||||
'';
|
||||
example = [ "internal.example" ];
|
||||
};
|
||||
ips = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
IP CIDRs to send direct.
|
||||
Merged with zapret-synced direct IPs when the corresponding zapret
|
||||
sync options are enabled.
|
||||
'';
|
||||
example = [ "10.10.0.0/16" ];
|
||||
};
|
||||
geosites = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
sing-geosite names to send direct.
|
||||
"category-ru" is added automatically when enableRuDirect = true.
|
||||
'';
|
||||
example = [ "category-ru" ];
|
||||
};
|
||||
geoips = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
sing-geoip names to send direct.
|
||||
"ru" is added automatically when enableRuDirect = true.
|
||||
'';
|
||||
example = [ "ru" ];
|
||||
};
|
||||
};
|
||||
|
||||
block = {
|
||||
domains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "Domain suffixes to block entirely.";
|
||||
example = [ "ads.example.com" ];
|
||||
};
|
||||
ips = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "IP CIDRs to block.";
|
||||
example = [ "203.0.113.0/24" ];
|
||||
};
|
||||
geosites = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "sing-geosite names to block.";
|
||||
example = [ "category-ads-all" ];
|
||||
};
|
||||
geoips = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "sing-geoip names to block.";
|
||||
example = [ "cn" ];
|
||||
};
|
||||
};
|
||||
|
||||
rules = mkOption {
|
||||
type = types.listOf t.routingRuleType;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Explicit routing rules evaluated before global proxy/direct/block lists.
|
||||
Each rule routes matching traffic to a specific outbound tag.
|
||||
|
||||
The outbound can be a configured outbound tag (useful with selector/urltest),
|
||||
or one of: "proxy" (active proxy), "direct", "block".
|
||||
|
||||
Order is preserved. The first matching rule wins in the active backend.
|
||||
With selection = "first", non-built-in outbound tags are effectively
|
||||
routed to the single active "proxy" outbound.
|
||||
'';
|
||||
example = [
|
||||
{
|
||||
outbound = "vps-de";
|
||||
domains = [ "netflix.com" ];
|
||||
geosites = [ "netflix" ];
|
||||
}
|
||||
{
|
||||
outbound = "direct";
|
||||
domains = [ "internal.corp" ];
|
||||
}
|
||||
{
|
||||
outbound = "block";
|
||||
domains = [ "ads.example.com" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption mkEnableOption types;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxy.tproxy = {
|
||||
enable = mkEnableOption "global proxy TProxy mode service";
|
||||
|
||||
autostart = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to start proxy-suite-tproxy automatically during boot by
|
||||
attaching it to multi-user.target.
|
||||
Cannot be enabled together with proxy.tun.autostart.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 1085;
|
||||
description = ''
|
||||
Local listen port for the proxy backend's TProxy inbound.
|
||||
nftables redirection created by proxy-suite-tproxy sends intercepted
|
||||
TCP/UDP traffic to this port.
|
||||
'';
|
||||
example = 1085;
|
||||
};
|
||||
|
||||
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
|
||||
proxy.tproxy.routeTable, which points traffic to
|
||||
loopback for local proxy processing.
|
||||
'';
|
||||
example = 1;
|
||||
};
|
||||
|
||||
proxyMark = mkOption {
|
||||
type = types.int;
|
||||
default = 2;
|
||||
description = ''
|
||||
Mark applied to backend 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 proxy.tproxy.fwmark.
|
||||
'';
|
||||
example = 100;
|
||||
};
|
||||
|
||||
localSubnets = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ "192.168.0.0/16" ];
|
||||
description = ''
|
||||
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
|
||||
subnet-specific NFQUEUE exemption on the zapret side.
|
||||
'';
|
||||
example = [
|
||||
"192.168.0.0/16"
|
||||
"10.0.0.0/8"
|
||||
];
|
||||
};
|
||||
|
||||
perApp = {
|
||||
enable = mkEnableOption "per-app-scoped proxy 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"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption mkEnableOption types;
|
||||
|
||||
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.proxy.tun = {
|
||||
enable = mkEnableOption "global proxy TUN mode service";
|
||||
|
||||
autostart = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to start proxy-suite-tun automatically during boot by
|
||||
attaching it to multi-user.target.
|
||||
Cannot be enabled together with proxy.tproxy.autostart.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
perApp = {
|
||||
enable = mkEnableOption "per-app-scoped proxy TUN backend for perAppRouting profiles";
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
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.";
|
||||
};
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
# Core proxy options. Feature-area options live in sing-box-{outbounds,dns,tun,tproxy,routing}.nix.
|
||||
{ lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
inherit (lib)
|
||||
literalExpression
|
||||
mkOption
|
||||
mkEnableOption
|
||||
types
|
||||
;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxy = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to configure and run the proxy backend services.
|
||||
This is disabled by default; enable it explicitly and choose at least
|
||||
one backend with proxy.singBox.enable or proxy.xray.enable. Enabling
|
||||
both runs sing-box as the frontend and XRay as a sidecar for outbounds
|
||||
that require XRay.
|
||||
'';
|
||||
};
|
||||
|
||||
listenAddress = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = ''
|
||||
Address for the local SOCKS5/HTTP inbound to bind to.
|
||||
This affects the proxy-suite-socks service.
|
||||
|
||||
Use "0.0.0.0" only if you intentionally want to expose the proxy to
|
||||
other machines on your network.
|
||||
'';
|
||||
example = "127.0.0.1";
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 1080;
|
||||
description = ''
|
||||
Listen port for the local SOCKS5/HTTP proxy inbound provided by
|
||||
proxy-suite-socks. SingBox exposes SOCKS5 and HTTP on this port.
|
||||
XRay's Socks inbound also accepts SOCKS and HTTP.
|
||||
'';
|
||||
example = 1080;
|
||||
};
|
||||
|
||||
auth = {
|
||||
username = mkOption {
|
||||
type = types.nullOr (types.strMatching "[^[:space:]]+");
|
||||
default = null;
|
||||
description = ''
|
||||
Optional username for the local SOCKS5/HTTP mixed inbound.
|
||||
|
||||
Set this together with exactly one of auth.password or
|
||||
auth.passwordFile to require clients to authenticate before using the
|
||||
local proxy. Leave unset to keep the local proxy unauthenticated.
|
||||
'';
|
||||
example = "proxy-user";
|
||||
};
|
||||
|
||||
password = mkOption {
|
||||
type = types.nullOr (types.strMatching "[^[:space:]]+");
|
||||
default = null;
|
||||
description = ''
|
||||
Optional inline password for the local SOCKS5/HTTP mixed inbound.
|
||||
Convenient for testing, but the password ends up in the Nix store.
|
||||
|
||||
Prefer auth.passwordFile for real deployments.
|
||||
'';
|
||||
example = "change-me";
|
||||
};
|
||||
|
||||
passwordFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to a file containing the local proxy password.
|
||||
Intended for use with secret managers so the password stays out of
|
||||
the Nix store. The file is read when proxy-suite-socks starts.
|
||||
|
||||
If perAppRouting.proxychains.enable is also used, keep this password
|
||||
as a single non-whitespace token so it can be written to the
|
||||
proxychains-ng config format. The generated proxychains config is
|
||||
readable by members of userControl.group.
|
||||
'';
|
||||
example = "/run/secrets/proxy-suite-local-proxy-password";
|
||||
};
|
||||
};
|
||||
|
||||
proxyByDefault = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether traffic that does not match any explicit routing rule should
|
||||
go through the proxy or go direct.
|
||||
|
||||
This affects the generated backend route final and DNS final in the
|
||||
config.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
singBox = {
|
||||
enable = mkEnableOption "SingBox proxy backend";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.sing-box;
|
||||
defaultText = literalExpression "pkgs.sing-box";
|
||||
example = literalExpression "pkgs.sing-box";
|
||||
description = ''
|
||||
sing-box package used by proxy-suite systemd services.
|
||||
|
||||
Override this to pin or test a specific sing-box build when upstream
|
||||
protocol behavior changes.
|
||||
'';
|
||||
};
|
||||
|
||||
clashApiPort = mkOption {
|
||||
type = types.port;
|
||||
default = 9090;
|
||||
description = ''
|
||||
Port for the Clash-compatible REST API exposed by sing-box.
|
||||
Only used when proxy.selection is "selector" or "urltest". Ignored
|
||||
in "first" mode because there is no selector-style outbound to
|
||||
control.
|
||||
'';
|
||||
example = 9090;
|
||||
};
|
||||
|
||||
urlTest.tolerance = mkOption {
|
||||
type = types.int;
|
||||
default = 50;
|
||||
description = ''
|
||||
Latency tolerance in milliseconds for sing-box urltest. The current
|
||||
proxy is only replaced when a competing one is faster by more than
|
||||
this value.
|
||||
|
||||
Only used when proxy.selection = "urltest" and the SingBox backend
|
||||
is active.
|
||||
'';
|
||||
example = 100;
|
||||
};
|
||||
};
|
||||
|
||||
xray = {
|
||||
enable = mkEnableOption "XRay proxy backend";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.xray;
|
||||
defaultText = literalExpression "pkgs.xray";
|
||||
example = literalExpression "pkgs.xray";
|
||||
description = ''
|
||||
XRay package used by proxy-suite systemd services.
|
||||
|
||||
Override this to pin or test a specific XRay build when upstream
|
||||
protocol behavior changes.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,138 +1,110 @@
|
||||
# SSH dynamic SOCKS5 proxy options.
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
token = types.nullOr (types.strMatching "[^[:space:]]+");
|
||||
path =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
inherit description example;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.sshProxy = {
|
||||
enable = mkEnableOption "SSH dynamic SOCKS5 proxy";
|
||||
enable = mkEnableOption "an SSH dynamic SOCKS5 tunnel";
|
||||
|
||||
user = mkOption {
|
||||
type = types.nullOr (types.strMatching "[^[:space:]]+");
|
||||
default = null;
|
||||
# Where the tunnel goes.
|
||||
server = {
|
||||
user = mkOption {
|
||||
type = token;
|
||||
default = null;
|
||||
description = "SSH login user.";
|
||||
example = "root";
|
||||
};
|
||||
|
||||
host = mkOption {
|
||||
type = token;
|
||||
default = null;
|
||||
description = "SSH server.";
|
||||
example = "ssh.example.com";
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 22;
|
||||
description = "SSH server port.";
|
||||
};
|
||||
};
|
||||
|
||||
asOutbound = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
SSH login user. Required when sshProxy.enable is true.
|
||||
Add the tunnel as an outbound tagged "ssh-proxy". sing-box dials SSH itself; XRay goes
|
||||
through the OpenSSH unit's SOCKS listener.
|
||||
'';
|
||||
example = "root";
|
||||
};
|
||||
|
||||
serviceUser = mkOption {
|
||||
type = types.nullOr (types.strMatching "[^[:space:]]+");
|
||||
default = null;
|
||||
description = ''
|
||||
Unix user for the systemd SSH proxy service. Leave unset to use
|
||||
systemd's default user.
|
||||
|
||||
OpenSSH path only: ignored when a SingBox or hybrid backend dials SSH
|
||||
natively and no separate unit is created.
|
||||
'';
|
||||
example = "proxy";
|
||||
};
|
||||
|
||||
host = mkOption {
|
||||
type = types.nullOr (types.strMatching "[^[:space:]]+");
|
||||
default = null;
|
||||
description = ''
|
||||
SSH server hostname or address. Required when sshProxy.enable is true.
|
||||
'';
|
||||
example = "ssh.example.com";
|
||||
};
|
||||
|
||||
sshPort = mkOption {
|
||||
type = types.port;
|
||||
default = 22;
|
||||
description = "Remote SSH server port.";
|
||||
example = 22;
|
||||
};
|
||||
|
||||
listenAddress = mkOption {
|
||||
type = types.strMatching "[^[:space:]]+";
|
||||
default = "127.0.0.1";
|
||||
description = ''
|
||||
Local address for the SSH-created SOCKS5 listener.
|
||||
|
||||
OpenSSH path only: a SingBox or hybrid backend dials SSH natively and
|
||||
creates no local listener.
|
||||
'';
|
||||
example = "127.0.0.1";
|
||||
};
|
||||
|
||||
listenPort = mkOption {
|
||||
type = types.port;
|
||||
default = 1091;
|
||||
description = ''
|
||||
Local port for the SSH-created SOCKS5 listener.
|
||||
|
||||
OpenSSH path only: a SingBox or hybrid backend dials SSH natively and
|
||||
creates no local listener.
|
||||
'';
|
||||
example = 1091;
|
||||
};
|
||||
|
||||
identityFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to the SSH private key. Leave unset to use the SSH agent
|
||||
or OpenSSH's normal identity-file lookup.
|
||||
'';
|
||||
example = "/run/secrets/proxy-suite-ssh-key";
|
||||
};
|
||||
|
||||
knownHostsFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Optional runtime path to the known-hosts file passed to OpenSSH.
|
||||
|
||||
OpenSSH path only. A SingBox or hybrid backend verifies host keys with
|
||||
sshProxy.hostKey instead.
|
||||
'';
|
||||
example = "/run/secrets/proxy-suite-ssh-known-hosts";
|
||||
};
|
||||
identityFile = path "Runtime path to the private key. Null uses the agent or OpenSSH defaults." "/run/secrets/proxy-suite-ssh-key";
|
||||
|
||||
hostKey = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Accepted SSH host public keys, in `authorized_keys` one-line form.
|
||||
Used by the sing-box backend, which verifies host keys by value rather
|
||||
than against a known-hosts file.
|
||||
|
||||
List **every** key the server offers, not just one. The host key
|
||||
algorithm is negotiated, so pinning a single key fails the handshake
|
||||
outright whenever the server picks a different algorithm. Get the full
|
||||
set with `ssh-keyscan -p PORT HOST`, or from an existing known-hosts
|
||||
entry with `ssh-keygen -F '[HOST]:PORT'`.
|
||||
|
||||
Leaving this empty accepts **any** host key, which allows a
|
||||
machine-in-the-middle on the tunnel. Set it whenever sshProxy.asOutbound
|
||||
is used with a SingBox or hybrid backend.
|
||||
|
||||
Ignored by the XRay backend and by a standalone tunnel, which use
|
||||
knownHostsFile and strictHostKeyChecking instead.
|
||||
Accepted host keys (sing-box). List every key `ssh-keyscan` prints: the algorithm is
|
||||
negotiated. Empty accepts any key.
|
||||
'';
|
||||
example = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI..." ];
|
||||
};
|
||||
|
||||
hostKeyFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
hostKeyFile = path "Known-hosts file to read hostKey from at runtime (sing-box). Wins over hostKey." "/root/.ssh/known_hosts";
|
||||
|
||||
# The rest only apply to the OpenSSH unit (XRay, or asOutbound = false).
|
||||
knownHostsFile = path "Known-hosts file for OpenSSH." "/run/secrets/proxy-suite-ssh-known-hosts";
|
||||
|
||||
strictHostKeyChecking = mkOption {
|
||||
type = types.enum [
|
||||
"yes"
|
||||
"accept-new"
|
||||
"no"
|
||||
];
|
||||
default = "accept-new";
|
||||
description = "OpenSSH host key policy.";
|
||||
example = "yes";
|
||||
};
|
||||
|
||||
# The local SOCKS5 listener the OpenSSH unit opens.
|
||||
listener = {
|
||||
address = mkOption {
|
||||
type = types.strMatching "[^[:space:]]+";
|
||||
default = "127.0.0.1";
|
||||
description = "Address of the OpenSSH SOCKS5 listener.";
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 1091;
|
||||
description = "Port of the OpenSSH SOCKS5 listener.";
|
||||
};
|
||||
};
|
||||
|
||||
serviceUser = mkOption {
|
||||
type = token;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to a known-hosts file to read the accepted host keys from,
|
||||
instead of listing them inline in sshProxy.hostKey. Every key recorded
|
||||
there for `host:sshPort` is accepted, so a single known-hosts file stays
|
||||
the one source of truth. Hashed known-hosts files work.
|
||||
description = "Unix user running the OpenSSH unit.";
|
||||
example = "proxy";
|
||||
};
|
||||
|
||||
Read when the service starts, not at evaluation time, so the file never
|
||||
enters the Nix store. Set either this or sshProxy.hostKey; if both are
|
||||
set the file wins.
|
||||
|
||||
Used by the sing-box backend. The XRay backend and a standalone tunnel
|
||||
pass knownHostsFile to OpenSSH instead.
|
||||
'';
|
||||
example = "/root/.ssh/known_hosts";
|
||||
extraArgs = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "Extra OpenSSH arguments.";
|
||||
example = [
|
||||
"-J"
|
||||
"jump.example.com"
|
||||
];
|
||||
};
|
||||
|
||||
domainStrategy = mkOption {
|
||||
@@ -145,74 +117,8 @@ in
|
||||
]
|
||||
);
|
||||
default = null;
|
||||
description = ''
|
||||
Resolve destination domains locally before sending them through the
|
||||
SSH SOCKS5 proxy, so the remote SSH server never has to resolve them.
|
||||
Null preserves the backend's default behavior.
|
||||
|
||||
Only applies to the XRay backend, which reaches the tunnel through the
|
||||
local SOCKS5 listener and maps this onto the outbound's
|
||||
`sockopt.domainStrategy`. SingBox and hybrid backends dial SSH natively
|
||||
and resolve destinations themselves, so this option is ignored there.
|
||||
|
||||
Note that local resolution hands the remote server an address chosen by
|
||||
*this* machine's DNS. For anycast or geo-steered CDNs that address can
|
||||
be unreachable from the remote network, which surfaces as connection
|
||||
timeouts rather than as a DNS error. Prefer fixing DNS on the remote
|
||||
server if you have access to it.
|
||||
'';
|
||||
description = "Resolve destinations locally before the tunnel (XRay only). Can break geo-steered CDNs.";
|
||||
example = "prefer_ipv4";
|
||||
};
|
||||
|
||||
strictHostKeyChecking = mkOption {
|
||||
type = types.enum [
|
||||
"yes"
|
||||
"accept-new"
|
||||
"no"
|
||||
];
|
||||
default = "accept-new";
|
||||
description = ''
|
||||
OpenSSH host-key verification policy. Use "yes" with pinned
|
||||
knownHostsFile contents for strict verification.
|
||||
|
||||
OpenSSH path only. A SingBox or hybrid backend verifies host keys with
|
||||
sshProxy.hostKey instead.
|
||||
'';
|
||||
example = "yes";
|
||||
};
|
||||
|
||||
extraArgs = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Additional arguments passed to OpenSSH before the destination.
|
||||
This can be used for options such as jump hosts or agent forwarding.
|
||||
|
||||
OpenSSH path only: ignored when a SingBox or hybrid backend dials SSH
|
||||
natively. Keepalive, connect-timeout and restart behavior are already
|
||||
set by the module, so they do not need to be repeated here.
|
||||
'';
|
||||
example = [
|
||||
"-o"
|
||||
"ServerAliveInterval=30"
|
||||
];
|
||||
};
|
||||
|
||||
asOutbound = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Add the SSH tunnel as a proxy-suite outbound tagged "ssh-proxy".
|
||||
Requires proxy.enable and an active SingBox or XRay backend.
|
||||
|
||||
How the tunnel is built depends on the backend. SingBox and hybrid
|
||||
backends dial SSH natively, with no systemd unit and no local SOCKS5
|
||||
listener. XRay has no SSH outbound, so it keeps the OpenSSH `ssh -D`
|
||||
unit and proxies through its local SOCKS5 listener. With
|
||||
asOutbound = false the OpenSSH unit is always used, since the tunnel is
|
||||
then a standalone listener the backends know nothing about.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
domains =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
inherit description example;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.tgWsProxy = {
|
||||
enable = mkEnableOption "the Telegram MTProto WebSocket proxy";
|
||||
|
||||
listener = {
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "Bind address.";
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 1443;
|
||||
description = "Listen port.";
|
||||
};
|
||||
};
|
||||
|
||||
secret = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = "Inline MTProto secret (`openssl rand -hex 16`). Ends up in the Nix store; prefer secretFile.";
|
||||
example = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
};
|
||||
|
||||
secretFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = "Runtime path to the MTProto secret.";
|
||||
example = "/run/secrets/tg-ws-proxy-secret";
|
||||
};
|
||||
|
||||
dcIps = mkOption {
|
||||
type = types.attrsOf types.str;
|
||||
default = { };
|
||||
description = "Relay IP per Telegram DC ID.";
|
||||
example = {
|
||||
"2" = "149.154.167.220";
|
||||
};
|
||||
};
|
||||
|
||||
fakeTlsDomain = mkOption {
|
||||
type = types.nullOr (types.strMatching ".+");
|
||||
default = null;
|
||||
description = "SNI for Fake TLS masking (ee-secret links).";
|
||||
example = "www.example.com";
|
||||
};
|
||||
|
||||
cloudflare = {
|
||||
domains = domains "Cloudflare-proxied domains for WebSocket fallback." [ "cdn.example.com" ];
|
||||
workerDomains = domains "Cloudflare Worker domains, tried first." [ "worker.example.com" ];
|
||||
|
||||
fallback = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Fall back to Cloudflare when direct WebSocket fails.";
|
||||
};
|
||||
};
|
||||
|
||||
poolSize = mkOption {
|
||||
type = types.ints.unsigned;
|
||||
default = 4;
|
||||
description = "WebSocket pool size per DC; 0 disables pooling.";
|
||||
};
|
||||
|
||||
bufferKiB = mkOption {
|
||||
type = types.ints.between 4 2147483647;
|
||||
default = 256;
|
||||
description = "Socket buffer size, in KiB.";
|
||||
};
|
||||
|
||||
proxyProtocol = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Accept a PROXY protocol v1 header from a fronting reverse proxy.";
|
||||
};
|
||||
|
||||
bypassTransparentProxy = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Keep the relay's own connections out of TUN/TProxy, which would otherwise loop them.";
|
||||
};
|
||||
|
||||
fwmark = mkOption {
|
||||
type = types.int;
|
||||
default = 4;
|
||||
description = "Packet mark bypassTransparentProxy uses.";
|
||||
};
|
||||
|
||||
log = {
|
||||
verbose = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Debug logging.";
|
||||
};
|
||||
|
||||
file = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = "Rotating log file. Null logs to stderr.";
|
||||
example = "/var/log/tg-ws-proxy.log";
|
||||
};
|
||||
|
||||
maxSizeMiB = mkOption {
|
||||
type = types.numbers.positive;
|
||||
default = 5.0;
|
||||
description = "Log size before rotation, in MiB.";
|
||||
};
|
||||
|
||||
keep = mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 1;
|
||||
description = "Rotated logs kept.";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.tray = {
|
||||
enable = mkEnableOption "the system tray indicator";
|
||||
|
||||
autostart = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Start the tray in graphical sessions (XDG autostart).";
|
||||
};
|
||||
|
||||
pollInterval = mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 5;
|
||||
description = "Status refresh interval, in seconds.";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,84 +1,34 @@
|
||||
# Type submodule definitions shared across options sub-files.
|
||||
{ lib }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
|
||||
# Reused in both outboundType.routing and routing.rules entries.
|
||||
list =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
inherit description example;
|
||||
};
|
||||
|
||||
routingFields = {
|
||||
domains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Domain suffixes to match in this routing rule.
|
||||
Leave empty to skip domain-based matching for this rule entry.
|
||||
'';
|
||||
example = [
|
||||
"youtube.com"
|
||||
"discord.com"
|
||||
];
|
||||
};
|
||||
ips = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
IP CIDRs to match in this routing rule.
|
||||
Leave empty to skip IP-based matching for this rule entry.
|
||||
'';
|
||||
example = [ "1.1.1.0/24" ];
|
||||
};
|
||||
geosites = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
sing-geosite rule-set names to match in this routing rule.
|
||||
Each name becomes a backend geosite rule-set reference.
|
||||
'';
|
||||
example = [
|
||||
"netflix"
|
||||
"google"
|
||||
];
|
||||
};
|
||||
geoips = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
sing-geoip rule-set names to match in this routing rule.
|
||||
Each name becomes a backend geoip rule-set reference.
|
||||
'';
|
||||
example = [
|
||||
"us"
|
||||
"de"
|
||||
];
|
||||
};
|
||||
domains = list "Domain suffixes to match." [ "youtube.com" ];
|
||||
ips = list "IP CIDRs to match." [ "1.1.1.0/24" ];
|
||||
geosites = list "Geosite names to match (see geodata)." [ "netflix" ];
|
||||
geoips = list "Geoip names to match (see geodata; the defaults are country codes only)." [ "us" ];
|
||||
};
|
||||
|
||||
routingRuleType = types.submodule {
|
||||
options = {
|
||||
outbound = mkOption {
|
||||
type = types.str;
|
||||
description = ''
|
||||
Target outbound tag. Can be a specific server tag (only useful with
|
||||
selection = "selector" or "urltest"), or one of the built-in tags:
|
||||
"proxy" (the active proxy outbound), "direct", "block".
|
||||
|
||||
With selection = "first", named proxy outbounds are collapsed into the
|
||||
single active "proxy" outbound at runtime, so per-tag routing no longer
|
||||
distinguishes between individual proxy servers.
|
||||
'';
|
||||
description = ''Outbound tag, or "proxy", "direct", "block". With selection = "first" every proxy tag means "proxy".'';
|
||||
example = "vps-de";
|
||||
};
|
||||
}
|
||||
// routingFields;
|
||||
};
|
||||
|
||||
outboundTypes = import ./types/outbounds.nix {
|
||||
inherit lib;
|
||||
inherit routingFields;
|
||||
};
|
||||
|
||||
zapretTypes = import ./types/zapret.nix { inherit lib; };
|
||||
|
||||
dnsUpstreamType = types.submodule {
|
||||
options = {
|
||||
type = mkOption {
|
||||
@@ -88,27 +38,19 @@ let
|
||||
"tls"
|
||||
];
|
||||
default = "udp";
|
||||
description = ''
|
||||
DNS transport type for this upstream resolver.
|
||||
'';
|
||||
example = "tls";
|
||||
description = "DNS transport.";
|
||||
};
|
||||
|
||||
address = mkOption {
|
||||
type = types.strMatching ".+";
|
||||
description = ''
|
||||
Resolver address or hostname used for this DNS upstream.
|
||||
'';
|
||||
description = "Resolver address.";
|
||||
example = "1.1.1.1";
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 53;
|
||||
description = ''
|
||||
Destination port for this DNS upstream.
|
||||
'';
|
||||
example = 853;
|
||||
description = "Resolver port.";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -117,10 +59,7 @@ let
|
||||
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 perAppRouting.profiles.
|
||||
'';
|
||||
description = "Profile name, unique.";
|
||||
example = "steam-browser";
|
||||
};
|
||||
|
||||
@@ -134,23 +73,9 @@ let
|
||||
];
|
||||
default = "proxychains";
|
||||
description = ''
|
||||
Per-app route backend used by proxy-ctl wrap.
|
||||
|
||||
- "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 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 per-app-routing TProxy
|
||||
slice so only that app's traffic is transparently intercepted by
|
||||
the local proxy TProxy inbound.
|
||||
- "zapret": launch the command in the dedicated per-app-routing zapret
|
||||
slice so only that app's traffic is handled by the separate
|
||||
per-app-scoped zapret instance.
|
||||
|
||||
Additional route backends may be added in the future.
|
||||
Backend: "direct" (unchanged), "proxychains", or the per-app "tun", "tproxy" or "zapret"
|
||||
backend of perAppRouting.
|
||||
'';
|
||||
example = "proxychains";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -163,5 +88,7 @@ in
|
||||
routingRuleType
|
||||
;
|
||||
}
|
||||
// outboundTypes
|
||||
// zapretTypes
|
||||
// import ./types/outbounds.nix { inherit lib routingFields; }
|
||||
// import ./types/zapret.nix { inherit lib; }
|
||||
// import ./types/inbounds.nix { inherit lib; }
|
||||
// import ./types/amnezia-wg.nix { inherit lib; }
|
||||
@@ -304,11 +304,5 @@ let
|
||||
);
|
||||
in
|
||||
{
|
||||
inherit
|
||||
profileType
|
||||
settingsType
|
||||
peerType
|
||||
obfuscationType
|
||||
rangeValue
|
||||
;
|
||||
inherit profileType;
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
{ lib }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
nullStr =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
inherit description example;
|
||||
};
|
||||
|
||||
userType = types.submodule {
|
||||
options = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = "Account label: the share link's name, and what subscriptions and stats group by.";
|
||||
example = "phone";
|
||||
};
|
||||
uuid = nullStr "UUID (vless, vmess). Ends up in the Nix store; prefer uuidFile." "b831381d-6324-4d53-ad4f-8cda48b30811";
|
||||
uuidFile = nullStr "Runtime path to the UUID." "/run/secrets/proxy-inbound-uuid";
|
||||
password = nullStr "Password (trojan, shadowsocks, socks, http). Ends up in the Nix store; prefer passwordFile." "hunter2";
|
||||
passwordFile = nullStr "Runtime path to the password." "/run/secrets/proxy-inbound-password";
|
||||
};
|
||||
};
|
||||
|
||||
transportType = types.submodule {
|
||||
options = {
|
||||
type = mkOption {
|
||||
type = types.enum [
|
||||
"raw"
|
||||
"ws"
|
||||
"grpc"
|
||||
"httpupgrade"
|
||||
"xhttp"
|
||||
];
|
||||
default = "raw";
|
||||
description = ''Stream transport. "raw" is plain TCP, the usual choice for REALITY.'';
|
||||
example = "ws";
|
||||
};
|
||||
|
||||
path = mkOption {
|
||||
type = types.str;
|
||||
default = "/";
|
||||
description = "Request path (ws, httpupgrade, xhttp).";
|
||||
example = "/download";
|
||||
};
|
||||
|
||||
host = nullStr "Expected Host header (ws, httpupgrade, xhttp). Null accepts any." "cdn.example.com";
|
||||
|
||||
mode = mkOption {
|
||||
type = types.nullOr (
|
||||
types.enum [
|
||||
"auto"
|
||||
"packet-up"
|
||||
"stream-up"
|
||||
"stream-one"
|
||||
]
|
||||
);
|
||||
default = null;
|
||||
description = ''xhttp mode. Null lets the client choose; behind an HTTP/1.1 proxy use "packet-up".'';
|
||||
example = "packet-up";
|
||||
};
|
||||
|
||||
serviceName = mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = "gRPC service name.";
|
||||
example = "GunService";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
tlsType = types.submodule {
|
||||
options = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Terminate TLS (always on for trojan). Exclusive with reality.";
|
||||
};
|
||||
certificateFile = nullStr "Runtime path to the PEM certificate chain." "/var/lib/acme/example.com/fullchain.pem";
|
||||
keyFile = nullStr "Runtime path to the PEM private key." "/var/lib/acme/example.com/key.pem";
|
||||
serverName = nullStr "SNI in share links. Defaults to inbounds.serverAddress." "example.com";
|
||||
|
||||
alpn = mkOption {
|
||||
type = types.nullOr (
|
||||
types.listOf (
|
||||
types.enum [
|
||||
"h3"
|
||||
"h2"
|
||||
"http/1.1"
|
||||
]
|
||||
)
|
||||
);
|
||||
default = null;
|
||||
description = ''
|
||||
ALPN offered and put in share links. [ "h3" ] alone makes an xhttp listener UDP-only, so
|
||||
a web server can keep the TCP port.
|
||||
'';
|
||||
example = [ "h3" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
realityType = types.submodule {
|
||||
options = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable REALITY. Exclusive with tls.";
|
||||
};
|
||||
|
||||
dest = mkOption {
|
||||
type = types.str;
|
||||
default = "www.microsoft.com:443";
|
||||
description = "TLS 1.3 + HTTP/2 server that unauthenticated probes are forwarded to.";
|
||||
};
|
||||
|
||||
serverNames = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "Accepted SNIs, served by dest. The first goes into share links.";
|
||||
example = [ "www.microsoft.com" ];
|
||||
};
|
||||
|
||||
privateKeyFile = nullStr "Runtime path to the x25519 private key (`xray x25519`)." "/run/secrets/proxy-inbound-reality-key";
|
||||
privateKey = nullStr "x25519 private key. Ends up in the Nix store; prefer privateKeyFile." "gG1Yz...";
|
||||
publicKey = nullStr "x25519 public key, required for share links." "jNXH...";
|
||||
|
||||
shortIds = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ "" ];
|
||||
description = "Accepted short IDs (hex). The first goes into share links.";
|
||||
example = [ "0123abcd" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
inboundType = types.submodule {
|
||||
options = {
|
||||
type = mkOption {
|
||||
type = types.nullOr (
|
||||
types.enum [
|
||||
"vless"
|
||||
"vmess"
|
||||
"trojan"
|
||||
"shadowsocks"
|
||||
"socks"
|
||||
"http"
|
||||
]
|
||||
);
|
||||
default = null;
|
||||
description = "Protocol. Set exactly one of type, xrayJson, or jsonFile.";
|
||||
example = "vless";
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 443;
|
||||
description = "Bound port.";
|
||||
};
|
||||
|
||||
sharePort = mkOption {
|
||||
type = types.nullOr types.port;
|
||||
default = null;
|
||||
description = "Port share links advertise, when something in front owns the public port. Null uses port.";
|
||||
example = 443;
|
||||
};
|
||||
|
||||
address = mkOption {
|
||||
type = types.strMatching "[^[:space:]]+";
|
||||
default = "::";
|
||||
description = "Bound address. A loopback address keeps the port closed in the firewall.";
|
||||
example = "127.0.0.1";
|
||||
};
|
||||
|
||||
via = nullStr "Egress, as in inbounds.routing.via. Null inherits it." "nl-vps";
|
||||
|
||||
users = mkOption {
|
||||
type = types.listOf userType;
|
||||
default = [ ];
|
||||
description = "Accepted accounts.";
|
||||
example = [ { uuidFile = "/run/secrets/proxy-inbound-uuid"; } ];
|
||||
};
|
||||
|
||||
flow = mkOption {
|
||||
type = types.nullOr (types.enum [ "xtls-rprx-vision" ]);
|
||||
default = null;
|
||||
description = "VLESS flow; raw transport only.";
|
||||
example = "xtls-rprx-vision";
|
||||
};
|
||||
|
||||
method = mkOption {
|
||||
type = types.str;
|
||||
default = "2022-blake3-aes-128-gcm";
|
||||
description = "Shadowsocks cipher. 2022 ciphers take a base64 key of matching length as password.";
|
||||
example = "aes-128-gcm";
|
||||
};
|
||||
|
||||
transport = mkOption {
|
||||
type = transportType;
|
||||
default = { };
|
||||
description = "Stream transport.";
|
||||
};
|
||||
|
||||
tls = mkOption {
|
||||
type = tlsType;
|
||||
default = { };
|
||||
description = "TLS termination.";
|
||||
};
|
||||
|
||||
reality = mkOption {
|
||||
type = realityType;
|
||||
default = { };
|
||||
description = "REALITY.";
|
||||
};
|
||||
|
||||
xrayJson = mkOption {
|
||||
type = types.nullOr types.attrs;
|
||||
default = null;
|
||||
description = "Raw XRay inbound, built into the store; tag is overridden.";
|
||||
example = {
|
||||
protocol = "dokodemo-door";
|
||||
settings.port = 8080;
|
||||
};
|
||||
};
|
||||
|
||||
jsonFile = nullStr "Runtime path to a raw XRay inbound (no share link); tag is overridden." "/run/secrets/proxy-inbound-vless.json";
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit inboundType;
|
||||
}
|
||||
@@ -1,51 +1,31 @@
|
||||
# Subscription and outbound option type definitions.
|
||||
{ lib, routingFields }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
nullStr =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
inherit description example;
|
||||
};
|
||||
nullAttrs =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.nullOr types.attrs;
|
||||
default = null;
|
||||
inherit description example;
|
||||
};
|
||||
|
||||
subscriptionType = types.submodule {
|
||||
options = {
|
||||
tag = mkOption {
|
||||
type = types.strMatching "^[A-Za-z0-9][A-Za-z0-9._-]*$";
|
||||
description = ''
|
||||
Unique identifier for this subscription.
|
||||
Used as a prefix for all outbound tags generated from its proxy list,
|
||||
e.g. "my-sub" -> tags like "my-sub-Server-DE".
|
||||
|
||||
This value is also used as the subscription cache filename stem under
|
||||
/var/lib/proxy-suite/subscriptions/<backend>/, so it must be a safe
|
||||
identifier.
|
||||
'';
|
||||
description = "Unique name; prefixes the tags of its outbounds and names its cache file.";
|
||||
example = "community-list";
|
||||
};
|
||||
|
||||
url = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Literal subscription URL. The response must be a base64-encoded
|
||||
newline-separated list of proxy URIs (standard v2rayN format) or
|
||||
a plain-text list of the same.
|
||||
|
||||
This value is embedded in the Nix store. Prefer urlFile for private
|
||||
subscription links or tokens.
|
||||
'';
|
||||
example = "https://example.com/sub/token123";
|
||||
};
|
||||
|
||||
urlFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to a file containing the subscription URL.
|
||||
Intended for use with secret managers (sops-nix, agenix, etc.).
|
||||
The file is read at service start time and never lands in the Nix store.
|
||||
|
||||
Set exactly one of urlFile or url for each subscription entry.
|
||||
'';
|
||||
example = "/run/secrets/proxy-subscription-url";
|
||||
};
|
||||
url = nullStr "Subscription URL. Ends up in the Nix store; prefer urlFile." "https://example.com/sub/token123";
|
||||
urlFile = nullStr "Runtime path to the subscription URL." "/run/secrets/proxy-subscription-url";
|
||||
};
|
||||
};
|
||||
|
||||
@@ -53,41 +33,29 @@ let
|
||||
options = {
|
||||
tag = mkOption {
|
||||
type = types.str;
|
||||
description = ''
|
||||
Outbound tag used in routing rules and multi-outbound selection.
|
||||
|
||||
With selection = "selector" or "urltest", each outbound keeps its own
|
||||
tag and can be selected directly. With selection = "first", proxy-suite
|
||||
routes through a single active outbound tagged "proxy", so individual
|
||||
proxy tags are mainly useful for documentation and config structure.
|
||||
'';
|
||||
description = "Outbound tag, for routing rules and selection.";
|
||||
example = "vps-de";
|
||||
};
|
||||
|
||||
urlFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to a file containing the proxy URL.
|
||||
Intended for use with secret managers (sops-nix, agenix, etc.).
|
||||
The file is read at service start time and never lands in the Nix store.
|
||||
url = nullStr "Proxy URL. Ends up in the Nix store; prefer urlFile." "hy2://password@example.com:443?sni=example.com";
|
||||
urlFile = nullStr "Runtime path to the proxy URL." "/run/secrets/my-proxy-url";
|
||||
|
||||
Set exactly one of urlFile, url, or json for each outbound.
|
||||
'';
|
||||
example = "/run/secrets/my-proxy-url";
|
||||
singBoxJson = nullAttrs "Raw sing-box outbound (sing-box backend); tag is overridden." {
|
||||
type = "vless";
|
||||
server = "example.com";
|
||||
server_port = 443;
|
||||
};
|
||||
|
||||
url = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Literal proxy URL. Convenient for non-secret configs, but the URL
|
||||
will end up in the Nix store.
|
||||
xrayJson = nullAttrs "Raw XRay outbound (XRay backend); tag is overridden." {
|
||||
protocol = "vless";
|
||||
settings.address = "example.com";
|
||||
};
|
||||
|
||||
Set exactly one of urlFile, url, or json for each outbound.
|
||||
Prefer urlFile for real credentials.
|
||||
'';
|
||||
example = "hy2://password@example.com:443?sni=example.com";
|
||||
json = mkOption {
|
||||
type = types.nullOr types.attrs;
|
||||
default = null;
|
||||
visible = false;
|
||||
description = "Deprecated alias for singBoxJson.";
|
||||
};
|
||||
|
||||
backend = mkOption {
|
||||
@@ -98,70 +66,13 @@ let
|
||||
];
|
||||
default = "auto";
|
||||
description = ''
|
||||
Backend preference for this outbound when both SingBox and XRay are
|
||||
enabled. "auto" uses SingBox when the URL or JSON can be represented
|
||||
there and falls back to XRay for XRay-only transports such as XHTTP
|
||||
or ECH. Ignored by single-backend configurations.
|
||||
Backend for this outbound when both run. "auto" prefers sing-box and falls back to XRay
|
||||
for XRay-only transports (XHTTP, ECH).
|
||||
'';
|
||||
example = "xray";
|
||||
};
|
||||
|
||||
singBoxJson = mkOption {
|
||||
type = types.nullOr types.attrs;
|
||||
default = null;
|
||||
description = ''
|
||||
Raw sing-box outbound configuration as a Nix attribute set.
|
||||
Embedded directly into the config at build time. The tag field
|
||||
is overridden by the outbound's tag option.
|
||||
|
||||
Set exactly one of urlFile, url, singBoxJson, xrayJson, or json for
|
||||
each outbound.
|
||||
Use this when the proxy definition is easier to generate as native Nix
|
||||
than as a single URL string. Only valid with the SingBox backend.
|
||||
'';
|
||||
example = {
|
||||
type = "vless";
|
||||
server = "example.com";
|
||||
server_port = 443;
|
||||
uuid = "...";
|
||||
};
|
||||
};
|
||||
|
||||
xrayJson = mkOption {
|
||||
type = types.nullOr types.attrs;
|
||||
default = null;
|
||||
description = ''
|
||||
Raw XRay outbound configuration as a Nix attribute set.
|
||||
Embedded directly into the config at build time. The tag field is
|
||||
overridden by the outbound's tag option.
|
||||
|
||||
Set exactly one of urlFile, url, singBoxJson, xrayJson, or json for
|
||||
each outbound. Only valid with the XRay backend.
|
||||
'';
|
||||
example = {
|
||||
protocol = "vless";
|
||||
settings = {
|
||||
address = "example.com";
|
||||
port = 443;
|
||||
id = "...";
|
||||
encryption = "none";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
json = mkOption {
|
||||
type = types.nullOr types.attrs;
|
||||
default = null;
|
||||
visible = false;
|
||||
description = ''
|
||||
Deprecated alias for singBoxJson. Use singBoxJson instead.
|
||||
'';
|
||||
};
|
||||
|
||||
# Shorthand for attaching routing rules directly to an outbound definition.
|
||||
# Traffic matching these patterns is sent to this specific outbound.
|
||||
# Only meaningful when selection = "selector" or "urltest" (with "first",
|
||||
# all proxy traffic goes to the single "proxy" outbound anyway).
|
||||
# Destinations sent to this outbound (selection "selector" or "urltest").
|
||||
routing = routingFields;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,432 +0,0 @@
|
||||
# Server-side inbound listener option type definitions.
|
||||
{ lib }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
|
||||
userType = types.submodule {
|
||||
options = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = ''
|
||||
Optional label for this account. Used as the share-link fragment so
|
||||
clients show a readable server name, and as the XRay user email.
|
||||
'';
|
||||
example = "phone";
|
||||
};
|
||||
|
||||
uuid = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Literal UUID for vless/vmess accounts.
|
||||
|
||||
This value is embedded in the Nix store. Prefer uuidFile for real
|
||||
credentials.
|
||||
|
||||
Set exactly one of uuid or uuidFile for vless and vmess listeners.
|
||||
'';
|
||||
example = "b831381d-6324-4d53-ad4f-8cda48b30811";
|
||||
};
|
||||
|
||||
uuidFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to a file containing the account UUID.
|
||||
Intended for use with secret managers (sops-nix, agenix, etc.).
|
||||
The file is read at service start time and never lands in the Nix store.
|
||||
'';
|
||||
example = "/run/secrets/proxy-inbound-uuid";
|
||||
};
|
||||
|
||||
password = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Literal password for trojan, shadowsocks, socks, and http listeners.
|
||||
|
||||
This value is embedded in the Nix store. Prefer passwordFile for real
|
||||
credentials.
|
||||
'';
|
||||
example = "hunter2";
|
||||
};
|
||||
|
||||
passwordFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to a file containing the account password.
|
||||
The file is read at service start time and never lands in the Nix store.
|
||||
'';
|
||||
example = "/run/secrets/proxy-inbound-password";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
transportType = types.submodule {
|
||||
options = {
|
||||
type = mkOption {
|
||||
type = types.enum [
|
||||
"raw"
|
||||
"ws"
|
||||
"grpc"
|
||||
"httpupgrade"
|
||||
"xhttp"
|
||||
];
|
||||
default = "raw";
|
||||
description = ''
|
||||
Stream transport for this listener. "raw" is plain TCP and is what
|
||||
REALITY setups normally use.
|
||||
'';
|
||||
example = "ws";
|
||||
};
|
||||
|
||||
path = mkOption {
|
||||
type = types.str;
|
||||
default = "/";
|
||||
description = ''
|
||||
Request path for the "ws", "httpupgrade", and "xhttp" transports.
|
||||
Ignored by the other transports.
|
||||
'';
|
||||
example = "/download";
|
||||
};
|
||||
|
||||
host = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Expected Host header for the "ws", "httpupgrade", and "xhttp"
|
||||
transports. Leave null to accept any host.
|
||||
'';
|
||||
example = "cdn.example.com";
|
||||
};
|
||||
|
||||
mode = mkOption {
|
||||
type = types.nullOr (
|
||||
types.enum [
|
||||
"auto"
|
||||
"packet-up"
|
||||
"stream-up"
|
||||
"stream-one"
|
||||
]
|
||||
);
|
||||
default = null;
|
||||
description = ''
|
||||
Transfer mode for the "xhttp" transport. Ignored by the others.
|
||||
|
||||
Leave null for XRay's own default, which lets the client choose.
|
||||
Behind an HTTP/1.1 reverse proxy, "packet-up" is the mode that works:
|
||||
"stream-one" needs a full-duplex HTTP/2 path from the client all the
|
||||
way to the listener, which a proxy speaking HTTP/1.1 upstream cannot
|
||||
provide.
|
||||
'';
|
||||
example = "packet-up";
|
||||
};
|
||||
|
||||
serviceName = mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = ''
|
||||
gRPC service name for the "grpc" transport. Ignored otherwise.
|
||||
'';
|
||||
example = "GunService";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
tlsType = types.submodule {
|
||||
options = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Terminate TLS on this listener. Mutually exclusive with reality.
|
||||
|
||||
Always on for trojan listeners regardless of this setting.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
certificateFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to the PEM certificate chain. Compose with
|
||||
security.acme to keep it renewed.
|
||||
'';
|
||||
example = "/var/lib/acme/example.com/fullchain.pem";
|
||||
};
|
||||
|
||||
keyFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to the PEM private key matching certificateFile.
|
||||
'';
|
||||
example = "/var/lib/acme/example.com/key.pem";
|
||||
};
|
||||
|
||||
serverName = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
SNI advertised in generated share links. Defaults to
|
||||
proxyInbounds.serverAddress when unset.
|
||||
'';
|
||||
example = "example.com";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
realityType = types.submodule {
|
||||
options = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Enable REALITY on this listener. Mutually exclusive with tls.enable.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
dest = mkOption {
|
||||
type = types.str;
|
||||
default = "www.microsoft.com:443";
|
||||
description = ''
|
||||
Real TLS server that unauthenticated probes are proxied to. Must be a
|
||||
host:port that serves TLS 1.3 with HTTP/2.
|
||||
'';
|
||||
example = "www.microsoft.com:443";
|
||||
};
|
||||
|
||||
serverNames = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
SNI values accepted by this listener. These must be names the dest
|
||||
server actually serves. The first entry is used in share links.
|
||||
'';
|
||||
example = [ "www.microsoft.com" ];
|
||||
};
|
||||
|
||||
privateKeyFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to the REALITY x25519 private key, as produced by
|
||||
`xray x25519`. Read at service start time; never lands in the Nix
|
||||
store.
|
||||
'';
|
||||
example = "/run/secrets/proxy-inbound-reality-key";
|
||||
};
|
||||
|
||||
privateKey = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Literal REALITY x25519 private key.
|
||||
|
||||
This value is embedded in the Nix store. Prefer privateKeyFile.
|
||||
'';
|
||||
example = "gG1Yz...";
|
||||
};
|
||||
|
||||
publicKey = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
REALITY x25519 public key matching privateKeyFile, as printed
|
||||
alongside it by `xray x25519`. Not a secret: clients need it, and it
|
||||
is what generated share links carry as `pbk`.
|
||||
|
||||
Required when proxyInbounds.shareLinks is enabled.
|
||||
'';
|
||||
example = "jNXH...";
|
||||
};
|
||||
|
||||
shortIds = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ "" ];
|
||||
description = ''
|
||||
Accepted REALITY short IDs (hex, up to 16 characters). The default
|
||||
accepts the empty short ID. The first entry is used in share links.
|
||||
'';
|
||||
example = [ "0123abcd" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
inboundType = types.submodule {
|
||||
options = {
|
||||
type = mkOption {
|
||||
type = types.nullOr (types.enum [
|
||||
"vless"
|
||||
"vmess"
|
||||
"trojan"
|
||||
"shadowsocks"
|
||||
"socks"
|
||||
"http"
|
||||
]);
|
||||
default = null;
|
||||
description = ''
|
||||
Proxy protocol served by this listener.
|
||||
|
||||
Set exactly one of type, xrayJson, or jsonFile for each listener.
|
||||
'';
|
||||
example = "vless";
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 443;
|
||||
description = ''
|
||||
Port this listener binds. Opened in the firewall automatically unless
|
||||
proxyInbounds.openFirewall is disabled.
|
||||
'';
|
||||
example = 443;
|
||||
};
|
||||
|
||||
sharePort = mkOption {
|
||||
type = types.nullOr types.port;
|
||||
default = null;
|
||||
description = ''
|
||||
Port generated share links advertise, for when clients do not reach
|
||||
this listener on the port it binds. Set it when something in front of
|
||||
it owns the public port: an nginx vhost proxying to a loopback bind,
|
||||
a container port mapping, a DNAT rule.
|
||||
|
||||
Leave null to advertise port.
|
||||
'';
|
||||
example = 443;
|
||||
};
|
||||
|
||||
listenAddress = mkOption {
|
||||
type = types.strMatching "[^[:space:]]+";
|
||||
default = "::";
|
||||
description = ''
|
||||
Address this listener binds. The default accepts both IPv4 and IPv6
|
||||
connections from anywhere.
|
||||
'';
|
||||
example = "0.0.0.0";
|
||||
};
|
||||
|
||||
via = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Egress for traffic arriving on this listener: "proxy" (out through
|
||||
the local proxy stack, following its current selection), a
|
||||
proxy.outbounds tag (pinned to that specific server), "direct" (out
|
||||
from this machine), or "block".
|
||||
|
||||
Give two listeners two different tags to have them leave through two
|
||||
different servers.
|
||||
|
||||
Leave null to inherit proxyInbounds.via.
|
||||
'';
|
||||
example = "nl-vps";
|
||||
};
|
||||
|
||||
users = mkOption {
|
||||
type = types.listOf userType;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Accounts accepted by this listener. vless and vmess use uuid/uuidFile;
|
||||
trojan, shadowsocks, socks, and http use password/passwordFile.
|
||||
|
||||
A share link is generated for the first user of each listener.
|
||||
'';
|
||||
example = [ { uuidFile = "/run/secrets/proxy-inbound-uuid"; } ];
|
||||
};
|
||||
|
||||
flow = mkOption {
|
||||
type = types.nullOr (types.enum [ "xtls-rprx-vision" ]);
|
||||
default = null;
|
||||
description = ''
|
||||
VLESS flow control. "xtls-rprx-vision" is the usual pairing with
|
||||
REALITY on the "raw" transport; it is not valid over ws, grpc,
|
||||
httpupgrade, or xhttp.
|
||||
'';
|
||||
example = "xtls-rprx-vision";
|
||||
};
|
||||
|
||||
method = mkOption {
|
||||
type = types.str;
|
||||
default = "2022-blake3-aes-128-gcm";
|
||||
description = ''
|
||||
Shadowsocks cipher. Ignored by other protocols.
|
||||
|
||||
The 2022 ciphers require a base64 pre-shared key of the matching
|
||||
length as the password, not a passphrase.
|
||||
'';
|
||||
example = "aes-128-gcm";
|
||||
};
|
||||
|
||||
transport = mkOption {
|
||||
type = transportType;
|
||||
default = { };
|
||||
description = ''
|
||||
Stream transport settings for this listener.
|
||||
'';
|
||||
};
|
||||
|
||||
tls = mkOption {
|
||||
type = tlsType;
|
||||
default = { };
|
||||
description = ''
|
||||
TLS termination settings for this listener. Mutually exclusive with
|
||||
reality.
|
||||
'';
|
||||
};
|
||||
|
||||
reality = mkOption {
|
||||
type = realityType;
|
||||
default = { };
|
||||
description = ''
|
||||
REALITY settings for this listener. Mutually exclusive with tls.
|
||||
'';
|
||||
};
|
||||
|
||||
xrayJson = mkOption {
|
||||
type = types.nullOr types.attrs;
|
||||
default = null;
|
||||
description = ''
|
||||
Raw XRay inbound configuration as a Nix attribute set, for protocols
|
||||
or options the typed fields do not cover. Embedded into the config at
|
||||
build time, so avoid putting credentials here; use jsonFile instead.
|
||||
The tag field is overridden by the listener name.
|
||||
|
||||
Set exactly one of type, xrayJson, or jsonFile for each listener.
|
||||
'';
|
||||
example = {
|
||||
protocol = "dokodemo-door";
|
||||
settings = {
|
||||
address = "127.0.0.1";
|
||||
port = 8080;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
jsonFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Runtime path to a file containing a complete XRay inbound object as
|
||||
JSON. Read at service start time, so the whole inbound including its
|
||||
credentials can be rendered by a secret manager and never lands in
|
||||
the Nix store. The tag field is overridden by the listener name.
|
||||
|
||||
No share link is generated for listeners defined this way.
|
||||
|
||||
Set exactly one of type, xrayJson, or jsonFile for each listener.
|
||||
'';
|
||||
example = "/run/secrets/proxy-inbound-vless.json";
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit inboundType;
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
# zapret hostlist and preset option type definitions.
|
||||
{ lib }:
|
||||
|
||||
let
|
||||
@@ -22,55 +21,29 @@ let
|
||||
"twitter"
|
||||
];
|
||||
|
||||
zapretDefaultIpType = types.enum [
|
||||
"all"
|
||||
];
|
||||
zapretDefaultIpType = types.enum [ "all" ];
|
||||
|
||||
zapretHostlistRuleType = types.submodule {
|
||||
options = {
|
||||
name = mkOption {
|
||||
type = types.strMatching "^[a-z0-9][a-z0-9-]*$";
|
||||
description = ''
|
||||
Custom hostlist name. Used to generate hostlists/list-<name>.txt
|
||||
inside the derived zapret config directory.
|
||||
'';
|
||||
description = "Hostlist name (hostlists/list-<name>.txt).";
|
||||
example = "cloudflare";
|
||||
};
|
||||
|
||||
domains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Domains written into the generated custom zapret hostlist file.
|
||||
Can be combined with defaultDomains.
|
||||
'';
|
||||
example = [
|
||||
"example.com"
|
||||
"example.de"
|
||||
];
|
||||
description = "Domains in this hostlist.";
|
||||
example = [ "example.com" ];
|
||||
};
|
||||
|
||||
defaultDomains = mkOption {
|
||||
type = types.listOf zapretDefaultDomainType;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Built-in domain groups copied from zapret-discord-youtube hostlists.
|
||||
These are expanded and combined with domains.
|
||||
|
||||
Each value maps directly to the same-named upstream file:
|
||||
"general" uses list-general.txt, "google" uses list-google.txt,
|
||||
and the remaining values use their corresponding list-<name>.txt.
|
||||
|
||||
"discord" is an alias for "general"; "youtube" is an alias for
|
||||
"google".
|
||||
|
||||
When "general" or "discord" is used together with configName, the
|
||||
module also clones the selected config's Discord UDP voice rule
|
||||
(--filter-l7=discord,stun).
|
||||
|
||||
When preset is unset, use one defaultDomains entry per rule so the
|
||||
module can infer a single rule family. Split groups into separate
|
||||
rules when they need different strategies.
|
||||
Upstream lists to include ("discord" = "general", "youtube" = "google"). Without preset,
|
||||
use one per rule so the strategy family can be inferred.
|
||||
'';
|
||||
example = [ "google" ];
|
||||
};
|
||||
@@ -78,86 +51,46 @@ let
|
||||
ips = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
IPs or CIDRs written into the generated custom zapret ipset file.
|
||||
Can be combined with defaultIps.
|
||||
'';
|
||||
example = [
|
||||
"203.0.113.0/24"
|
||||
"2001:db8::/32"
|
||||
];
|
||||
description = "IPs/CIDRs in this rule's ipset.";
|
||||
example = [ "203.0.113.0/24" ];
|
||||
};
|
||||
|
||||
defaultIps = mkOption {
|
||||
type = types.listOf zapretDefaultIpType;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Built-in IP/CIDR groups copied from zapret-discord-youtube ipsets.
|
||||
|
||||
"all" uses the upstream ipset-all.txt list. The upstream bundle does
|
||||
not split this list by service, so site-specific defaults remain in
|
||||
defaultDomains.
|
||||
'';
|
||||
description = ''Upstream ipsets to include ("all" is ipset-all.txt).'';
|
||||
example = [ "all" ];
|
||||
};
|
||||
|
||||
preset = mkOption {
|
||||
type = types.nullOr zapretPresetType;
|
||||
default = null;
|
||||
description = ''
|
||||
Clone this built-in NFQWS rule family for this hostlist. When
|
||||
configName is set, the family is cloned from that zapret config;
|
||||
otherwise it is cloned from the active global zapret config.
|
||||
|
||||
When unset and defaultDomains is non-empty, rule families are
|
||||
inferred from defaultDomains.
|
||||
'';
|
||||
description = "Strategy family to clone, from configName or the active config.";
|
||||
example = "google";
|
||||
};
|
||||
|
||||
configName = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
zapret config name to clone NFQWS rules from for this hostlist.
|
||||
Names use the same matching rules as services.proxy-suite.zapret.configName.
|
||||
|
||||
This is a higher-level alternative to nfqwsArgs and cannot be used
|
||||
together with nfqwsArgs.
|
||||
'';
|
||||
description = "Config to clone strategies from. Exclusive with nfqwsArgs.";
|
||||
example = "general(ALT9)";
|
||||
};
|
||||
|
||||
nfqwsArgs = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Additional NFQWS argument fragments for this hostlist.
|
||||
The module injects --hostlist=... and trailing --new automatically.
|
||||
|
||||
This cannot be used together with configName.
|
||||
'';
|
||||
example = [
|
||||
"--filter-tcp=443 --dpi-desync=fake,multisplit"
|
||||
];
|
||||
description = "Raw NFQWS arguments; --hostlist and --new are added. Exclusive with configName.";
|
||||
example = [ "--filter-tcp=443 --dpi-desync=fake,multisplit" ];
|
||||
};
|
||||
|
||||
enableDirectSync = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether this custom hostlist should also be mirrored into proxy
|
||||
direct domain routing when zapret.syncDirectRouting = true.
|
||||
'';
|
||||
description = "Include these domains in zapret.directSync.";
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit
|
||||
zapretDefaultDomainType
|
||||
zapretDefaultIpType
|
||||
zapretPresetType
|
||||
zapretHostlistRuleType
|
||||
;
|
||||
inherit zapretHostlistRuleType;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.userControl = {
|
||||
group = mkOption {
|
||||
type = types.strMatching "^[a-z_][a-z0-9_-]*$";
|
||||
default = "proxy-suite";
|
||||
description = "Group whose members may run privileged `proxy-ctl` commands without a password.";
|
||||
};
|
||||
|
||||
allow = mkOption {
|
||||
type = types.listOf (
|
||||
types.enum [
|
||||
"global"
|
||||
"perApp"
|
||||
]
|
||||
);
|
||||
default = [
|
||||
"global"
|
||||
"perApp"
|
||||
];
|
||||
description = ''
|
||||
What userControl.group may control without a password:
|
||||
- "global": the global units (proxy, tun, tproxy, zapret, restart, subs update).
|
||||
- "perApp": the per-app backend units used by `proxy-ctl apps run`.
|
||||
Empty grants no passwordless control.
|
||||
'';
|
||||
example = [ "global" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,202 +1,98 @@
|
||||
# zapret DPI bypass options.
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption mkEnableOption types;
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
t = import ./types.nix { inherit lib; };
|
||||
list =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
inherit description example;
|
||||
};
|
||||
bool =
|
||||
default: description:
|
||||
mkOption {
|
||||
type = types.bool;
|
||||
inherit default description;
|
||||
};
|
||||
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;
|
||||
description = ''
|
||||
When zapret.enable = true, mirror zapret's upstream domain hostlists
|
||||
into proxy direct domain routing.
|
||||
|
||||
This includes the default zapret domain lists and any custom
|
||||
hostlistRules entries with enableDirectSync = true.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
syncDirectRoutingUpstreamIps = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
When zapret.enable = true, mirror zapret's upstream ipset ranges
|
||||
(such as ipset-all.txt minus exclusions) into proxy direct IP routing.
|
||||
'';
|
||||
example = false;
|
||||
};
|
||||
|
||||
syncDirectRoutingUserIps = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
When zapret.enable = true, mirror user-defined zapret.ipsetAll and
|
||||
zapret.ipsetExclude entries into proxy direct IP routing.
|
||||
'';
|
||||
example = true;
|
||||
};
|
||||
|
||||
configName = mkOption {
|
||||
type = types.str;
|
||||
default = "general(ALT)";
|
||||
description = ''
|
||||
zapret strategy preset name selected from the upstream configs
|
||||
directory. Exact filenames are accepted, and names that differ only by
|
||||
whitespace are treated as aliases.
|
||||
'';
|
||||
example = "general(ALT)";
|
||||
};
|
||||
|
||||
gameFilter = mkOption {
|
||||
type = types.str;
|
||||
default = "null";
|
||||
description = ''zapret game traffic filter mode: "all", "tcp", "udp", or "null" to disable.'';
|
||||
example = "null";
|
||||
};
|
||||
|
||||
listGeneral = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Extra domains to include in zapret's interception list.
|
||||
When syncDirectRouting = true, these domains are also mirrored into
|
||||
proxy direct routing.
|
||||
'';
|
||||
example = [ "youtube.com" ];
|
||||
};
|
||||
|
||||
listExclude = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Domains to exclude from zapret interception.
|
||||
When syncDirectRouting = true, these exclusions also remove matching
|
||||
domains from the zapret-derived proxy direct-routing set.
|
||||
'';
|
||||
example = [ "music.youtube.com" ];
|
||||
};
|
||||
|
||||
ipsetAll = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Extra IPs/CIDRs to add to zapret's ipset.
|
||||
Mirrored into proxy direct IP routing when
|
||||
syncDirectRoutingUserIps = true.
|
||||
'';
|
||||
example = [ "203.0.113.0/24" ];
|
||||
};
|
||||
|
||||
ipsetExclude = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
IPs/CIDRs to exclude from zapret's ipset.
|
||||
Also excluded from zapret-derived proxy direct IP routing when
|
||||
syncDirectRoutingUserIps = true.
|
||||
'';
|
||||
example = [ "203.0.113.10/32" ];
|
||||
};
|
||||
|
||||
includeExtraUpstreamLists = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Automatically activate upstream list-instagram.txt, list-soundcloud.txt,
|
||||
and list-twitter.txt in the generated zapret config when the selected
|
||||
upstream preset does not already reference them.
|
||||
|
||||
When syncDirectRouting = true, domains from these extra lists are also
|
||||
mirrored into proxy direct routing.
|
||||
'';
|
||||
example = false;
|
||||
};
|
||||
|
||||
hostlistRules = mkOption {
|
||||
type = types.listOf t.zapretHostlistRuleType;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Additional named zapret hostlists with per-list DPI mitigation rules.
|
||||
Each entry generates hostlists/list-<name>.txt and can clone a built-in
|
||||
zapret family from the active config, clone it from another configName,
|
||||
add custom NFQWS rule fragments, or combine these pieces.
|
||||
|
||||
defaultDomains selects same-named upstream zapret-discord-youtube
|
||||
hostlists such as "general" and "google", with the aliases "discord"
|
||||
and "youtube" for readability. defaultIps provides upstream IP/CIDR
|
||||
groups such as "all". configName is a higher-level alternative to
|
||||
nfqwsArgs and cannot be used together with nfqwsArgs.
|
||||
'';
|
||||
example = [
|
||||
{
|
||||
name = "youtube-alt9";
|
||||
defaultDomains = [ "youtube" ];
|
||||
configName = "general(ALT9)";
|
||||
}
|
||||
{
|
||||
name = "discord-alt12";
|
||||
defaultDomains = [ "discord" ];
|
||||
configName = "general (ALT12)";
|
||||
}
|
||||
{
|
||||
name = "custom-sites";
|
||||
domains = [
|
||||
"example.com"
|
||||
"example.org"
|
||||
];
|
||||
ips = [ "203.0.113.0/24" ];
|
||||
preset = "general";
|
||||
configName = "general (SIMPLE FAKE)";
|
||||
}
|
||||
engine = mkOption {
|
||||
type = types.enum [
|
||||
"zapret-discord-youtube"
|
||||
"zapret2"
|
||||
];
|
||||
default = "zapret-discord-youtube";
|
||||
description = ''
|
||||
"zapret-discord-youtube": nfqws with curated presets and static hostlists (zapret.zapret-discord-youtube).
|
||||
"zapret2": nfqws2, which learns blocked hosts at runtime (zapret.zapret2).
|
||||
'';
|
||||
example = "zapret2";
|
||||
};
|
||||
|
||||
cidrExemption = {
|
||||
enable = mkEnableOption "CIDR exemption from zapret NFQUEUE";
|
||||
# What zapret feeds back into the client routing table.
|
||||
directSync = {
|
||||
enable = bool true "Add zapret's domain hostlists to proxy.routing.direct.";
|
||||
upstreamIps = bool false "Add zapret's upstream ipsets to proxy.routing.direct.";
|
||||
userIps = bool true "Add zapret-discord-youtube.ips, minus zapret-discord-youtube.excludeIps, to proxy.routing.direct.";
|
||||
};
|
||||
|
||||
cidrs = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
example = [
|
||||
"192.168.123.0/24"
|
||||
"10.0.0.0/8"
|
||||
# Shared by both engines: a netfilter-level bypass, not an engine-specific concept.
|
||||
cidrExemption = {
|
||||
enable = mkEnableOption "exempting subnets from zapret, e.g. NATed VMs whose traffic it would break";
|
||||
cidrs = list "Exempted subnets." [ "192.168.123.0/24" ];
|
||||
};
|
||||
|
||||
zapret-discord-youtube = {
|
||||
configName = mkOption {
|
||||
type = types.str;
|
||||
default = "general(ALT)";
|
||||
description = "Upstream strategy preset. Names that differ only in whitespace match.";
|
||||
example = "general (ALT9)";
|
||||
};
|
||||
|
||||
gameFilter = mkOption {
|
||||
type = types.enum [
|
||||
"all"
|
||||
"tcp"
|
||||
"udp"
|
||||
"null"
|
||||
];
|
||||
default = "null";
|
||||
description = ''Game traffic filter, or "null" for off.'';
|
||||
example = "all";
|
||||
};
|
||||
|
||||
domains = list "Extra domains to bypass." [ "youtube.com" ];
|
||||
excludeDomains = list "Domains never bypassed." [ "music.youtube.com" ];
|
||||
ips = list "Extra IPs/CIDRs to bypass." [ "203.0.113.0/24" ];
|
||||
excludeIps = list "IPs/CIDRs never bypassed." [ "203.0.113.10/32" ];
|
||||
|
||||
includeExtraUpstreamLists = bool false "Also use the upstream instagram, soundcloud and twitter lists.";
|
||||
|
||||
hostlistRules = mkOption {
|
||||
type = types.listOf t.zapretHostlistRuleType;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Subnets to exempt from zapret's NFQUEUE mangle rules.
|
||||
Useful when a VM (libvirt, etc.) is behind NAT and zapret
|
||||
would corrupt its traffic through the host's nftables.
|
||||
Extra named hostlists, each with its own strategy: cloned from a preset or configName,
|
||||
or given as nfqwsArgs.
|
||||
'';
|
||||
example = [
|
||||
{
|
||||
name = "youtube-alt9";
|
||||
defaultDomains = [ "youtube" ];
|
||||
configName = "general(ALT9)";
|
||||
}
|
||||
{
|
||||
name = "custom-sites";
|
||||
domains = [ "example.com" ];
|
||||
preset = "general";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
int =
|
||||
default: description:
|
||||
mkOption {
|
||||
type = types.ints.positive;
|
||||
inherit default description;
|
||||
};
|
||||
|
||||
# Ported from nfqws2-keenetic. `circular` rotates strategy=1/2/3 per
|
||||
# second-level domain whenever the failure detector fires.
|
||||
defaultProfiles = [
|
||||
''
|
||||
--filter-tcp=443,80,1984,5222 --filter-l7=http,tls,mtproto <HOSTLIST>
|
||||
--payload=tls_client_hello,mtproto_initial
|
||||
--lua-desync=circular:fails=2:time=300:retrans=3:nld=2
|
||||
--lua-desync=fake:blob=tls_clienthello:tls_mod=rnd,dupsid,sni=fonts.google.com:tcp_seq=10000:strategy=1
|
||||
--lua-desync=multisplit:pos=1,midsld:seqovl=1:seqovl_pattern=tls_clienthello:tcp_ts_up:strategy=1
|
||||
--lua-desync=fake:blob=0x00000000:tcp_ack=-66000:tls_mod=rnd,dupsid,sni=www.google.com:repeats=2:strategy=2
|
||||
--lua-desync=multisplit:pos=1,midsld:strategy=2
|
||||
--lua-desync=hostfakesplit:host=ozon.ru:midhost=host-2:seqovl=sniext+3:seqovl_pattern=tls_clienthello:badsum:tcp_md5:tcp_ts_up:strategy=3
|
||||
--lua-desync=hostfakesplit:tcp_md5:tcp_ts_up:strategy=3
|
||||
--payload=http_req
|
||||
--lua-desync=http_methodeol:badsum
|
||||
''
|
||||
# QUIC reads the learned list but never adds to it: browsers retry over TCP.
|
||||
''
|
||||
--filter-udp=443 --filter-l7=quic <HOSTLIST_NOAUTO>
|
||||
--payload=quic_initial
|
||||
--lua-desync=fake:blob=quic_initial:repeats=11
|
||||
''
|
||||
# No hostlist: these protocols carry no SNI.
|
||||
''
|
||||
--filter-udp=590-600,1400,3478-3481,5349,19294-19344,49152-65535
|
||||
--filter-l7=wireguard,stun,discord,mtproto,unknown
|
||||
--out-range=<n2
|
||||
--payload=wireguard_initiation,wireguard_response,wireguard_cookie,stun,discord_ip_discovery,mtproto_initial,unknown
|
||||
--lua-desync=circular:fails=2:time=300:retrans=3:nld=2
|
||||
--lua-desync=fake:repeats=6:strategy=1
|
||||
--lua-desync=fake:blob=quic_initial:repeats=6:strategy=2
|
||||
''
|
||||
];
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.zapret.zapret2 = {
|
||||
profiles = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = defaultProfiles;
|
||||
description = ''
|
||||
nfqws2 profiles, joined with --new; first match wins. <HOSTLIST> expands to the hostlist
|
||||
arguments, <HOSTLIST_NOAUTO> to the same without learning. --qnum, --fwmark and --lua-init
|
||||
are added automatically.
|
||||
'';
|
||||
example = [
|
||||
"--filter-tcp=443 --filter-l7=tls <HOSTLIST> --payload=tls_client_hello --lua-desync=multisplit:pos=1,midsld"
|
||||
];
|
||||
};
|
||||
|
||||
blobs = mkOption {
|
||||
type = types.attrsOf types.str;
|
||||
default = {
|
||||
tls_clienthello = "tls_clienthello_www_google_com.bin";
|
||||
quic_initial = "quic_initial_www_google_com.bin";
|
||||
};
|
||||
description = "Fake payloads by name (blob=<name>): a file in zapret2's files/fake, or an absolute path.";
|
||||
example = {
|
||||
tls_clienthello = "/etc/proxy-suite/my_clienthello.bin";
|
||||
};
|
||||
};
|
||||
|
||||
domains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "Domains always treated as blocked. At runtime: `proxy-ctl zapret auto add`.";
|
||||
example = [ "rutracker.org" ];
|
||||
};
|
||||
|
||||
excludeDomains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "Domains never touched or learned. At runtime: `proxy-ctl zapret auto exclude`.";
|
||||
example = [ "bank.example.com" ];
|
||||
};
|
||||
|
||||
ports = {
|
||||
tcp = mkOption {
|
||||
type = types.str;
|
||||
default = "80,443,1984,2053,2083,2087,2096,5222,8443";
|
||||
description = "TCP ports sent to NFQUEUE. Must cover every port a profile filters on.";
|
||||
};
|
||||
|
||||
udp = mkOption {
|
||||
type = types.str;
|
||||
default = "443,590-600,1400,3478-3481,5349,19294-19344,49152-65535";
|
||||
description = "UDP ports sent to NFQUEUE. Must cover every port a profile filters on.";
|
||||
};
|
||||
};
|
||||
|
||||
ipv6 = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Intercept IPv6 as well as IPv4.";
|
||||
};
|
||||
|
||||
autoHostlist = {
|
||||
enable = mkEnableOption "learning blocked hosts at runtime" // {
|
||||
default = true;
|
||||
description = ''
|
||||
Learn blocked hosts: after failThreshold failures (retransmissions, early RST, DPI
|
||||
redirect, one-sided UDP) a host joins /var/lib/proxy-suite/zapret2/zapret-hosts-auto.txt.
|
||||
Off, only zapret2.domains and `proxy-ctl zapret auto add` are acted on.
|
||||
'';
|
||||
};
|
||||
|
||||
failThreshold = int 3 "Failures before a host is learned.";
|
||||
failTime = int 300 "Seconds allowed between two failures before the count resets.";
|
||||
retransThreshold = int 3 "Retransmissions of the first request that count as one failure.";
|
||||
|
||||
retransReset = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "RST a stalled client once retransThreshold is hit, so failures are counted fast.";
|
||||
};
|
||||
|
||||
retransMaxseq = int 32768 "Outgoing sequence number past which failure detection stops.";
|
||||
incomingMaxseq = int 4096 "Incoming sequence number past which an RST or redirect is not a failure.";
|
||||
udpOut = int 4 "Outgoing UDP packets before a one-sided exchange counts as a failure.";
|
||||
udpIn = int 1 "Incoming UDP packets at or below which an exchange is one-sided.";
|
||||
|
||||
debugLog = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Log why hosts are or are not learned to zapret-hosts-auto-debug.log.";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user