chore: refactoring (split)
This commit is contained in:
84 files changed
+9149
-7244
No files matched your search
@@ -1,13 +1,12 @@
|
||||
# Top-level, userControl, tray, and tgWsProxy options.
|
||||
# Miscellaneous top-level proxy-suite options.
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption mkEnableOption types;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite = {
|
||||
enable = mkEnableOption "proxy suite (proxy backend + zapret + tg-ws-proxy)";
|
||||
|
||||
tgWsProxyOptions = import ./other/tg-ws-proxy.nix { inherit lib; };
|
||||
|
||||
userControlOptions = {
|
||||
userControl = {
|
||||
group = mkOption {
|
||||
type = types.strMatching "^[a-z_][a-z0-9_-]*$";
|
||||
@@ -40,7 +39,9 @@ in
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
trayOptions = {
|
||||
tray = {
|
||||
enable = mkEnableOption "system tray indicator for proxy-suite";
|
||||
|
||||
@@ -65,210 +66,13 @@ in
|
||||
example = true;
|
||||
};
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite = {
|
||||
enable = lib.mkEnableOption "proxy suite (proxy backend + zapret + tg-ws-proxy)";
|
||||
}
|
||||
// userControlOptions
|
||||
// trayOptions
|
||||
// tgWsProxyOptions;
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
# 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;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
|
||||
# Shared routing-rule fields (reused in both outboundType.routing and routing.rules entries)
|
||||
# Reused in both outboundType.routing and routing.rules entries.
|
||||
routingFields = {
|
||||
domains = mkOption {
|
||||
type = types.listOf types.str;
|
||||
@@ -53,7 +53,6 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
# An explicit routing rule – associates traffic patterns with a named outbound.
|
||||
routingRuleType = types.submodule {
|
||||
options = {
|
||||
outbound = mkOption {
|
||||
@@ -73,167 +72,12 @@ let
|
||||
// routingFields;
|
||||
};
|
||||
|
||||
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.
|
||||
'';
|
||||
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";
|
||||
};
|
||||
};
|
||||
outboundTypes = import ./types/outbounds.nix {
|
||||
inherit lib;
|
||||
inherit routingFields;
|
||||
};
|
||||
|
||||
outboundType = types.submodule {
|
||||
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.
|
||||
'';
|
||||
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.
|
||||
|
||||
Set exactly one of urlFile, url, or json for each outbound.
|
||||
'';
|
||||
example = "/run/secrets/my-proxy-url";
|
||||
};
|
||||
|
||||
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.
|
||||
|
||||
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";
|
||||
};
|
||||
|
||||
backend = mkOption {
|
||||
type = types.enum [
|
||||
"auto"
|
||||
"sing-box"
|
||||
"xray"
|
||||
];
|
||||
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.
|
||||
'';
|
||||
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).
|
||||
routing = routingFields;
|
||||
};
|
||||
};
|
||||
zapretTypes = import ./types/zapret.nix { inherit lib; };
|
||||
|
||||
dnsUpstreamType = types.submodule {
|
||||
options = {
|
||||
@@ -269,155 +113,6 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
zapretPresetType = types.enum [
|
||||
"general"
|
||||
"google"
|
||||
"instagram"
|
||||
"soundcloud"
|
||||
"twitter"
|
||||
];
|
||||
|
||||
zapretDefaultDomainType = types.enum [
|
||||
"general"
|
||||
"google"
|
||||
"discord"
|
||||
"youtube"
|
||||
"instagram"
|
||||
"soundcloud"
|
||||
"twitter"
|
||||
];
|
||||
|
||||
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.
|
||||
'';
|
||||
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"
|
||||
];
|
||||
};
|
||||
|
||||
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.
|
||||
'';
|
||||
example = [ "google" ];
|
||||
};
|
||||
|
||||
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"
|
||||
];
|
||||
};
|
||||
|
||||
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.
|
||||
'';
|
||||
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.
|
||||
'';
|
||||
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.
|
||||
'';
|
||||
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"
|
||||
];
|
||||
};
|
||||
|
||||
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.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
perAppRoutingProfileType = types.submodule {
|
||||
options = {
|
||||
name = mkOption {
|
||||
@@ -459,19 +154,14 @@ let
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
in
|
||||
{
|
||||
inherit
|
||||
dnsUpstreamType
|
||||
perAppRoutingProfileType
|
||||
routingFields
|
||||
routingRuleType
|
||||
subscriptionType
|
||||
outboundType
|
||||
dnsUpstreamType
|
||||
zapretDefaultDomainType
|
||||
zapretDefaultIpType
|
||||
zapretPresetType
|
||||
zapretHostlistRuleType
|
||||
perAppRoutingProfileType
|
||||
;
|
||||
}
|
||||
// outboundTypes
|
||||
// zapretTypes
|
||||
@@ -0,0 +1,171 @@
|
||||
# Subscription and outbound option type definitions.
|
||||
{ lib, routingFields }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
|
||||
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.
|
||||
'';
|
||||
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";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
outboundType = types.submodule {
|
||||
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.
|
||||
'';
|
||||
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.
|
||||
|
||||
Set exactly one of urlFile, url, or json for each outbound.
|
||||
'';
|
||||
example = "/run/secrets/my-proxy-url";
|
||||
};
|
||||
|
||||
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.
|
||||
|
||||
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";
|
||||
};
|
||||
|
||||
backend = mkOption {
|
||||
type = types.enum [
|
||||
"auto"
|
||||
"sing-box"
|
||||
"xray"
|
||||
];
|
||||
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.
|
||||
'';
|
||||
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).
|
||||
routing = routingFields;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit subscriptionType outboundType;
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
# zapret hostlist and preset option type definitions.
|
||||
{ lib }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
|
||||
zapretPresetType = types.enum [
|
||||
"general"
|
||||
"google"
|
||||
"instagram"
|
||||
"soundcloud"
|
||||
"twitter"
|
||||
];
|
||||
|
||||
zapretDefaultDomainType = types.enum [
|
||||
"general"
|
||||
"google"
|
||||
"discord"
|
||||
"youtube"
|
||||
"instagram"
|
||||
"soundcloud"
|
||||
"twitter"
|
||||
];
|
||||
|
||||
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.
|
||||
'';
|
||||
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"
|
||||
];
|
||||
};
|
||||
|
||||
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.
|
||||
'';
|
||||
example = [ "google" ];
|
||||
};
|
||||
|
||||
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"
|
||||
];
|
||||
};
|
||||
|
||||
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.
|
||||
'';
|
||||
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.
|
||||
'';
|
||||
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.
|
||||
'';
|
||||
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"
|
||||
];
|
||||
};
|
||||
|
||||
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.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit
|
||||
zapretDefaultDomainType
|
||||
zapretDefaultIpType
|
||||
zapretPresetType
|
||||
zapretHostlistRuleType
|
||||
;
|
||||
}
|
||||
Reference in new issue
Block a user