feat(wip): amnezia-wg 3.1 support
This commit is contained in:
29 files changed
+4092
-12
No files matched your search
@@ -0,0 +1,345 @@
|
||||
# Native AmneziaWG client profile services.
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
cfg,
|
||||
}:
|
||||
|
||||
let
|
||||
awgCfg = cfg.amneziaWg;
|
||||
profiles = awgCfg.profiles;
|
||||
profileNames = builtins.attrNames profiles;
|
||||
serviceName = name: "proxy-suite-awg-${name}";
|
||||
serviceNames = map serviceName profileNames;
|
||||
allProfileConflicts =
|
||||
name:
|
||||
map (other: "${serviceName other}.service") (builtins.filter (other: other != name) profileNames);
|
||||
sourceCount =
|
||||
profile:
|
||||
builtins.length (
|
||||
builtins.filter (value: value != null) [
|
||||
profile.configFile
|
||||
profile.vpnFile
|
||||
profile.vpn
|
||||
profile.settings
|
||||
]
|
||||
);
|
||||
inlineVpnFile = name: profile: pkgs.writeText "proxy-suite-awg-${name}.vpn" profile.vpn;
|
||||
sourceKind =
|
||||
profile:
|
||||
if profile.configFile != null then
|
||||
"configFile"
|
||||
else if profile.vpnFile != null then
|
||||
"vpnFile"
|
||||
else if profile.vpn != null then
|
||||
"vpn"
|
||||
else
|
||||
"settings";
|
||||
sourcePath =
|
||||
name: profile:
|
||||
if profile.configFile != null then
|
||||
profile.configFile
|
||||
else if profile.vpnFile != null then
|
||||
profile.vpnFile
|
||||
else if profile.vpn != null then
|
||||
inlineVpnFile name profile
|
||||
else
|
||||
null;
|
||||
manifestFor =
|
||||
name: profile:
|
||||
pkgs.writeText "proxy-suite-awg-${name}-manifest.json" (
|
||||
builtins.toJSON (
|
||||
{
|
||||
kind = sourceKind profile;
|
||||
allowConfigHooks = profile.allowConfigHooks;
|
||||
vpnContainer = profile.vpnContainer;
|
||||
}
|
||||
// lib.optionalAttrs (sourcePath name profile != null) { path = sourcePath name profile; }
|
||||
// lib.optionalAttrs (profile.settings != null) { settings = profile.settings; }
|
||||
)
|
||||
);
|
||||
configTool = ../../scripts/amneziawg_config.py;
|
||||
runtimeDir = name: "/run/${serviceName name}";
|
||||
runtimeConfig = name: profile: "${runtimeDir name}/${profile.interfaceName}.conf";
|
||||
# Keep proxy backend sockets (which already carry proxyMark) out of AWG's
|
||||
# default-route policy table. This priority sits ahead of the global TUN
|
||||
# rules while leaving the per-app rules at 8996/8997 untouched.
|
||||
proxyBypassRulePriority = 8998;
|
||||
|
||||
mkService =
|
||||
name: profile:
|
||||
let
|
||||
manifest = manifestFor name profile;
|
||||
configPath = runtimeConfig name profile;
|
||||
prepare = pkgs.writeShellScript "proxy-suite-awg-${name}-prepare" ''
|
||||
set -euo pipefail
|
||||
${pkgs.python3}/bin/python3 ${configTool} \
|
||||
--manifest ${lib.escapeShellArg (toString manifest)} \
|
||||
--output ${lib.escapeShellArg configPath}
|
||||
'';
|
||||
proxyBypassUp = pkgs.writeShellScript "proxy-suite-awg-${name}-proxy-bypass-up" ''
|
||||
set -euo pipefail
|
||||
|
||||
add_bypass_rule() {
|
||||
local family="$1"
|
||||
while ${pkgs.iproute2}/bin/ip "$family" rule del \
|
||||
pref ${toString proxyBypassRulePriority} \
|
||||
fwmark ${toString cfg.proxy.tproxy.proxyMark} lookup main 2>/dev/null; do :; done
|
||||
if ! ${pkgs.iproute2}/bin/ip "$family" rule add \
|
||||
pref ${toString proxyBypassRulePriority} \
|
||||
fwmark ${toString cfg.proxy.tproxy.proxyMark} lookup main 2>/dev/null; then
|
||||
# IPv4 is required: without this rule the proxy backend itself is
|
||||
# captured by AWG's default-route table and HTTP_PROXY clients can
|
||||
# hang or recurse. IPv6 is best-effort for hosts without IPv6
|
||||
# policy-routing support.
|
||||
if [ "$family" = "-4" ]; then
|
||||
echo "proxy-suite: unable to install the AWG proxy-backend bypass rule" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
add_bypass_rule -4
|
||||
add_bypass_rule -6
|
||||
'';
|
||||
proxyBypassDown = pkgs.writeShellScript "proxy-suite-awg-${name}-proxy-bypass-down" ''
|
||||
set +e
|
||||
|
||||
while ${pkgs.iproute2}/bin/ip -4 rule del \
|
||||
pref ${toString proxyBypassRulePriority} \
|
||||
fwmark ${toString cfg.proxy.tproxy.proxyMark} lookup main 2>/dev/null; do :; done
|
||||
while ${pkgs.iproute2}/bin/ip -6 rule del \
|
||||
pref ${toString proxyBypassRulePriority} \
|
||||
fwmark ${toString cfg.proxy.tproxy.proxyMark} lookup main 2>/dev/null; do :; done
|
||||
'';
|
||||
start = pkgs.writeShellScript "proxy-suite-awg-${name}-start" ''
|
||||
set -Eeuo pipefail
|
||||
|
||||
cleanup() {
|
||||
set +e
|
||||
${awgCfg.toolsPackage}/bin/awg-quick down ${lib.escapeShellArg configPath}
|
||||
|
||||
# If the userspace control socket died, awg-quick cannot discover its
|
||||
# fwmark. Remove only routing/firewall state tied to this interface.
|
||||
for family in -4 -6; do
|
||||
had_table=0
|
||||
for table in $(${pkgs.iproute2}/bin/ip "$family" route show table all 2>/dev/null \
|
||||
| ${pkgs.gawk}/bin/awk '$1 == "default" && $2 == "dev" && $3 == "${profile.interfaceName}" { for (i = 1; i <= NF; i++) if ($i == "table") print $(i + 1) }'); do
|
||||
had_table=1
|
||||
while ${pkgs.iproute2}/bin/ip "$family" rule delete table "$table" 2>/dev/null; do :; done
|
||||
${pkgs.iproute2}/bin/ip "$family" route flush table "$table" 2>/dev/null || true
|
||||
done
|
||||
if (( had_table )); then
|
||||
${pkgs.iproute2}/bin/ip "$family" rule delete table main suppress_prefixlength 0 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
if command -v nft >/dev/null; then
|
||||
nft list tables 2>/dev/null \
|
||||
| ${pkgs.gnugrep}/bin/grep -F " wg-quick-${profile.interfaceName}" \
|
||||
| while read -r _ family table; do nft delete table "$family" "$table" 2>/dev/null || true; done
|
||||
fi
|
||||
${config.networking.resolvconf.package}/bin/resolvconf -d "${profile.interfaceName}" -f 2>/dev/null || true
|
||||
${pkgs.iproute2}/bin/ip link delete dev ${lib.escapeShellArg profile.interfaceName} 2>/dev/null || true
|
||||
}
|
||||
trap cleanup ERR
|
||||
|
||||
${lib.optionalString (awgCfg.kernelModulePackage != null) ''
|
||||
${pkgs.kmod}/bin/modprobe amneziawg 2>/dev/null || true
|
||||
''}
|
||||
|
||||
implementation="$(${pkgs.python3}/bin/python3 ${configTool} \
|
||||
--transport-implementation ${lib.escapeShellArg configPath})"
|
||||
# The official 3.1.20260812 kernel module silently drops transport
|
||||
# packets for RandomTrailers with ranged H1-H3. The bundled userspace
|
||||
# build carries the receive-path repair until upstream publishes it.
|
||||
if [[ "$implementation" == userspace ]]; then
|
||||
WG_QUICK_FORCE_USERSPACE_IMPLEMENTATION=1 \
|
||||
WG_QUICK_USERSPACE_IMPLEMENTATION=${awgCfg.userspacePackage}/bin/amneziawg-go \
|
||||
${awgCfg.toolsPackage}/bin/awg-quick up ${lib.escapeShellArg configPath}
|
||||
else
|
||||
WG_QUICK_USERSPACE_IMPLEMENTATION=${awgCfg.userspacePackage}/bin/amneziawg-go \
|
||||
${awgCfg.toolsPackage}/bin/awg-quick up ${lib.escapeShellArg configPath}
|
||||
fi
|
||||
|
||||
probe="$(${pkgs.python3}/bin/python3 ${configTool} --probe-address ${lib.escapeShellArg configPath})"
|
||||
for _ in $(${pkgs.coreutils}/bin/seq 1 15); do
|
||||
${pkgs.iputils}/bin/ping -n -c 1 -W 1 "$probe" >/dev/null 2>&1 || true
|
||||
if ${awgCfg.toolsPackage}/bin/awg show ${lib.escapeShellArg profile.interfaceName} latest-handshakes 2>/dev/null \
|
||||
| ${pkgs.gawk}/bin/awk '$2 + 0 > 0 { found = 1 } END { exit !found }'; then
|
||||
trap - ERR
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
|
||||
echo "proxy-suite: AmneziaWG profile '${name}' did not complete a handshake; rolling back routes" >&2
|
||||
false
|
||||
'';
|
||||
stop = pkgs.writeShellScript "proxy-suite-awg-${name}-stop" ''
|
||||
set -euo pipefail
|
||||
exec ${awgCfg.toolsPackage}/bin/awg-quick down ${lib.escapeShellArg configPath}
|
||||
'';
|
||||
in
|
||||
{
|
||||
description = "proxy-suite AmneziaWG client profile ${name}";
|
||||
# When the normal proxy stack is enabled, bring its local HTTP/SOCKS
|
||||
# listener up before installing AWG's default-route policy. This keeps
|
||||
# applications using HTTP_PROXY/HTTPS_PROXY (for example Codex) from
|
||||
# racing the proxy backend during boot or an explicit `awg on`.
|
||||
after = [
|
||||
"network-online.target"
|
||||
"zapret-discord-youtube.service"
|
||||
]
|
||||
++ lib.optional cfg.proxy.enable "proxy-suite-socks.service";
|
||||
wants = [ "network-online.target" ] ++ lib.optional cfg.proxy.enable "proxy-suite-socks.service";
|
||||
wantedBy = lib.optionals profile.autostart [ "multi-user.target" ];
|
||||
conflicts = allProfileConflicts name ++ [
|
||||
"proxy-suite-tun.service"
|
||||
"proxy-suite-tproxy.service"
|
||||
"zapret-discord-youtube.service"
|
||||
"proxy-suite-per-app-zapret.service"
|
||||
"proxy-suite-zapret-vm-exempt.service"
|
||||
];
|
||||
path = [
|
||||
awgCfg.toolsPackage
|
||||
awgCfg.userspacePackage
|
||||
pkgs.coreutils
|
||||
pkgs.gnugrep
|
||||
pkgs.iproute2
|
||||
pkgs.iputils
|
||||
pkgs.kmod
|
||||
config.networking.firewall.package
|
||||
config.networking.resolvconf.package
|
||||
];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
RuntimeDirectory = serviceName name;
|
||||
RuntimeDirectoryMode = "0700";
|
||||
UMask = "0077";
|
||||
NoNewPrivileges = true;
|
||||
LockPersonality = true;
|
||||
ProtectClock = true;
|
||||
ProtectControlGroups = true;
|
||||
ProtectHostname = true;
|
||||
ProtectKernelLogs = true;
|
||||
RestrictRealtime = true;
|
||||
RestrictSUIDSGID = true;
|
||||
ExecStartPre = [ prepare ] ++ lib.optionals cfg.proxy.enable [ proxyBypassUp ];
|
||||
ExecStart = start;
|
||||
ExecStop = stop;
|
||||
}
|
||||
// lib.optionalAttrs cfg.proxy.enable {
|
||||
ExecStopPost = proxyBypassDown;
|
||||
};
|
||||
};
|
||||
|
||||
profileAssertions = lib.concatMap (
|
||||
name:
|
||||
let
|
||||
profile = profiles.${name};
|
||||
settings = profile.settings;
|
||||
obfuscation = if settings == null then null else settings.obfuscation;
|
||||
in
|
||||
[
|
||||
{
|
||||
assertion = builtins.match "^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$" name != null;
|
||||
message = "proxy-suite: AmneziaWG profile '${name}' must be a safe 1-32 character identifier";
|
||||
}
|
||||
{
|
||||
assertion = sourceCount profile == 1;
|
||||
message = "proxy-suite: AmneziaWG profile '${name}' must set exactly one of configFile, vpnFile, vpn, or settings";
|
||||
}
|
||||
{
|
||||
assertion = profile.vpnContainer == null || profile.vpn != null || profile.vpnFile != null;
|
||||
message = "proxy-suite: AmneziaWG profile '${name}': vpnContainer requires vpn or vpnFile";
|
||||
}
|
||||
{
|
||||
assertion = settings == null || settings.addresses != [ ];
|
||||
message = "proxy-suite: AmneziaWG profile '${name}': declarative settings require at least one address";
|
||||
}
|
||||
{
|
||||
assertion = settings == null || settings.peers != [ ];
|
||||
message = "proxy-suite: AmneziaWG profile '${name}': declarative settings require at least one peer";
|
||||
}
|
||||
{
|
||||
assertion =
|
||||
settings == null || ((settings.privateKey != null) != (settings.privateKeyFile != null));
|
||||
message = "proxy-suite: AmneziaWG profile '${name}': set exactly one of settings.privateKey or settings.privateKeyFile";
|
||||
}
|
||||
{
|
||||
assertion =
|
||||
obfuscation == null
|
||||
|| ((obfuscation.headerProtectionKey != null) != (obfuscation.headerProtectionKeyFile != null))
|
||||
|| (obfuscation.headerProtectionKey == null && obfuscation.headerProtectionKeyFile == null);
|
||||
message = "proxy-suite: AmneziaWG profile '${name}': set at most one header-protection key source";
|
||||
}
|
||||
]
|
||||
++ lib.optionals (settings != null) (
|
||||
lib.imap0 (index: peer: {
|
||||
assertion = peer.presharedKey == null || peer.presharedKeyFile == null;
|
||||
message = "proxy-suite: AmneziaWG profile '${name}' peer ${toString index}: set at most one preshared key source";
|
||||
}) settings.peers
|
||||
)
|
||||
) profileNames;
|
||||
|
||||
interfaceNames = map (name: profiles.${name}.interfaceName) profileNames;
|
||||
autostartProfiles = builtins.filter (name: profiles.${name}.autostart) profileNames;
|
||||
globalAutostartCount =
|
||||
builtins.length autostartProfiles
|
||||
+ (if cfg.proxy.tun.autostart then 1 else 0)
|
||||
+ (if cfg.proxy.tproxy.autostart then 1 else 0);
|
||||
in
|
||||
{
|
||||
environment.systemPackages = [
|
||||
awgCfg.toolsPackage
|
||||
awgCfg.userspacePackage
|
||||
];
|
||||
|
||||
boot.extraModulePackages = lib.optionals (awgCfg.kernelModulePackage != null) [
|
||||
awgCfg.kernelModulePackage
|
||||
];
|
||||
|
||||
systemd.services = lib.mkMerge [
|
||||
(lib.mapAttrs' (
|
||||
name: profile: lib.nameValuePair (serviceName name) (mkService name profile)
|
||||
) profiles)
|
||||
(lib.mkIf cfg.proxy.tun.enable {
|
||||
proxy-suite-tun.conflicts = map (name: "${name}.service") serviceNames;
|
||||
})
|
||||
(lib.mkIf cfg.proxy.tproxy.enable {
|
||||
proxy-suite-tproxy.conflicts = map (name: "${name}.service") serviceNames;
|
||||
})
|
||||
];
|
||||
|
||||
assertions = profileAssertions ++ [
|
||||
{
|
||||
assertion = profiles != { };
|
||||
message = "proxy-suite: amneziaWg.enable requires at least one profile";
|
||||
}
|
||||
{
|
||||
assertion = builtins.length interfaceNames == builtins.length (lib.unique interfaceNames);
|
||||
message = "proxy-suite: AmneziaWG profile interface names must be unique";
|
||||
}
|
||||
{
|
||||
assertion = builtins.length autostartProfiles <= 1;
|
||||
message = "proxy-suite: at most one AmneziaWG profile may autostart";
|
||||
}
|
||||
{
|
||||
assertion = globalAutostartCount <= 1;
|
||||
message = "proxy-suite: at most one AmneziaWG, TUN, or TProxy global mode may autostart";
|
||||
}
|
||||
{
|
||||
assertion =
|
||||
!cfg.proxy.tun.enable
|
||||
|| builtins.all (interface: interface != cfg.proxy.tun.interface) interfaceNames;
|
||||
message = "proxy-suite: AmneziaWG interfaces must differ from proxy.tun.interface";
|
||||
}
|
||||
{
|
||||
assertion =
|
||||
!cfg.proxy.tun.perApp.enable
|
||||
|| builtins.all (interface: interface != cfg.proxy.tun.perApp.interface) interfaceNames;
|
||||
message = "proxy-suite: AmneziaWG interfaces must differ from proxy.tun.perApp.interface";
|
||||
}
|
||||
];
|
||||
}
|
||||
@@ -47,7 +47,12 @@ in
|
||||
packages
|
||||
cfg
|
||||
;
|
||||
inherit (configs) tproxyFile tunFile perAppTunFile routeModeRulesFile;
|
||||
inherit (configs)
|
||||
tproxyFile
|
||||
tunFile
|
||||
perAppTunFile
|
||||
routeModeRulesFile
|
||||
;
|
||||
inherit (nftr)
|
||||
nftablesRulesFile
|
||||
perAppTproxyRulesFile
|
||||
@@ -81,6 +86,17 @@ in
|
||||
}
|
||||
))
|
||||
|
||||
(lib.mkIf cfg.amneziaWg.enable (
|
||||
import ./amnezia-wg.nix {
|
||||
inherit
|
||||
config
|
||||
lib
|
||||
pkgs
|
||||
cfg
|
||||
;
|
||||
}
|
||||
))
|
||||
|
||||
(lib.mkIf cfg.tray.enable (
|
||||
import ./tray.nix {
|
||||
inherit
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (lib)
|
||||
mkEnableOption
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
awgTypes = import ./types/amnezia-wg.nix { inherit lib; };
|
||||
awgPackages = import ../../../pkgs/amneziawg.nix { inherit pkgs; };
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.amneziaWg = {
|
||||
enable = mkEnableOption "native AmneziaWG client profiles";
|
||||
|
||||
toolsPackage = mkOption {
|
||||
type = types.package;
|
||||
default = awgPackages.tools;
|
||||
description = "AWG 3.1 package providing awg and awg-quick.";
|
||||
};
|
||||
|
||||
userspacePackage = mkOption {
|
||||
type = types.package;
|
||||
default = awgPackages.userspace;
|
||||
description = "AWG 3.1 userspace implementation used when the kernel interface is unavailable.";
|
||||
};
|
||||
|
||||
kernelModulePackage = mkOption {
|
||||
type = types.nullOr types.package;
|
||||
default = awgPackages.kernelModule config.boot.kernelPackages;
|
||||
description = "AWG 3.1 kernel module package. Set null to use userspace-only fallback.";
|
||||
};
|
||||
|
||||
profiles = mkOption {
|
||||
type = types.attrsOf awgTypes.profileType;
|
||||
default = { };
|
||||
description = "Named AmneziaWG client profiles. Only one global profile can be active.";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
{
|
||||
imports = [
|
||||
./other.nix
|
||||
./amnezia-wg.nix
|
||||
./legacy-sing-box.nix
|
||||
./sing-box.nix
|
||||
./sing-box-outbounds.nix
|
||||
|
||||
@@ -70,7 +70,7 @@ let
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite = {
|
||||
enable = lib.mkEnableOption "proxy suite (proxy backend + zapret + tg-ws-proxy)";
|
||||
enable = lib.mkEnableOption "proxy suite (proxy backend + AmneziaWG + zapret + tg-ws-proxy)";
|
||||
}
|
||||
// userControlOptions
|
||||
// trayOptions
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
# AmneziaWG profile option types.
|
||||
{ lib }:
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
optionalString = types.nullOr types.str;
|
||||
optionalUnsigned = types.nullOr types.ints.unsigned;
|
||||
rangeValue = types.oneOf [
|
||||
types.ints.unsigned
|
||||
(types.strMatching "^([0-9]+|[0-9]+-[0-9]+|\\(off\\))$")
|
||||
];
|
||||
optionalRange = types.nullOr rangeValue;
|
||||
|
||||
peerType = types.submodule {
|
||||
options = {
|
||||
publicKey = mkOption {
|
||||
type = types.strMatching "[^[:space:]]+";
|
||||
description = "AmneziaWG peer public key.";
|
||||
};
|
||||
presharedKey = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Inline peer preshared key. Prefer presharedKeyFile for secrets.";
|
||||
};
|
||||
presharedKeyFile = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Runtime path containing the peer preshared key.";
|
||||
};
|
||||
allowedIPs = mkOption {
|
||||
type = types.listOf types.str;
|
||||
description = "IP prefixes routed to and accepted from this peer.";
|
||||
example = [
|
||||
"0.0.0.0/0"
|
||||
"::/0"
|
||||
];
|
||||
};
|
||||
endpoint = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
example = "vpn.example.com:51820";
|
||||
description = "Optional peer endpoint in host:port form.";
|
||||
};
|
||||
persistentKeepalive = mkOption {
|
||||
type = optionalRange;
|
||||
default = null;
|
||||
description = "Persistent keepalive seconds, optionally expressed as an AWG 3 range.";
|
||||
};
|
||||
advancedSecurity = mkOption {
|
||||
type = types.nullOr types.bool;
|
||||
default = null;
|
||||
description = "Optional AWG peer AdvancedSecurity setting.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
obfuscationType = types.submodule {
|
||||
options = {
|
||||
jc = mkOption {
|
||||
type = optionalUnsigned;
|
||||
default = null;
|
||||
description = "Junk packet count (Jc).";
|
||||
};
|
||||
jmin = mkOption {
|
||||
type = optionalUnsigned;
|
||||
default = null;
|
||||
description = "Minimum junk packet size (Jmin).";
|
||||
};
|
||||
jmax = mkOption {
|
||||
type = optionalUnsigned;
|
||||
default = null;
|
||||
description = "Maximum junk packet size (Jmax).";
|
||||
};
|
||||
s1 = mkOption {
|
||||
type = optionalUnsigned;
|
||||
default = null;
|
||||
description = "Handshake-init padding (S1).";
|
||||
};
|
||||
s2 = mkOption {
|
||||
type = optionalUnsigned;
|
||||
default = null;
|
||||
description = "Handshake-response padding (S2).";
|
||||
};
|
||||
s3 = mkOption {
|
||||
type = optionalUnsigned;
|
||||
default = null;
|
||||
description = "Cookie-reply padding (S3).";
|
||||
};
|
||||
s4 = mkOption {
|
||||
type = optionalUnsigned;
|
||||
default = null;
|
||||
description = "Transport-message padding (S4).";
|
||||
};
|
||||
h1 = mkOption {
|
||||
type = optionalRange;
|
||||
default = null;
|
||||
description = "Handshake-init header or range (H1).";
|
||||
};
|
||||
h2 = mkOption {
|
||||
type = optionalRange;
|
||||
default = null;
|
||||
description = "Handshake-response header or range (H2).";
|
||||
};
|
||||
h3 = mkOption {
|
||||
type = optionalRange;
|
||||
default = null;
|
||||
description = "Cookie-reply header or range (H3).";
|
||||
};
|
||||
h4 = mkOption {
|
||||
type = optionalRange;
|
||||
default = null;
|
||||
description = "Transport-message header or range (H4).";
|
||||
};
|
||||
i1 = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "First custom signature packet (I1).";
|
||||
};
|
||||
i2 = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Second custom signature packet (I2).";
|
||||
};
|
||||
i3 = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Third custom signature packet (I3).";
|
||||
};
|
||||
i4 = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Fourth custom signature packet (I4).";
|
||||
};
|
||||
i5 = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Fifth custom signature packet (I5).";
|
||||
};
|
||||
headerProtectionKey = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Inline AWG 3 header-protection key. Prefer headerProtectionKeyFile.";
|
||||
};
|
||||
headerProtectionKeyFile = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Runtime path containing the AWG 3 header-protection key.";
|
||||
};
|
||||
contentPaddingAddition = mkOption {
|
||||
type = optionalRange;
|
||||
default = null;
|
||||
description = "AWG 3 content-padding addition or range.";
|
||||
};
|
||||
rekeyAfterTime = mkOption {
|
||||
type = optionalRange;
|
||||
default = null;
|
||||
description = "AWG 3 rekey interval or range.";
|
||||
};
|
||||
rekeyTimeout = mkOption {
|
||||
type = optionalRange;
|
||||
default = null;
|
||||
description = "AWG 3 rekey timeout or range.";
|
||||
};
|
||||
rejectAfterTime = mkOption {
|
||||
type = optionalRange;
|
||||
default = null;
|
||||
description = "AWG 3 reject-after interval or range.";
|
||||
};
|
||||
keepaliveTimeout = mkOption {
|
||||
type = optionalRange;
|
||||
default = null;
|
||||
description = "AWG 3 keepalive timeout or range.";
|
||||
};
|
||||
maxHandshakeAttempts = mkOption {
|
||||
type = optionalRange;
|
||||
default = null;
|
||||
description = "AWG 3 maximum handshake attempts or range.";
|
||||
};
|
||||
randomTrailers = mkOption {
|
||||
type = types.nullOr types.bool;
|
||||
default = null;
|
||||
description = "AWG 3 random transport trailers (RandomTrailers).";
|
||||
};
|
||||
disableCookies = mkOption {
|
||||
type = types.nullOr types.bool;
|
||||
default = null;
|
||||
description = "AWG 3 cookie suppression (DisableCookies).";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
settingsType = types.submodule {
|
||||
options = {
|
||||
addresses = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "IP prefixes assigned to the AWG interface.";
|
||||
example = [ "10.8.0.2/32" ];
|
||||
};
|
||||
dns = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "DNS servers installed while this profile is active.";
|
||||
};
|
||||
privateKey = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Inline client private key. Prefer privateKeyFile.";
|
||||
};
|
||||
privateKeyFile = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Runtime path containing the client private key.";
|
||||
};
|
||||
listenPort = mkOption {
|
||||
type = types.nullOr types.port;
|
||||
default = null;
|
||||
description = "Optional local UDP listen port.";
|
||||
};
|
||||
mtu = mkOption {
|
||||
type = optionalUnsigned;
|
||||
default = null;
|
||||
description = "Optional interface MTU.";
|
||||
};
|
||||
table = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "wg-quick routing table name/number, auto, or off.";
|
||||
};
|
||||
obfuscation = mkOption {
|
||||
type = obfuscationType;
|
||||
default = { };
|
||||
description = "AmneziaWG 1.x through 3.x obfuscation parameters.";
|
||||
};
|
||||
peers = mkOption {
|
||||
type = types.listOf peerType;
|
||||
default = [ ];
|
||||
description = "AmneziaWG peers.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
profileType = types.submodule (
|
||||
{ name, ... }:
|
||||
{
|
||||
options = {
|
||||
interfaceName = mkOption {
|
||||
type = types.strMatching "^[A-Za-z0-9_.-]{1,15}$";
|
||||
default = "awg-${name}";
|
||||
description = "Linux interface name. It must fit Linux's 15-character limit.";
|
||||
};
|
||||
autostart = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Whether to start this profile at boot. At most one profile may autostart.";
|
||||
};
|
||||
allowConfigHooks = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Allow trusted imported configs to execute wg-quick hooks or use SaveConfig.";
|
||||
};
|
||||
vpnContainer = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "AWG container/protocol identifier to select when a vpn:// bundle is ambiguous.";
|
||||
};
|
||||
configFile = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Runtime path to an AmneziaWG .conf file.";
|
||||
};
|
||||
vpnFile = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Runtime path containing a self-contained vpn:// export.";
|
||||
};
|
||||
vpn = mkOption {
|
||||
type = optionalString;
|
||||
default = null;
|
||||
description = "Inline self-contained vpn:// export. This value is stored in the Nix store.";
|
||||
};
|
||||
settings = mkOption {
|
||||
type = types.nullOr settingsType;
|
||||
default = null;
|
||||
description = "Typed declarative AmneziaWG client configuration.";
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
inherit
|
||||
profileType
|
||||
settingsType
|
||||
peerType
|
||||
obfuscationType
|
||||
rangeValue
|
||||
;
|
||||
}
|
||||
@@ -55,6 +55,9 @@ let
|
||||
headBin = "${pkgs.coreutils}/bin/head";
|
||||
seqBin = "${pkgs.coreutils}/bin/seq";
|
||||
findBin = "${pkgs.findutils}/bin/find";
|
||||
amneziaWgProfileNamesFile = pkgs.writeText "proxy-suite-awg-profiles.json" (
|
||||
builtins.toJSON (builtins.attrNames cfg.amneziaWg.profiles)
|
||||
);
|
||||
|
||||
proxySuiteScriptsDir = ../../../scripts;
|
||||
parserScriptsPythonPath = proxySuiteScriptsDir;
|
||||
@@ -138,6 +141,7 @@ let
|
||||
;
|
||||
inherit (scripts) subscriptionTagsFile subscriptionCacheDir;
|
||||
inherit (scripts) routeModeStateFile;
|
||||
inherit amneziaWgProfileNamesFile;
|
||||
inherit (perAppRouting)
|
||||
perAppRoutingProfilesFile
|
||||
proxychainsConfigFile
|
||||
@@ -172,5 +176,6 @@ in
|
||||
scripts
|
||||
perAppRouting
|
||||
control
|
||||
amneziaWgProfileNamesFile
|
||||
;
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
proxychainsConfigFile,
|
||||
proxychainsQuietArg,
|
||||
routeModeStateFile,
|
||||
amneziaWgProfileNamesFile,
|
||||
}:
|
||||
{
|
||||
proxyCtl = packages.mkProxyCtl {
|
||||
@@ -26,6 +27,7 @@
|
||||
proxychainsConfigFile
|
||||
proxychainsQuietArg
|
||||
routeModeStateFile
|
||||
amneziaWgProfileNamesFile
|
||||
;
|
||||
defaultRouteMode = if proxyCfg.proxyByDefault then "blacklist" else "whitelist";
|
||||
perAppRoutingEnabled = if perAppRoutingCfg.enable then "1" else "0";
|
||||
|
||||
@@ -14,6 +14,9 @@ let
|
||||
|
||||
zapretCfg = cfg.zapret;
|
||||
perAppZapretCfg = zapretCfg.perApp;
|
||||
awgServiceNames = map (name: "proxy-suite-awg-${name}.service") (
|
||||
builtins.attrNames cfg.amneziaWg.profiles
|
||||
);
|
||||
zapretPackages = import ./zapret/packages.nix {
|
||||
inherit
|
||||
lib
|
||||
@@ -84,6 +87,7 @@ in
|
||||
description = "zapret DPI bypass";
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
conflicts = awgServiceNames;
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
preStart = zapretCommonPreStart globalZapretPackage;
|
||||
runtimeDirectory = "proxy-suite-zapret";
|
||||
@@ -102,7 +106,8 @@ in
|
||||
conflicts = [
|
||||
"proxy-suite-tproxy.service"
|
||||
"proxy-suite-tun.service"
|
||||
];
|
||||
]
|
||||
++ awgServiceNames;
|
||||
preStart = zapretCommonPreStart perAppZapretPackage;
|
||||
runtimeDirectory = "proxy-suite-per-app-zapret";
|
||||
execStart = "${perAppZapretPackage}/opt/zapret/init.d/sysv/zapret start";
|
||||
@@ -118,6 +123,7 @@ in
|
||||
description = "Exempt CIDRs from zapret NFQUEUE";
|
||||
after = [ "zapret-discord-youtube.service" ];
|
||||
wants = [ "zapret-discord-youtube.service" ];
|
||||
conflicts = awgServiceNames;
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
execStart = pkgs.writeShellScript "proxy-suite-zapret-vm-exempt-start" exemptStart;
|
||||
execStop = pkgs.writeShellScript "proxy-suite-zapret-vm-exempt-stop" exemptStop;
|
||||
|
||||
Reference in new issue
Block a user