refactor: overhaul of options and features

Includes, but not limited to:
- zapret2 support
- declarative inbounds
- proxy-ctl revamp
- automatic proxy learning
This commit is contained in:
FUFSoB committed 2026-09-13 22:37:45 +05:00
1 parent b892384527
commit fdb2b08790
144 files changed
+13198 -14066

No files matched your search

+85 -179
View File
@@ -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;
};
};
}