refactor: remove duplication
This commit is contained in:
109 files changed
+2206
-3078
No files matched your search
@@ -23,13 +23,10 @@ let
|
||||
lanListeners = builtins.filter (listener: listener.mode == "lan") listeners;
|
||||
lanIPv6 = lib.any (listener: listener.subnet6 != null) lanListeners;
|
||||
|
||||
scriptsDir = builtins.path {
|
||||
name = "proxy-suite-scripts";
|
||||
path = ../../scripts;
|
||||
};
|
||||
scriptsDir = import ./lib/scripts-dir.nix { inherit lib; };
|
||||
python3 = "${pkgs.python3}/bin/python3";
|
||||
awg = "${awgCfg.toolsPackage}/bin/awg";
|
||||
awgQuick = "${awgCfg.toolsPackage}/bin/awg-quick";
|
||||
awgCommon = import ./awg-common.nix { inherit lib pkgs awgCfg; };
|
||||
|
||||
# Diverted packets are delivered locally; only "lan" listeners forward.
|
||||
sysctl =
|
||||
@@ -128,9 +125,7 @@ let
|
||||
set -Eeuo pipefail
|
||||
trap ${stop} ERR
|
||||
|
||||
${lib.optionalString (awgCfg.kernelModulePackage != null) ''
|
||||
${pkgs.kmod}/bin/modprobe amneziawg 2>/dev/null || true
|
||||
''}
|
||||
${awgCommon.modprobe}
|
||||
|
||||
${stop}
|
||||
|
||||
@@ -139,15 +134,7 @@ let
|
||||
> "$RUNTIME_DIRECTORY/interfaces"
|
||||
|
||||
while read -r _interface implementation config; do
|
||||
# The 3.1 kernel module drops RandomTrailers packets with ranged H1-H3; userspace does not.
|
||||
if [[ "$implementation" == userspace ]]; then
|
||||
WG_QUICK_FORCE_USERSPACE_IMPLEMENTATION=1 \
|
||||
WG_QUICK_USERSPACE_IMPLEMENTATION=${awgCfg.userspacePackage}/bin/amneziawg-go \
|
||||
${awgQuick} up "$config"
|
||||
else
|
||||
WG_QUICK_USERSPACE_IMPLEMENTATION=${awgCfg.userspacePackage}/bin/amneziawg-go \
|
||||
${awgQuick} up "$config"
|
||||
fi
|
||||
${awgCommon.awgQuickUp "$implementation" "\"$config\""}
|
||||
done < "$RUNTIME_DIRECTORY/interfaces"
|
||||
|
||||
${lib.concatStrings (
|
||||
|
||||
@@ -81,12 +81,8 @@ let
|
||||
// source profile
|
||||
)
|
||||
);
|
||||
configTool = "${
|
||||
builtins.path {
|
||||
name = "proxy-suite-scripts";
|
||||
path = ../../scripts;
|
||||
}
|
||||
}/amneziawg_config.py";
|
||||
configTool = "${import ./lib/scripts-dir.nix { inherit lib; }}/amneziawg_config.py";
|
||||
awgCommon = import ./awg-common.nix { inherit lib pkgs awgCfg; };
|
||||
runtimeDir = name: "/run/${serviceName name}";
|
||||
runtimeConfig = name: profile: "${runtimeDir name}/${profile.interfaceName}.conf";
|
||||
# Keep proxy backend sockets (proxyMark) out of AWG's default-route table.
|
||||
@@ -204,22 +200,11 @@ let
|
||||
}
|
||||
trap cleanup ERR
|
||||
|
||||
${lib.optionalString (awgCfg.kernelModulePackage != null) ''
|
||||
${pkgs.kmod}/bin/modprobe amneziawg 2>/dev/null || true
|
||||
''}
|
||||
${awgCommon.modprobe}
|
||||
|
||||
read -r implementation probe _ < <(${pkgs.python3}/bin/python3 ${configTool} \
|
||||
--inspect ${lib.escapeShellArg configPath})
|
||||
# The 3.1 kernel module dropped RandomTrailers packets with ranged H1-H3 (seen on 20260812);
|
||||
# userspace carries the fix.
|
||||
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
|
||||
${awgCommon.awgQuickUp "$implementation" (lib.escapeShellArg configPath)}
|
||||
|
||||
${mkHandshakeHelpers profile}
|
||||
# A handshake is retried every 5 seconds: each retry after the first gets a new port.
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# Routing rules → generated configs → nftables rule files → service context: the wiring the
|
||||
# host-neutral module does at evaluation time, in one place so the docs generator and the
|
||||
# checks assemble it exactly as the running system does.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
cfg,
|
||||
packages,
|
||||
zapret,
|
||||
}:
|
||||
let
|
||||
rules = import ./rules.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
cfg
|
||||
zapret
|
||||
;
|
||||
};
|
||||
configs = import ./config.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
cfg
|
||||
rules
|
||||
;
|
||||
};
|
||||
nftr = import ./nftables.nix { inherit lib pkgs cfg; };
|
||||
context = import ./service/context.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
packages
|
||||
cfg
|
||||
;
|
||||
inherit (configs)
|
||||
tproxyFile
|
||||
tunFile
|
||||
perAppTunFile
|
||||
routeModeRulesFile
|
||||
proxyInboundsFile
|
||||
proxyInboundsSpecFile
|
||||
;
|
||||
inherit (nftr)
|
||||
perAppTunChainFile
|
||||
perAppTproxyRulesFile
|
||||
perAppZapretRulesFile
|
||||
nftablesRulesFile
|
||||
ip
|
||||
nft
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit
|
||||
rules
|
||||
configs
|
||||
nftr
|
||||
context
|
||||
;
|
||||
inherit (context) derived;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
# Shared AmneziaWG plumbing: bringing an interface up the way both the client profiles
|
||||
# (./amnezia-wg.nix) and the server listeners (./amnezia-wg-inbounds.nix) need it.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
awgCfg,
|
||||
}:
|
||||
{
|
||||
# The kernel module is optional; userspace works without it.
|
||||
modprobe = lib.optionalString (awgCfg.kernelModulePackage != null) ''
|
||||
${pkgs.kmod}/bin/modprobe amneziawg 2>/dev/null || true
|
||||
'';
|
||||
|
||||
# `implementation` is a shell word holding "userspace" or "kernel", `config` the .conf path.
|
||||
# The 3.1 kernel module dropped RandomTrailers packets with ranged H1-H3 (seen on 20260812);
|
||||
# userspace carries the fix, so a profile that needs it asks for userspace by name.
|
||||
awgQuickUp = implementation: config: ''
|
||||
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 ${config}
|
||||
else
|
||||
WG_QUICK_USERSPACE_IMPLEMENTATION=${awgCfg.userspacePackage}/bin/amneziawg-go \
|
||||
${awgCfg.toolsPackage}/bin/awg-quick up ${config}
|
||||
fi
|
||||
'';
|
||||
}
|
||||
@@ -14,17 +14,7 @@ let
|
||||
proxyInboundsResolveInSingBox
|
||||
;
|
||||
|
||||
localProxyAddress =
|
||||
if
|
||||
builtins.elem proxyCfg.listener.address [
|
||||
"0.0.0.0"
|
||||
"::"
|
||||
""
|
||||
]
|
||||
then
|
||||
"127.0.0.1"
|
||||
else
|
||||
proxyCfg.listener.address;
|
||||
localProxyAddress = derived.localProxy.host;
|
||||
|
||||
# The client stack's SOCKS listener; credentials are injected at start.
|
||||
localProxyOutbound = lib.optional proxyInboundsNeedLocalProxy {
|
||||
|
||||
@@ -18,8 +18,16 @@
|
||||
let
|
||||
cfg = config.services.proxy-suite;
|
||||
packages = import ../../pkgs/default.nix { inherit pkgs; };
|
||||
nftr = import ./nftables.nix { inherit lib pkgs cfg; };
|
||||
derived = import ./derived.nix { inherit lib cfg; };
|
||||
assembly = import ./assembly.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
cfg
|
||||
packages
|
||||
zapret
|
||||
;
|
||||
};
|
||||
inherit (assembly) nftr derived;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
@@ -44,48 +52,10 @@ in
|
||||
}
|
||||
|
||||
(lib.mkIf cfg.enable (
|
||||
let
|
||||
rules = import ./rules.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
cfg
|
||||
zapret
|
||||
;
|
||||
};
|
||||
configs = import ./config.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
cfg
|
||||
rules
|
||||
;
|
||||
};
|
||||
in
|
||||
lib.mkMerge [
|
||||
(import ./service {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
packages
|
||||
cfg
|
||||
;
|
||||
inherit (configs)
|
||||
tproxyFile
|
||||
tunFile
|
||||
perAppTunFile
|
||||
routeModeRulesFile
|
||||
proxyInboundsFile
|
||||
proxyInboundsSpecFile
|
||||
;
|
||||
inherit (nftr)
|
||||
nftablesRulesFile
|
||||
perAppTproxyRulesFile
|
||||
perAppZapretRulesFile
|
||||
perAppTunChainFile
|
||||
ip
|
||||
nft
|
||||
;
|
||||
inherit lib pkgs cfg;
|
||||
inherit (assembly) context;
|
||||
})
|
||||
|
||||
(lib.mkIf
|
||||
@@ -176,7 +146,7 @@ in
|
||||
cfg
|
||||
derived
|
||||
;
|
||||
inherit (configs) proxyInboundsSpecFile;
|
||||
inherit (assembly.configs) proxyInboundsSpecFile;
|
||||
inherit (nftr) reservedIpBlock ip nft;
|
||||
}
|
||||
))
|
||||
|
||||
@@ -18,7 +18,6 @@ let
|
||||
singBoxEnabled = proxyEnabled && proxyCfg.backend != "xray";
|
||||
xrayEnabled = proxyEnabled && proxyCfg.backend != "sing-box";
|
||||
hybridEnabled = proxyEnabled && proxyCfg.backend == "hybrid";
|
||||
pureSingBoxEnabled = proxyEnabled && proxyCfg.backend == "sing-box";
|
||||
pureXrayEnabled = proxyEnabled && proxyCfg.backend == "xray";
|
||||
activeBackend = if proxyEnabled then proxyCfg.backend else null;
|
||||
perAppRoutingCfg = cfg.perAppRouting;
|
||||
@@ -36,6 +35,29 @@ let
|
||||
# Only sing-box dials SSH natively; XRay and standalone tunnels use the OpenSSH unit.
|
||||
sshProxyNativeOutbound = sshProxyOutboundEnabled && !pureXrayEnabled;
|
||||
sshProxyUnitEnabled = sshProxyCfg.enable && !sshProxyNativeOutbound;
|
||||
# The local proxy as the other services dial it: a wildcard listener is reached on loopback.
|
||||
# (The secret itself stays with whoever needs it on disk: derived.nix has no pkgs.)
|
||||
localProxy =
|
||||
let
|
||||
auth = proxyCfg.listener.auth;
|
||||
host =
|
||||
if
|
||||
builtins.elem proxyCfg.listener.address [
|
||||
"0.0.0.0"
|
||||
"::"
|
||||
""
|
||||
]
|
||||
then
|
||||
"127.0.0.1"
|
||||
else
|
||||
proxyCfg.listener.address;
|
||||
in
|
||||
{
|
||||
inherit auth host;
|
||||
hostPart = if lib.hasInfix ":" host then "[${host}]" else host;
|
||||
authEnabled = auth.username != null && (auth.password != null || auth.passwordFile != null);
|
||||
};
|
||||
|
||||
warpCfg = cfg.warp // {
|
||||
# Without a configFile, proxy-suite-warp registers with wgcf into its state dir.
|
||||
autoRegister = cfg.warp.enable && cfg.warp.configFile == null;
|
||||
@@ -402,13 +424,13 @@ in
|
||||
{
|
||||
inherit
|
||||
proxyCfg
|
||||
localProxy
|
||||
singBoxCfg
|
||||
xrayCfg
|
||||
proxyEnabled
|
||||
singBoxEnabled
|
||||
xrayEnabled
|
||||
hybridEnabled
|
||||
pureSingBoxEnabled
|
||||
pureXrayEnabled
|
||||
activeBackend
|
||||
perAppRoutingCfg
|
||||
@@ -426,12 +448,10 @@ in
|
||||
userControlEnabled
|
||||
userControlAllows
|
||||
sshProxyCfg
|
||||
sshProxyOutboundTag
|
||||
sshProxyOutboundEnabled
|
||||
sshProxyNativeOutbound
|
||||
sshProxyUnitEnabled
|
||||
warpCfg
|
||||
warpOutboundTag
|
||||
warpOutboundEnabled
|
||||
torCfg
|
||||
torOutboundTag
|
||||
@@ -464,7 +484,6 @@ in
|
||||
outboundTags
|
||||
effectiveOutboundTags
|
||||
subscriptionTags
|
||||
hasStaticOutbounds
|
||||
hasSubscriptions
|
||||
hasAvailableOutbounds
|
||||
collapseNamedOutbounds
|
||||
|
||||
@@ -13,6 +13,63 @@ rec {
|
||||
);
|
||||
forward = forwardWith lib.id;
|
||||
|
||||
# The unit and package forwarding NixOS and system-manager do identically.
|
||||
systemdForward = internal: {
|
||||
systemd.services = forward internal.services;
|
||||
systemd.timers = forward internal.timers;
|
||||
systemd.paths = forward internal.paths;
|
||||
systemd.tmpfiles.rules = forward internal.tmpfiles;
|
||||
|
||||
environment.systemPackages = lib.mkMerge [
|
||||
(forwardWith lib.mkBefore internal.earlyPackages)
|
||||
(forward internal.packages)
|
||||
];
|
||||
};
|
||||
|
||||
# One system user per daemon, each in a group of its own, plus the userControl group.
|
||||
systemUsersAndGroups = cfg: {
|
||||
users.users = lib.genAttrs cfg.internal.systemUsers (name: {
|
||||
isSystemUser = true;
|
||||
group = name;
|
||||
description = "proxy-suite daemons";
|
||||
});
|
||||
users.groups = lib.genAttrs (cfg.internal.systemUsers ++ cfg.internal.groups) (_: { });
|
||||
};
|
||||
|
||||
firewallPortForward = internal: {
|
||||
networking.firewall = {
|
||||
allowedTCPPorts = forward internal.firewall.allowedTCPPorts;
|
||||
allowedUDPPorts = forward internal.firewall.allowedUDPPorts;
|
||||
};
|
||||
};
|
||||
|
||||
# The rootless adapters (home-manager, nix-on-droid) render the same unit set for a user
|
||||
# manager: system and user services together, timers and paths, each filtered to enabled.
|
||||
userUnitsFor =
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
host,
|
||||
internal,
|
||||
hostPath ? null,
|
||||
}:
|
||||
let
|
||||
units = import ./user-units.nix (
|
||||
{
|
||||
inherit lib pkgs;
|
||||
inherit (host) runtimeDir;
|
||||
stateDir = builtins.dirOf host.stateDir;
|
||||
}
|
||||
// lib.optionalAttrs (hostPath != null) { inherit hostPath; }
|
||||
);
|
||||
enabled = lib.filterAttrs (_: unit: unit.enable);
|
||||
in
|
||||
{
|
||||
services = lib.mapAttrs units.toService (enabled (internal.services // internal.userServices));
|
||||
timers = lib.mapAttrs units.toTimer (enabled internal.timers);
|
||||
paths = lib.mapAttrs units.toPath (enabled internal.paths);
|
||||
};
|
||||
|
||||
# Scripts share one store name per block, and journald names a unit's output
|
||||
# after its ExecStart basename; tag each unit with its own name instead.
|
||||
unitsWithOwnSyslogIdentifier = lib.mkOption {
|
||||
|
||||
@@ -13,18 +13,14 @@ let
|
||||
host = cfg.host;
|
||||
internal = cfg.internal;
|
||||
|
||||
inherit
|
||||
(import ./user-units.nix {
|
||||
inherit lib pkgs;
|
||||
inherit (host) runtimeDir;
|
||||
stateDir = dirOf host.stateDir;
|
||||
})
|
||||
toService
|
||||
toTimer
|
||||
toPath
|
||||
;
|
||||
|
||||
enabled = lib.filterAttrs (_: unit: unit.enable);
|
||||
userUnits = (import ./common.nix { inherit lib; }).userUnitsFor {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
host
|
||||
internal
|
||||
;
|
||||
};
|
||||
in
|
||||
{
|
||||
config = lib.mkMerge [
|
||||
@@ -44,11 +40,9 @@ in
|
||||
(lib.mkIf cfg.enable (
|
||||
lib.mkMerge [
|
||||
{
|
||||
systemd.user.services = lib.mapAttrs toService (
|
||||
enabled (internal.services // internal.userServices)
|
||||
);
|
||||
systemd.user.timers = lib.mapAttrs toTimer (enabled internal.timers);
|
||||
systemd.user.paths = lib.mapAttrs toPath (enabled internal.paths);
|
||||
systemd.user.services = userUnits.services;
|
||||
systemd.user.timers = userUnits.timers;
|
||||
systemd.user.paths = userUnits.paths;
|
||||
|
||||
home.packages = lib.mkMerge [
|
||||
(lib.mkBefore internal.earlyPackages)
|
||||
|
||||
@@ -15,30 +15,21 @@ let
|
||||
internal = cfg.internal;
|
||||
home = config.user.home;
|
||||
|
||||
inherit
|
||||
(import ./user-units.nix {
|
||||
inherit lib pkgs;
|
||||
inherit (host) runtimeDir;
|
||||
stateDir = dirOf host.stateDir;
|
||||
hostPath = "${home}/.nix-profile/bin";
|
||||
})
|
||||
toService
|
||||
toTimer
|
||||
toPath
|
||||
;
|
||||
|
||||
enabled = lib.filterAttrs (_: unit: unit.enable);
|
||||
userUnits = (import ./common.nix { inherit lib; }).userUnitsFor {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
host
|
||||
internal
|
||||
;
|
||||
hostPath = "${home}/.nix-profile/bin";
|
||||
};
|
||||
|
||||
supervisorDir = "${host.runtimeDir}/proxy-suite-supervisor";
|
||||
# Outside the store, so proxy-suitectl stays the same from one generation to the next.
|
||||
manifestLink = "${host.stateDir}/supervisor/manifest.json";
|
||||
manifest = pkgs.writeText "proxy-suite-units.json" (
|
||||
builtins.toJSON {
|
||||
services = lib.mapAttrs toService (enabled (internal.services // internal.userServices));
|
||||
timers = lib.mapAttrs toTimer (enabled internal.timers);
|
||||
paths = lib.mapAttrs toPath (enabled internal.paths);
|
||||
inherit (internal) tmpfiles;
|
||||
}
|
||||
builtins.toJSON (userUnits // { inherit (internal) tmpfiles; })
|
||||
);
|
||||
|
||||
suitectl = import ../../../pkgs/proxy-suite-supervisor.nix { inherit lib pkgs; } {
|
||||
|
||||
@@ -12,6 +12,8 @@ let
|
||||
inherit (import ./common.nix { inherit lib; })
|
||||
forwardWith
|
||||
forward
|
||||
systemdForward
|
||||
systemUsersAndGroups
|
||||
unitsWithOwnSyslogIdentifier
|
||||
;
|
||||
in
|
||||
@@ -32,39 +34,29 @@ in
|
||||
};
|
||||
}
|
||||
|
||||
(lib.mkIf cfg.enable {
|
||||
systemd.services = forward internal.services;
|
||||
systemd.user.services = forward internal.userServices;
|
||||
systemd.timers = forward internal.timers;
|
||||
systemd.paths = forward internal.paths;
|
||||
systemd.tmpfiles.rules = forward internal.tmpfiles;
|
||||
(lib.mkIf cfg.enable (
|
||||
lib.mkMerge [
|
||||
(systemdForward internal)
|
||||
(systemUsersAndGroups cfg)
|
||||
{
|
||||
systemd.user.services = forward internal.userServices;
|
||||
|
||||
environment.systemPackages = lib.mkMerge [
|
||||
(forwardWith lib.mkBefore internal.earlyPackages)
|
||||
(forward internal.packages)
|
||||
];
|
||||
security.polkit.enable = lib.mkIf cfg.internal.polkit.enable true;
|
||||
security.polkit.extraConfig = forwardWith lib.mkAfter internal.polkit.rules;
|
||||
|
||||
users.users = lib.genAttrs cfg.internal.systemUsers (name: {
|
||||
isSystemUser = true;
|
||||
group = name;
|
||||
description = "proxy-suite daemons";
|
||||
});
|
||||
users.groups = lib.genAttrs (cfg.internal.systemUsers ++ cfg.internal.groups) (_: { });
|
||||
networking.nftables.enable = lib.mkIf cfg.internal.nftables (lib.mkDefault true);
|
||||
networking.firewall = {
|
||||
allowedTCPPorts = forward internal.firewall.allowedTCPPorts;
|
||||
allowedUDPPorts = forward internal.firewall.allowedUDPPorts;
|
||||
extraReversePathFilterRules = forward internal.firewall.extraReversePathFilterRules;
|
||||
trustedInterfaces = forward internal.firewall.trustedInterfaces;
|
||||
};
|
||||
|
||||
security.polkit.enable = lib.mkIf cfg.internal.polkit.enable true;
|
||||
security.polkit.extraConfig = forwardWith lib.mkAfter internal.polkit.rules;
|
||||
|
||||
networking.nftables.enable = lib.mkIf cfg.internal.nftables (lib.mkDefault true);
|
||||
networking.firewall = {
|
||||
allowedTCPPorts = forward internal.firewall.allowedTCPPorts;
|
||||
allowedUDPPorts = forward internal.firewall.allowedUDPPorts;
|
||||
extraReversePathFilterRules = forward internal.firewall.extraReversePathFilterRules;
|
||||
trustedInterfaces = forward internal.firewall.trustedInterfaces;
|
||||
};
|
||||
|
||||
boot.extraModulePackages = forward internal.kernelModulePackages;
|
||||
boot.kernel.sysctl = lib.mapAttrs (_: lib.mkDefault) cfg.internal.sysctl;
|
||||
})
|
||||
boot.extraModulePackages = forward internal.kernelModulePackages;
|
||||
boot.kernel.sysctl = lib.mapAttrs (_: lib.mkDefault) cfg.internal.sysctl;
|
||||
}
|
||||
]
|
||||
))
|
||||
|
||||
# Off by default since nixpkgs 26.11, and always there before, where the option does
|
||||
# not exist.
|
||||
|
||||
@@ -14,8 +14,10 @@ let
|
||||
cfg = config.services.proxy-suite;
|
||||
internal = options.services.proxy-suite.internal;
|
||||
inherit (import ./common.nix { inherit lib; })
|
||||
forwardWith
|
||||
forward
|
||||
systemdForward
|
||||
systemUsersAndGroups
|
||||
firewallPortForward
|
||||
unitsWithOwnSyslogIdentifier
|
||||
;
|
||||
|
||||
@@ -72,47 +74,33 @@ in
|
||||
};
|
||||
}
|
||||
|
||||
(lib.mkIf cfg.enable {
|
||||
assertions = [
|
||||
(lib.mkIf cfg.enable (
|
||||
lib.mkMerge [
|
||||
(systemdForward internal)
|
||||
(systemUsersAndGroups cfg)
|
||||
# Only reported: system-manager leaves the host firewall alone. The routing modes load
|
||||
# their own nftables tables, and the distribution's loose reverse-path filter already
|
||||
# lets AmneziaWG replies in.
|
||||
(firewallPortForward internal)
|
||||
{
|
||||
assertion = cfg.internal.kernelModulePackages == [ ];
|
||||
message = "proxy-suite: system-manager cannot load kernel modules from Nix; leave amneziaWg.kernelModulePackage at null";
|
||||
assertions = [
|
||||
{
|
||||
assertion = cfg.internal.kernelModulePackages == [ ];
|
||||
message = "proxy-suite: system-manager cannot load kernel modules from Nix; leave amneziaWg.kernelModulePackage at null";
|
||||
}
|
||||
];
|
||||
|
||||
environment.etc = lib.mkMerge [
|
||||
userServiceFiles
|
||||
# Read by polkit 0.106 and later; the distribution runs the daemon. The rules
|
||||
# go through the host's setuid pkexec: nothing here needs a wrapper.
|
||||
(lib.mkIf cfg.internal.polkit.enable {
|
||||
"polkit-1/rules.d/50-proxy-suite.rules".text = cfg.internal.polkit.rules;
|
||||
})
|
||||
];
|
||||
|
||||
}
|
||||
];
|
||||
|
||||
systemd.services = forward internal.services;
|
||||
systemd.timers = forward internal.timers;
|
||||
systemd.paths = forward internal.paths;
|
||||
systemd.tmpfiles.rules = forward internal.tmpfiles;
|
||||
|
||||
environment.systemPackages = lib.mkMerge [
|
||||
(forwardWith lib.mkBefore internal.earlyPackages)
|
||||
(forward internal.packages)
|
||||
];
|
||||
|
||||
environment.etc = lib.mkMerge [
|
||||
userServiceFiles
|
||||
# Read by polkit 0.106 and later; the distribution runs the daemon. The rules
|
||||
# go through the host's setuid pkexec: nothing here needs a wrapper.
|
||||
(lib.mkIf cfg.internal.polkit.enable {
|
||||
"polkit-1/rules.d/50-proxy-suite.rules".text = cfg.internal.polkit.rules;
|
||||
})
|
||||
];
|
||||
|
||||
users.users = lib.genAttrs cfg.internal.systemUsers (name: {
|
||||
isSystemUser = true;
|
||||
group = name;
|
||||
description = "proxy-suite daemons";
|
||||
});
|
||||
users.groups = lib.genAttrs (cfg.internal.systemUsers ++ cfg.internal.groups) (_: { });
|
||||
|
||||
# Only reported: system-manager leaves the host firewall alone. The routing modes
|
||||
# load their own nftables tables, and the distribution's loose reverse-path filter
|
||||
# already lets AmneziaWG replies in.
|
||||
networking.firewall = {
|
||||
allowedTCPPorts = forward internal.firewall.allowedTCPPorts;
|
||||
allowedUDPPorts = forward internal.firewall.allowedUDPPorts;
|
||||
};
|
||||
})
|
||||
]
|
||||
))
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# The runtime helper scripts (../../../scripts), as one filtered store path shared by every
|
||||
# module that shells out to them. Unfiltered, the unit tests and any stale __pycache__ land
|
||||
# in every host's closure and move its store hash.
|
||||
{ lib }:
|
||||
builtins.path {
|
||||
name = "proxy-suite-scripts";
|
||||
path = ../../../scripts;
|
||||
filter =
|
||||
path: _type:
|
||||
let
|
||||
base = baseNameOf path;
|
||||
in
|
||||
!(lib.hasPrefix "test-" base) && base != "__pycache__";
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
./tg-ws-proxy.nix
|
||||
./geodata.nix
|
||||
./gui.nix
|
||||
./tray.nix
|
||||
./tui.nix
|
||||
./user-control.nix
|
||||
./host.nix
|
||||
|
||||
@@ -9,12 +9,7 @@ let
|
||||
types
|
||||
;
|
||||
t = import ./types.nix { inherit lib; };
|
||||
bool =
|
||||
default: description:
|
||||
mkOption {
|
||||
type = types.bool;
|
||||
inherit default description;
|
||||
};
|
||||
inherit (import ./lib.nix { inherit lib; }) bool;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.inbounds = {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
# The option shapes this module declares over and over, in one place.
|
||||
{ lib }:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
list =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
inherit description example;
|
||||
};
|
||||
nullStr =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
inherit description example;
|
||||
};
|
||||
bool =
|
||||
default: description:
|
||||
mkOption {
|
||||
type = types.bool;
|
||||
inherit default description;
|
||||
};
|
||||
int =
|
||||
default: description:
|
||||
mkOption {
|
||||
type = types.int;
|
||||
inherit default description;
|
||||
};
|
||||
positiveInt =
|
||||
default: description:
|
||||
mkOption {
|
||||
type = types.ints.positive;
|
||||
inherit default description;
|
||||
};
|
||||
# An option path under services.proxy-suite, for the compatibility modules.
|
||||
path =
|
||||
path:
|
||||
[
|
||||
"services"
|
||||
"proxy-suite"
|
||||
]
|
||||
++ lib.splitString "." path;
|
||||
}
|
||||
@@ -3,12 +3,7 @@
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
t = import ./types.nix { inherit lib; };
|
||||
int =
|
||||
default: description:
|
||||
mkOption {
|
||||
type = types.int;
|
||||
inherit default description;
|
||||
};
|
||||
inherit (import ./lib.nix { inherit lib; }) int;
|
||||
localSubnets =
|
||||
description:
|
||||
mkOption {
|
||||
|
||||
@@ -3,13 +3,7 @@
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
t = import ./types.nix { inherit lib; };
|
||||
list =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
inherit description example;
|
||||
};
|
||||
inherit (import ./lib.nix { inherit lib; }) list;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.proxy.routing = {
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
p =
|
||||
path:
|
||||
[
|
||||
"services"
|
||||
"proxy-suite"
|
||||
]
|
||||
++ lib.splitString "." path;
|
||||
p = (import ./lib.nix { inherit lib; }).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.
|
||||
@@ -24,6 +18,11 @@ let
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
# The tray indicator became Proxy Suite GUI, which has the tray icon built in.
|
||||
(lib.mkRenamedOptionModule (p "tray.enable") (p "gui.enable"))
|
||||
(lib.mkRenamedOptionModule (p "tray.autostart") (p "gui.autostart"))
|
||||
(lib.mkRenamedOptionModule (p "tray.pollInterval") (p "gui.refreshInterval"))
|
||||
|
||||
# These were aliases; they are removal notices now, so there is one
|
||||
# compatibility policy instead of two.
|
||||
(rm "proxyInbounds" "Use services.proxy-suite.inbounds.")
|
||||
|
||||
@@ -3,13 +3,7 @@
|
||||
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;
|
||||
};
|
||||
path = (import ./lib.nix { inherit lib; }).nullStr;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.sshProxy = {
|
||||
|
||||
@@ -2,13 +2,7 @@
|
||||
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
domains =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
inherit description example;
|
||||
};
|
||||
domains = (import ./lib.nix { inherit lib; }).list;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.tgWsProxy = {
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
{ lib, ... }:
|
||||
|
||||
let
|
||||
p =
|
||||
path:
|
||||
[
|
||||
"services"
|
||||
"proxy-suite"
|
||||
]
|
||||
++ lib.splitString "." path;
|
||||
in
|
||||
{
|
||||
# The tray indicator became Proxy Suite GUI, which has the tray icon built in.
|
||||
imports = [
|
||||
(lib.mkRenamedOptionModule (p "tray.enable") (p "gui.enable"))
|
||||
(lib.mkRenamedOptionModule (p "tray.autostart") (p "gui.autostart"))
|
||||
(lib.mkRenamedOptionModule (p "tray.pollInterval") (p "gui.refreshInterval"))
|
||||
];
|
||||
}
|
||||
@@ -2,14 +2,7 @@
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
|
||||
list =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
inherit description example;
|
||||
};
|
||||
inherit (import ./lib.nix { inherit lib; }) list;
|
||||
|
||||
routingFields = {
|
||||
domains = list "Domain suffixes to match." [ "youtube.com" ];
|
||||
|
||||
@@ -54,139 +54,50 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
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).";
|
||||
};
|
||||
# Every AWG obfuscation field is an optional scalar with a one-line description, so they
|
||||
# are declared as tables per value type rather than 27 near-identical mkOption blocks.
|
||||
optional =
|
||||
type: description:
|
||||
mkOption {
|
||||
inherit type description;
|
||||
default = null;
|
||||
};
|
||||
obfuscationType = types.submodule {
|
||||
options =
|
||||
lib.mapAttrs (_: optional optionalUnsigned) {
|
||||
jc = "Junk packet count (Jc).";
|
||||
jmin = "Minimum junk packet size (Jmin).";
|
||||
jmax = "Maximum junk packet size (Jmax).";
|
||||
s1 = "Handshake-init padding (S1).";
|
||||
s2 = "Handshake-response padding (S2).";
|
||||
s3 = "Cookie-reply padding (S3).";
|
||||
s4 = "Transport-message padding (S4).";
|
||||
}
|
||||
// lib.mapAttrs (_: optional optionalRange) {
|
||||
h1 = "Handshake-init header or range (H1).";
|
||||
h2 = "Handshake-response header or range (H2).";
|
||||
h3 = "Cookie-reply header or range (H3).";
|
||||
h4 = "Transport-message header or range (H4).";
|
||||
contentPaddingAddition = "AWG 3 content-padding addition or range.";
|
||||
rekeyAfterTime = "AWG 3 rekey interval or range.";
|
||||
rekeyTimeout = "AWG 3 rekey timeout or range.";
|
||||
rejectAfterTime = "AWG 3 reject-after interval or range.";
|
||||
keepaliveTimeout = "AWG 3 keepalive timeout or range.";
|
||||
maxHandshakeAttempts = "AWG 3 maximum handshake attempts or range.";
|
||||
}
|
||||
// lib.mapAttrs (_: optional optionalString) {
|
||||
i1 = "First custom signature packet (I1).";
|
||||
i2 = "Second custom signature packet (I2).";
|
||||
i3 = "Third custom signature packet (I3).";
|
||||
i4 = "Fourth custom signature packet (I4).";
|
||||
i5 = "Fifth custom signature packet (I5).";
|
||||
headerProtectionKey = "Inline AWG 3 header-protection key. Prefer headerProtectionKeyFile.";
|
||||
headerProtectionKeyFile = "Runtime path containing the AWG 3 header-protection key.";
|
||||
}
|
||||
// lib.mapAttrs (_: optional (types.nullOr types.bool)) {
|
||||
randomTrailers = "AWG 3 random transport trailers (RandomTrailers).";
|
||||
disableCookies = "AWG 3 cookie suppression (DisableCookies).";
|
||||
};
|
||||
};
|
||||
|
||||
settingsType = types.submodule {
|
||||
|
||||
@@ -3,13 +3,7 @@
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
inherit (import ./amnezia-wg.nix { inherit lib; }) obfuscationType;
|
||||
nullStr =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
inherit description example;
|
||||
};
|
||||
inherit (import ../lib.nix { inherit lib; }) nullStr;
|
||||
|
||||
userType = types.submodule {
|
||||
options = {
|
||||
|
||||
@@ -2,13 +2,7 @@
|
||||
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
nullStr =
|
||||
description: example:
|
||||
mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
inherit description example;
|
||||
};
|
||||
inherit (import ../lib.nix { inherit lib; }) nullStr;
|
||||
nullAttrs =
|
||||
description: example:
|
||||
mkOption {
|
||||
|
||||
@@ -3,19 +3,7 @@
|
||||
let
|
||||
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;
|
||||
};
|
||||
inherit (import ./lib.nix { inherit lib; }) list bool;
|
||||
in
|
||||
{
|
||||
options.services.proxy-suite.zapret = {
|
||||
|
||||
@@ -2,12 +2,7 @@
|
||||
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
int =
|
||||
default: description:
|
||||
mkOption {
|
||||
type = types.ints.positive;
|
||||
inherit default description;
|
||||
};
|
||||
int = (import ./lib.nix { inherit lib; }).positiveInt;
|
||||
fromSource = what: "null uses the ${what} of strategySource.";
|
||||
in
|
||||
{
|
||||
|
||||
@@ -38,9 +38,10 @@ let
|
||||
requireEnabled =
|
||||
featureEnabled: dependencyEnabled: message:
|
||||
mkAssertion (!featureEnabled || dependencyEnabled) message;
|
||||
requireAvailable =
|
||||
featureUsed: dependencyEnabled: message:
|
||||
mkAssertion (!featureUsed || dependencyEnabled) message;
|
||||
# The shape of nearly every dependency assertion: "<used> requires <dependency> = true".
|
||||
requires =
|
||||
used: dependency: usedLabel: dependencyLabel:
|
||||
mkAssertion (!used || dependency) "proxy-suite: ${usedLabel} requires ${dependencyLabel} = true";
|
||||
uniqueValues =
|
||||
condition: values: message:
|
||||
mkAssertion (!condition || builtins.length values == builtins.length (lib.unique values)) message;
|
||||
@@ -55,6 +56,13 @@ let
|
||||
forbiddenValues =
|
||||
condition: value: disallowed: message:
|
||||
mkAssertion (!(condition && builtins.elem value disallowed)) message;
|
||||
# Two values that must not coincide; the message names the config that conflicts them.
|
||||
distinct =
|
||||
condition: left: right: message:
|
||||
notEqualWhen condition left right "proxy-suite: ${message}";
|
||||
positive =
|
||||
condition: value: label:
|
||||
mkAssertion (!condition || value > 0) "proxy-suite: ${label} must be greater than zero";
|
||||
|
||||
# Every loopback listener proxy-suite opens with a fixed port of its own, which
|
||||
# the autoProxy prober's range must stay clear of.
|
||||
@@ -238,54 +246,49 @@ let
|
||||
)
|
||||
];
|
||||
|
||||
# Each case reads "<used> requires <dependency> = true", with option paths as labels.
|
||||
perAppRoutingAssertions = [
|
||||
(requireAvailable (perAppRoutingCfg.profiles != [ ]) perAppRoutingCfg.enable
|
||||
"proxy-suite: perAppRouting.profiles requires perAppRouting.enable = true"
|
||||
(requires (
|
||||
perAppRoutingCfg.profiles != [ ]
|
||||
) perAppRoutingCfg.enable "perAppRouting.profiles" "perAppRouting.enable")
|
||||
(requires perAppRoutingCfg.proxychains.enable perAppRoutingCfg.enable
|
||||
"perAppRouting.proxychains.enable"
|
||||
"perAppRouting.enable"
|
||||
)
|
||||
(requireEnabled perAppRoutingCfg.proxychains.enable perAppRoutingCfg.enable
|
||||
"proxy-suite: perAppRouting.proxychains.enable requires perAppRouting.enable = true"
|
||||
)
|
||||
(requireEnabled perAppRoutingCfg.proxychains.enable proxyEnabled
|
||||
"proxy-suite: perAppRouting.proxychains.enable requires proxy.enable = true"
|
||||
(requires perAppRoutingCfg.proxychains.enable proxyEnabled "perAppRouting.proxychains.enable"
|
||||
"proxy.enable"
|
||||
)
|
||||
(uniqueValues true effectivePerAppRoutingProfileNames
|
||||
"proxy-suite: perAppRouting profile names must be unique"
|
||||
)
|
||||
(requireAvailable hasProxychainsProfiles perAppRoutingCfg.proxychains.enable
|
||||
"proxy-suite: route=proxychains in perAppRouting.profiles requires perAppRouting.proxychains.enable = true"
|
||||
(requires hasProxychainsProfiles perAppRoutingCfg.proxychains.enable
|
||||
"route=proxychains in perAppRouting.profiles"
|
||||
"perAppRouting.proxychains.enable"
|
||||
)
|
||||
(requireAvailable hasProxychainsProfiles proxyEnabled
|
||||
"proxy-suite: route=proxychains in perAppRouting.profiles requires proxy.enable = true"
|
||||
(requires hasProxychainsProfiles proxyEnabled "route=proxychains in perAppRouting.profiles"
|
||||
"proxy.enable"
|
||||
)
|
||||
(requireEnabled perAppRoutingTun.enable perAppRoutingCfg.enable
|
||||
"proxy-suite: perAppRouting.tun.enable requires perAppRouting.enable = true"
|
||||
(requires perAppRoutingTun.enable perAppRoutingCfg.enable "perAppRouting.tun.enable"
|
||||
"perAppRouting.enable"
|
||||
)
|
||||
(requireEnabled perAppRoutingTun.enable proxyEnabled
|
||||
"proxy-suite: perAppRouting.tun.enable requires proxy.enable = true"
|
||||
(requires perAppRoutingTun.enable proxyEnabled "perAppRouting.tun.enable" "proxy.enable")
|
||||
(requires hasTunProfiles perAppRoutingTun.enable "route=tun in perAppRouting.profiles"
|
||||
"perAppRouting.tun.enable"
|
||||
)
|
||||
(requireAvailable hasTunProfiles perAppRoutingTun.enable
|
||||
"proxy-suite: route=tun in perAppRouting.profiles requires perAppRouting.tun.enable = true"
|
||||
(requires hasTunProfiles proxyEnabled "route=tun in perAppRouting.profiles" "proxy.enable")
|
||||
(requires perAppRoutingTproxy.enable perAppRoutingCfg.enable "perAppRouting.tproxy.enable"
|
||||
"perAppRouting.enable"
|
||||
)
|
||||
(requireAvailable hasTunProfiles proxyEnabled
|
||||
"proxy-suite: route=tun in perAppRouting.profiles requires proxy.enable = true"
|
||||
(requires perAppRoutingTproxy.enable proxyEnabled "perAppRouting.tproxy.enable" "proxy.enable")
|
||||
(requires hasTproxyProfiles perAppRoutingTproxy.enable "route=tproxy in perAppRouting.profiles"
|
||||
"perAppRouting.tproxy.enable"
|
||||
)
|
||||
(requireEnabled perAppRoutingTproxy.enable perAppRoutingCfg.enable
|
||||
"proxy-suite: perAppRouting.tproxy.enable requires perAppRouting.enable = true"
|
||||
(requires hasTproxyProfiles proxyEnabled "route=tproxy in perAppRouting.profiles" "proxy.enable")
|
||||
(requires perAppZapretCfg.enable perAppRoutingCfg.enable "perAppRouting.zapret.enable"
|
||||
"perAppRouting.enable"
|
||||
)
|
||||
(requireEnabled perAppRoutingTproxy.enable proxyEnabled
|
||||
"proxy-suite: perAppRouting.tproxy.enable requires proxy.enable = true"
|
||||
)
|
||||
(requireAvailable hasTproxyProfiles perAppRoutingTproxy.enable
|
||||
"proxy-suite: route=tproxy in perAppRouting.profiles requires perAppRouting.tproxy.enable = true"
|
||||
)
|
||||
(requireAvailable hasTproxyProfiles proxyEnabled
|
||||
"proxy-suite: route=tproxy in perAppRouting.profiles requires proxy.enable = true"
|
||||
)
|
||||
(requireEnabled perAppZapretCfg.enable perAppRoutingCfg.enable
|
||||
"proxy-suite: perAppRouting.zapret.enable requires perAppRouting.enable = true"
|
||||
)
|
||||
(requireAvailable hasZapretProfiles perAppZapretCfg.enable
|
||||
"proxy-suite: route=zapret in perAppRouting.profiles requires perAppRouting.zapret.enable = true"
|
||||
(requires hasZapretProfiles perAppZapretCfg.enable "route=zapret in perAppRouting.profiles"
|
||||
"perAppRouting.zapret.enable"
|
||||
)
|
||||
];
|
||||
|
||||
@@ -528,7 +531,7 @@ let
|
||||
(mkAssertion (
|
||||
!proxyInboundsEnabled || !l.reality.enable || l.reality.serverNames != [ ]
|
||||
) "${prefix}: reality.serverNames must not be empty")
|
||||
(requireAvailable (proxyInboundsEnabled && l.reality.enable && proxyInboundsCfg.shareLinks)
|
||||
(requireEnabled (proxyInboundsEnabled && l.reality.enable && proxyInboundsCfg.shareLinks)
|
||||
(l.reality.publicKey != null)
|
||||
"${prefix}: reality.publicKey is required to generate share links. Run `xray x25519` to print it alongside the private key, or set inbounds.shareLinks = false."
|
||||
)
|
||||
@@ -692,254 +695,132 @@ let
|
||||
|
||||
globalTunAutoRouteTable = constants.tunAutoRouteTableIndex;
|
||||
globalZapretQnum = constants.zapretGlobalQnum.${zapretEngine};
|
||||
collisionAssertions = map (item: notEqualWhen item.condition item.left item.right item.message) [
|
||||
{
|
||||
condition = globalTun.enable && perAppRoutingTun.enable;
|
||||
left = globalTun.interface;
|
||||
right = perAppRoutingTun.interface;
|
||||
message = "proxy-suite: proxy.tun.interface and perAppRouting.tun.interface must differ";
|
||||
}
|
||||
{
|
||||
condition = globalTun.enable && perAppRoutingTun.enable;
|
||||
left = globalTun.address;
|
||||
right = perAppRoutingTun.address;
|
||||
message = "proxy-suite: proxy.tun.address and perAppRouting.tun.address must differ";
|
||||
}
|
||||
{
|
||||
condition = globalTun.enable && perAppRoutingTun.enable;
|
||||
left = perAppRoutingTun.routeTable;
|
||||
right = globalTunAutoRouteTable;
|
||||
message = "proxy-suite: perAppRouting.tun.routeTable must differ from the global TUN auto-route table ${toString globalTunAutoRouteTable}";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTun.enable && globalTproxy.enable;
|
||||
left = perAppRoutingTun.fwmark;
|
||||
right = globalTproxy.fwmark;
|
||||
message = "proxy-suite: perAppRouting.tun.fwmark must differ from proxy.tproxy.fwmark when global TProxy is enabled";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTun.enable && globalTproxy.enable;
|
||||
left = perAppRoutingTun.fwmark;
|
||||
right = globalTproxy.proxyMark;
|
||||
message = "proxy-suite: perAppRouting.tun.fwmark must differ from proxy.tproxy.proxyMark when global TProxy is enabled";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTun.enable && globalTproxy.enable;
|
||||
left = perAppRoutingTun.routeTable;
|
||||
right = globalTproxy.routeTable;
|
||||
message = "proxy-suite: perAppRouting.tun.routeTable must differ from proxy.tproxy.routeTable when global TProxy is enabled";
|
||||
}
|
||||
{
|
||||
condition = perAppZapretCfg.enable && zapretCfg.enable;
|
||||
left = perAppZapretCfg.qnum;
|
||||
right = globalZapretQnum;
|
||||
message = "proxy-suite: perAppRouting.zapret.qnum must differ from the global zapret instance's NFQUEUE ${toString globalZapretQnum}";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTproxy.enable;
|
||||
left = perAppRoutingTproxy.fwmark;
|
||||
right = globalTproxy.fwmark;
|
||||
message = "proxy-suite: perAppRouting.tproxy.fwmark must differ from proxy.tproxy.fwmark";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTproxy.enable;
|
||||
left = perAppRoutingTproxy.fwmark;
|
||||
right = globalTproxy.proxyMark;
|
||||
message = "proxy-suite: perAppRouting.tproxy.fwmark must differ from proxy.tproxy.proxyMark";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTproxy.enable;
|
||||
left = perAppRoutingTproxy.routeTable;
|
||||
right = globalTproxy.routeTable;
|
||||
message = "proxy-suite: perAppRouting.tproxy.routeTable must differ from proxy.tproxy.routeTable";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTun.enable && perAppRoutingTproxy.enable;
|
||||
left = perAppRoutingTun.fwmark;
|
||||
right = perAppRoutingTproxy.fwmark;
|
||||
message = "proxy-suite: perAppRouting.tun.fwmark and perAppRouting.tproxy.fwmark must differ";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTun.enable && perAppRoutingTproxy.enable;
|
||||
left = perAppRoutingTun.routeTable;
|
||||
right = perAppRoutingTproxy.routeTable;
|
||||
message = "proxy-suite: perAppRouting.tun.routeTable and perAppRouting.tproxy.routeTable must differ";
|
||||
}
|
||||
{
|
||||
condition = perAppZapretCfg.enable;
|
||||
left = perAppZapretCfg.filterMark;
|
||||
right = globalTproxy.fwmark;
|
||||
message = "proxy-suite: perAppRouting.zapret.filterMark must differ from proxy.tproxy.fwmark";
|
||||
}
|
||||
{
|
||||
condition = perAppZapretCfg.enable;
|
||||
left = perAppZapretCfg.filterMark;
|
||||
right = globalTproxy.proxyMark;
|
||||
message = "proxy-suite: perAppRouting.zapret.filterMark must differ from proxy.tproxy.proxyMark";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTun.enable && perAppZapretCfg.enable;
|
||||
left = perAppRoutingTun.fwmark;
|
||||
right = perAppZapretCfg.filterMark;
|
||||
message = "proxy-suite: perAppRouting.tun.fwmark and perAppRouting.zapret.filterMark must differ";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTproxy.enable && perAppZapretCfg.enable;
|
||||
left = perAppRoutingTproxy.fwmark;
|
||||
right = perAppZapretCfg.filterMark;
|
||||
message = "proxy-suite: perAppRouting.tproxy.fwmark and perAppRouting.zapret.filterMark must differ";
|
||||
}
|
||||
{
|
||||
condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && globalTproxy.enable;
|
||||
left = tgWsProxyCfg.fwmark;
|
||||
right = globalTproxy.fwmark;
|
||||
message = "proxy-suite: tgWsProxy.fwmark must differ from proxy.tproxy.fwmark";
|
||||
}
|
||||
{
|
||||
condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && globalTproxy.enable;
|
||||
left = tgWsProxyCfg.fwmark;
|
||||
right = globalTproxy.proxyMark;
|
||||
message = "proxy-suite: tgWsProxy.fwmark must differ from proxy.tproxy.proxyMark";
|
||||
}
|
||||
{
|
||||
condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && perAppRoutingTun.enable;
|
||||
left = tgWsProxyCfg.fwmark;
|
||||
right = perAppRoutingTun.fwmark;
|
||||
message = "proxy-suite: tgWsProxy.fwmark must differ from perAppRouting.tun.fwmark";
|
||||
}
|
||||
{
|
||||
condition =
|
||||
tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && perAppRoutingTproxy.enable;
|
||||
left = tgWsProxyCfg.fwmark;
|
||||
right = perAppRoutingTproxy.fwmark;
|
||||
message = "proxy-suite: tgWsProxy.fwmark must differ from perAppRouting.tproxy.fwmark";
|
||||
}
|
||||
{
|
||||
condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && perAppZapretCfg.enable;
|
||||
left = tgWsProxyCfg.fwmark;
|
||||
right = perAppZapretCfg.filterMark;
|
||||
message = "proxy-suite: tgWsProxy.fwmark must differ from perAppRouting.zapret.filterMark";
|
||||
}
|
||||
];
|
||||
collisionAssertions =
|
||||
let
|
||||
bothTun = globalTun.enable && perAppRoutingTun.enable;
|
||||
perAppTunWithTproxy = perAppRoutingTun.enable && globalTproxy.enable;
|
||||
bothPerApp = perAppRoutingTun.enable && perAppRoutingTproxy.enable;
|
||||
tgWsBypass = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy;
|
||||
in
|
||||
[
|
||||
(distinct bothTun globalTun.interface perAppRoutingTun.interface
|
||||
"proxy.tun.interface and perAppRouting.tun.interface must differ"
|
||||
)
|
||||
(distinct bothTun globalTun.address perAppRoutingTun.address
|
||||
"proxy.tun.address and perAppRouting.tun.address must differ"
|
||||
)
|
||||
(distinct bothTun perAppRoutingTun.routeTable globalTunAutoRouteTable
|
||||
"perAppRouting.tun.routeTable must differ from the global TUN auto-route table ${toString globalTunAutoRouteTable}"
|
||||
)
|
||||
(distinct perAppTunWithTproxy perAppRoutingTun.fwmark globalTproxy.fwmark
|
||||
"perAppRouting.tun.fwmark must differ from proxy.tproxy.fwmark when global TProxy is enabled"
|
||||
)
|
||||
(distinct perAppTunWithTproxy perAppRoutingTun.fwmark globalTproxy.proxyMark
|
||||
"perAppRouting.tun.fwmark must differ from proxy.tproxy.proxyMark when global TProxy is enabled"
|
||||
)
|
||||
(distinct perAppTunWithTproxy perAppRoutingTun.routeTable globalTproxy.routeTable
|
||||
"perAppRouting.tun.routeTable must differ from proxy.tproxy.routeTable when global TProxy is enabled"
|
||||
)
|
||||
(distinct (perAppZapretCfg.enable && zapretCfg.enable) perAppZapretCfg.qnum globalZapretQnum
|
||||
"perAppRouting.zapret.qnum must differ from the global zapret instance's NFQUEUE ${toString globalZapretQnum}"
|
||||
)
|
||||
(distinct perAppRoutingTproxy.enable perAppRoutingTproxy.fwmark globalTproxy.fwmark
|
||||
"perAppRouting.tproxy.fwmark must differ from proxy.tproxy.fwmark"
|
||||
)
|
||||
(distinct perAppRoutingTproxy.enable perAppRoutingTproxy.fwmark globalTproxy.proxyMark
|
||||
"perAppRouting.tproxy.fwmark must differ from proxy.tproxy.proxyMark"
|
||||
)
|
||||
(distinct perAppRoutingTproxy.enable perAppRoutingTproxy.routeTable globalTproxy.routeTable
|
||||
"perAppRouting.tproxy.routeTable must differ from proxy.tproxy.routeTable"
|
||||
)
|
||||
(distinct bothPerApp perAppRoutingTun.fwmark perAppRoutingTproxy.fwmark
|
||||
"perAppRouting.tun.fwmark and perAppRouting.tproxy.fwmark must differ"
|
||||
)
|
||||
(distinct bothPerApp perAppRoutingTun.routeTable perAppRoutingTproxy.routeTable
|
||||
"perAppRouting.tun.routeTable and perAppRouting.tproxy.routeTable must differ"
|
||||
)
|
||||
(distinct perAppZapretCfg.enable perAppZapretCfg.filterMark globalTproxy.fwmark
|
||||
"perAppRouting.zapret.filterMark must differ from proxy.tproxy.fwmark"
|
||||
)
|
||||
(distinct perAppZapretCfg.enable perAppZapretCfg.filterMark globalTproxy.proxyMark
|
||||
"perAppRouting.zapret.filterMark must differ from proxy.tproxy.proxyMark"
|
||||
)
|
||||
(distinct (perAppRoutingTun.enable && perAppZapretCfg.enable) perAppRoutingTun.fwmark
|
||||
perAppZapretCfg.filterMark
|
||||
"perAppRouting.tun.fwmark and perAppRouting.zapret.filterMark must differ"
|
||||
)
|
||||
(distinct (perAppRoutingTproxy.enable && perAppZapretCfg.enable) perAppRoutingTproxy.fwmark
|
||||
perAppZapretCfg.filterMark
|
||||
"perAppRouting.tproxy.fwmark and perAppRouting.zapret.filterMark must differ"
|
||||
)
|
||||
(distinct (
|
||||
tgWsBypass && globalTproxy.enable
|
||||
) tgWsProxyCfg.fwmark globalTproxy.fwmark "tgWsProxy.fwmark must differ from proxy.tproxy.fwmark")
|
||||
(distinct (tgWsBypass && globalTproxy.enable) tgWsProxyCfg.fwmark globalTproxy.proxyMark
|
||||
"tgWsProxy.fwmark must differ from proxy.tproxy.proxyMark"
|
||||
)
|
||||
(distinct (tgWsBypass && perAppRoutingTun.enable) tgWsProxyCfg.fwmark perAppRoutingTun.fwmark
|
||||
"tgWsProxy.fwmark must differ from perAppRouting.tun.fwmark"
|
||||
)
|
||||
(distinct (tgWsBypass && perAppRoutingTproxy.enable) tgWsProxyCfg.fwmark perAppRoutingTproxy.fwmark
|
||||
"tgWsProxy.fwmark must differ from perAppRouting.tproxy.fwmark"
|
||||
)
|
||||
(distinct (tgWsBypass && perAppZapretCfg.enable) tgWsProxyCfg.fwmark perAppZapretCfg.filterMark
|
||||
"tgWsProxy.fwmark must differ from perAppRouting.zapret.filterMark"
|
||||
)
|
||||
];
|
||||
|
||||
perAppZapretDesyncMarks = [
|
||||
67108864
|
||||
134217728
|
||||
];
|
||||
positiveNumberAssertions =
|
||||
map (item: mkAssertion (!item.condition || item.value > 0) item.message)
|
||||
[
|
||||
{
|
||||
condition = globalTun.enable;
|
||||
value = globalTun.mtu;
|
||||
message = "proxy-suite: proxy.tun.mtu must be greater than zero";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTun.enable;
|
||||
value = perAppRoutingTun.mtu;
|
||||
message = "proxy-suite: perAppRouting.tun.mtu must be greater than zero";
|
||||
}
|
||||
{
|
||||
condition = globalTproxy.enable;
|
||||
value = globalTproxy.fwmark;
|
||||
message = "proxy-suite: proxy.tproxy.fwmark must be greater than zero";
|
||||
}
|
||||
{
|
||||
condition = globalTproxy.enable;
|
||||
value = globalTproxy.proxyMark;
|
||||
message = "proxy-suite: proxy.tproxy.proxyMark must be greater than zero";
|
||||
}
|
||||
{
|
||||
condition = globalTproxy.enable;
|
||||
value = globalTproxy.routeTable;
|
||||
message = "proxy-suite: proxy.tproxy.routeTable must be greater than zero";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTun.enable;
|
||||
value = perAppRoutingTun.fwmark;
|
||||
message = "proxy-suite: perAppRouting.tun.fwmark must be greater than zero";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTun.enable;
|
||||
value = perAppRoutingTun.routeTable;
|
||||
message = "proxy-suite: perAppRouting.tun.routeTable must be greater than zero";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTproxy.enable;
|
||||
value = perAppRoutingTproxy.fwmark;
|
||||
message = "proxy-suite: perAppRouting.tproxy.fwmark must be greater than zero";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTproxy.enable;
|
||||
value = perAppRoutingTproxy.routeTable;
|
||||
message = "proxy-suite: perAppRouting.tproxy.routeTable must be greater than zero";
|
||||
}
|
||||
{
|
||||
condition = perAppZapretCfg.enable;
|
||||
value = perAppZapretCfg.filterMark;
|
||||
message = "proxy-suite: perAppRouting.zapret.filterMark must be greater than zero";
|
||||
}
|
||||
{
|
||||
condition = perAppZapretCfg.enable;
|
||||
value = perAppZapretCfg.qnum;
|
||||
message = "proxy-suite: perAppRouting.zapret.qnum must be greater than zero";
|
||||
}
|
||||
{
|
||||
condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy;
|
||||
value = tgWsProxyCfg.fwmark;
|
||||
message = "proxy-suite: tgWsProxy.fwmark must be greater than zero";
|
||||
}
|
||||
];
|
||||
positiveNumberAssertions = [
|
||||
(positive globalTun.enable globalTun.mtu "proxy.tun.mtu")
|
||||
(positive perAppRoutingTun.enable perAppRoutingTun.mtu "perAppRouting.tun.mtu")
|
||||
(positive globalTproxy.enable globalTproxy.fwmark "proxy.tproxy.fwmark")
|
||||
(positive globalTproxy.enable globalTproxy.proxyMark "proxy.tproxy.proxyMark")
|
||||
(positive globalTproxy.enable globalTproxy.routeTable "proxy.tproxy.routeTable")
|
||||
(positive perAppRoutingTun.enable perAppRoutingTun.fwmark "perAppRouting.tun.fwmark")
|
||||
(positive perAppRoutingTun.enable perAppRoutingTun.routeTable "perAppRouting.tun.routeTable")
|
||||
(positive perAppRoutingTproxy.enable perAppRoutingTproxy.fwmark "perAppRouting.tproxy.fwmark")
|
||||
(positive perAppRoutingTproxy.enable perAppRoutingTproxy.routeTable
|
||||
"perAppRouting.tproxy.routeTable"
|
||||
)
|
||||
(positive perAppZapretCfg.enable perAppZapretCfg.filterMark "perAppRouting.zapret.filterMark")
|
||||
(positive perAppZapretCfg.enable perAppZapretCfg.qnum "perAppRouting.zapret.qnum")
|
||||
(positive (
|
||||
tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy
|
||||
) tgWsProxyCfg.fwmark "tgWsProxy.fwmark")
|
||||
];
|
||||
|
||||
forbiddenValueAssertions =
|
||||
map (item: forbiddenValues item.condition item.value item.disallowed item.message)
|
||||
[
|
||||
{
|
||||
condition = perAppZapretCfg.enable;
|
||||
value = perAppZapretCfg.filterMark;
|
||||
disallowed = [
|
||||
536870912
|
||||
1073741824
|
||||
];
|
||||
message = "proxy-suite: perAppRouting.zapret.filterMark must not use zapret internal desync mark bits";
|
||||
}
|
||||
{
|
||||
condition = perAppZapretCfg.enable;
|
||||
value = globalTproxy.fwmark;
|
||||
disallowed = perAppZapretDesyncMarks;
|
||||
message = "proxy-suite: proxy.tproxy.fwmark must not use per-app-zapret internal desync mark bits";
|
||||
}
|
||||
{
|
||||
condition = perAppZapretCfg.enable;
|
||||
value = globalTproxy.proxyMark;
|
||||
disallowed = perAppZapretDesyncMarks;
|
||||
message = "proxy-suite: proxy.tproxy.proxyMark must not use per-app-zapret internal desync mark bits";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTun.enable && perAppZapretCfg.enable;
|
||||
value = perAppRoutingTun.fwmark;
|
||||
disallowed = perAppZapretDesyncMarks;
|
||||
message = "proxy-suite: perAppRouting.tun.fwmark must not use per-app-zapret internal desync mark bits";
|
||||
}
|
||||
{
|
||||
condition = perAppRoutingTproxy.enable && perAppZapretCfg.enable;
|
||||
value = perAppRoutingTproxy.fwmark;
|
||||
disallowed = perAppZapretDesyncMarks;
|
||||
message = "proxy-suite: perAppRouting.tproxy.fwmark must not use per-app-zapret internal desync mark bits";
|
||||
}
|
||||
{
|
||||
condition = perAppZapretCfg.enable;
|
||||
value = perAppZapretCfg.filterMark;
|
||||
disallowed = perAppZapretDesyncMarks;
|
||||
message = "proxy-suite: perAppRouting.zapret.filterMark must not use per-app-zapret internal desync mark bits";
|
||||
}
|
||||
{
|
||||
condition = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy && perAppZapretCfg.enable;
|
||||
value = tgWsProxyCfg.fwmark;
|
||||
disallowed = perAppZapretDesyncMarks;
|
||||
message = "proxy-suite: tgWsProxy.fwmark must not use per-app-zapret internal desync mark bits";
|
||||
}
|
||||
let
|
||||
# zapret's own desync marks: v1's pair, and the bits nfqws2 sets for per-app zapret.
|
||||
zapretInternalMarks = [
|
||||
536870912
|
||||
1073741824
|
||||
];
|
||||
noDesyncBits =
|
||||
condition: value: label:
|
||||
forbiddenValues condition value perAppZapretDesyncMarks
|
||||
"proxy-suite: ${label} must not use per-app-zapret internal desync mark bits";
|
||||
tgWsBypass = tgWsProxyCfg.enable && tgWsProxyCfg.bypassTransparentProxy;
|
||||
in
|
||||
[
|
||||
(forbiddenValues perAppZapretCfg.enable perAppZapretCfg.filterMark zapretInternalMarks
|
||||
"proxy-suite: perAppRouting.zapret.filterMark must not use zapret internal desync mark bits"
|
||||
)
|
||||
(noDesyncBits perAppZapretCfg.enable globalTproxy.fwmark "proxy.tproxy.fwmark")
|
||||
(noDesyncBits perAppZapretCfg.enable globalTproxy.proxyMark "proxy.tproxy.proxyMark")
|
||||
(noDesyncBits (
|
||||
perAppRoutingTun.enable && perAppZapretCfg.enable
|
||||
) perAppRoutingTun.fwmark "perAppRouting.tun.fwmark")
|
||||
(noDesyncBits (
|
||||
perAppRoutingTproxy.enable && perAppZapretCfg.enable
|
||||
) perAppRoutingTproxy.fwmark "perAppRouting.tproxy.fwmark")
|
||||
(noDesyncBits perAppZapretCfg.enable perAppZapretCfg.filterMark "perAppRouting.zapret.filterMark")
|
||||
(noDesyncBits (tgWsBypass && perAppZapretCfg.enable) tgWsProxyCfg.fwmark "tgWsProxy.fwmark")
|
||||
];
|
||||
|
||||
torCfg = cfg.tor;
|
||||
torOnionListeners =
|
||||
|
||||
@@ -13,54 +13,15 @@
|
||||
perAppTunChainFile,
|
||||
perAppTproxyRulesFile,
|
||||
perAppZapretRulesFile,
|
||||
nftablesRulesFile,
|
||||
ip,
|
||||
nft,
|
||||
}:
|
||||
|
||||
let
|
||||
derived = import ../derived.nix { inherit lib cfg; };
|
||||
constants = derived.constants;
|
||||
inherit (derived)
|
||||
singBoxCfg
|
||||
proxyCfg
|
||||
xrayCfg
|
||||
proxyEnabled
|
||||
singBoxEnabled
|
||||
xrayEnabled
|
||||
hybridEnabled
|
||||
pureXrayEnabled
|
||||
activeBackend
|
||||
perAppRoutingCfg
|
||||
globalTun
|
||||
globalTproxy
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
zapretEngine
|
||||
zapretCutoffEnabled
|
||||
zapretCutoffProxyFallback
|
||||
userControlCfg
|
||||
selectionMode
|
||||
builtinTags
|
||||
outboundTags
|
||||
subscriptionTags
|
||||
invalidRoutingTargets
|
||||
collapseNamedOutbounds
|
||||
sshProxyCfg
|
||||
sshProxyOutboundEnabled
|
||||
sshProxyUnitEnabled
|
||||
warpCfg
|
||||
torCfg
|
||||
awgOutbounds
|
||||
proxyInboundsCfg
|
||||
proxyInboundsEnabled
|
||||
proxyInboundsAwg
|
||||
proxyInboundsNeedLocalProxy
|
||||
torOnionEnabled
|
||||
proxyInboundsGuardPrivate
|
||||
proxyInboundViaOutbounds
|
||||
userControlAllows
|
||||
;
|
||||
# Only what this file itself needs; the rest reaches the sub-modules through ctx.
|
||||
inherit (derived) singBoxCfg xrayCfg userControlCfg;
|
||||
|
||||
# Tool paths – defined once here and passed into sub-modules as needed.
|
||||
jq = "${pkgs.jq}/bin/jq";
|
||||
@@ -81,10 +42,7 @@ let
|
||||
)
|
||||
);
|
||||
|
||||
proxySuiteScriptsDir = builtins.path {
|
||||
name = "proxy-suite-scripts";
|
||||
path = ../../../scripts;
|
||||
};
|
||||
proxySuiteScriptsDir = import ../lib/scripts-dir.nix { inherit lib; };
|
||||
parserScriptsPythonPath = proxySuiteScriptsDir;
|
||||
buildOutboundPy = "${proxySuiteScriptsDir}/build-outbound.py";
|
||||
buildInboundPy = "${proxySuiteScriptsDir}/build-inbound.py";
|
||||
@@ -94,36 +52,38 @@ let
|
||||
|
||||
polkit = import ./polkit.nix { inherit userControlCfg; };
|
||||
|
||||
scripts = import ./scripts.nix {
|
||||
# One context for the service layer: everything derived.nix computes, the tool paths and
|
||||
# generated files above, and the shell-snippet builders. Sub-modules take it whole and
|
||||
# `inherit` the names they use, so adding a value needs no plumbing in between.
|
||||
ctx = derived // {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
singBoxCfg
|
||||
proxyCfg
|
||||
sshProxyCfg
|
||||
warpCfg
|
||||
torCfg
|
||||
awgOutbounds
|
||||
xrayEnabled
|
||||
hybridEnabled
|
||||
pureXrayEnabled
|
||||
activeBackend
|
||||
perAppRoutingCfg
|
||||
userControlCfg
|
||||
selectionMode
|
||||
collapseNamedOutbounds
|
||||
constants
|
||||
zapretCutoffProxyFallback
|
||||
packages
|
||||
cfg
|
||||
builders
|
||||
polkit
|
||||
;
|
||||
inherit
|
||||
jq
|
||||
python3
|
||||
singBox
|
||||
xray
|
||||
grepBin
|
||||
awk
|
||||
sleepBin
|
||||
headBin
|
||||
seqBin
|
||||
findBin
|
||||
awgBin
|
||||
;
|
||||
inherit
|
||||
proxySuiteScriptsDir
|
||||
parserScriptsPythonPath
|
||||
buildOutboundPy
|
||||
buildInboundPy
|
||||
fetchSubscriptionPy
|
||||
amneziaWgProfileNamesFile
|
||||
;
|
||||
inherit
|
||||
tproxyFile
|
||||
@@ -132,102 +92,28 @@ let
|
||||
routeModeRulesFile
|
||||
proxyInboundsFile
|
||||
proxyInboundsSpecFile
|
||||
perAppTunChainFile
|
||||
perAppTproxyRulesFile
|
||||
perAppZapretRulesFile
|
||||
nftablesRulesFile
|
||||
ip
|
||||
nft
|
||||
;
|
||||
inherit
|
||||
proxyInboundsCfg
|
||||
proxyInboundsAwg
|
||||
awgBin
|
||||
proxyInboundsNeedLocalProxy
|
||||
torOnionEnabled
|
||||
proxyInboundsGuardPrivate
|
||||
proxyInboundViaOutbounds
|
||||
userControlAllows
|
||||
builders
|
||||
;
|
||||
# Filled in below; lazily, so the sub-modules can read each other's results.
|
||||
inherit scripts perAppRouting;
|
||||
};
|
||||
|
||||
perAppRouting = import ./per-app-routing.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
cfg
|
||||
singBoxCfg
|
||||
proxyCfg
|
||||
perAppRoutingCfg
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
constants
|
||||
;
|
||||
perAppZapretCfg = perAppZapretCfg;
|
||||
inherit perAppTunChainFile perAppTproxyRulesFile perAppZapretRulesFile;
|
||||
inherit ip nft;
|
||||
inherit
|
||||
awk
|
||||
grepBin
|
||||
findBin
|
||||
headBin
|
||||
seqBin
|
||||
sleepBin
|
||||
;
|
||||
};
|
||||
|
||||
control = import ./control.nix {
|
||||
inherit
|
||||
packages
|
||||
singBoxCfg
|
||||
proxyCfg
|
||||
perAppRoutingCfg
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
zapretEngine
|
||||
zapretCutoffEnabled
|
||||
constants
|
||||
selectionMode
|
||||
userControlCfg
|
||||
;
|
||||
inherit (scripts) subscriptionTagsFile subscriptionCacheDir;
|
||||
inherit (scripts) routeModeStateFile;
|
||||
inherit proxyInboundsEnabled;
|
||||
inherit (scripts) proxyInboundsLinksFile proxyInboundsSubscriptionsFile;
|
||||
proxyInboundsSubscriptionsBaseUrl = proxyInboundsCfg.subscriptions.baseUrl;
|
||||
proxyInboundsXray = "${proxyInboundsCfg.package}/bin/xray";
|
||||
inherit amneziaWgProfileNamesFile;
|
||||
guiRefreshInterval = cfg.gui.refreshInterval;
|
||||
inherit (perAppRouting)
|
||||
perAppRoutingProfilesFile
|
||||
proxychainsConfigFile
|
||||
proxychainsQuietArg
|
||||
;
|
||||
};
|
||||
scripts = import ./scripts.nix { inherit ctx; };
|
||||
perAppRouting = import ./per-app-routing.nix { inherit ctx; };
|
||||
control = import ./control.nix { inherit ctx; };
|
||||
in
|
||||
{
|
||||
inherit
|
||||
ctx
|
||||
derived
|
||||
singBoxCfg
|
||||
proxyCfg
|
||||
xrayCfg
|
||||
proxyEnabled
|
||||
singBoxEnabled
|
||||
xrayEnabled
|
||||
hybridEnabled
|
||||
pureXrayEnabled
|
||||
activeBackend
|
||||
perAppRoutingCfg
|
||||
globalTun
|
||||
globalTproxy
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
userControlCfg
|
||||
builtinTags
|
||||
outboundTags
|
||||
subscriptionTags
|
||||
invalidRoutingTargets
|
||||
polkit
|
||||
scripts
|
||||
perAppRouting
|
||||
control
|
||||
amneziaWgProfileNamesFile
|
||||
;
|
||||
}
|
||||
@@ -52,15 +52,7 @@ let
|
||||
mode="''${1:-}"
|
||||
|
||||
case "$mode" in
|
||||
default)
|
||||
;;
|
||||
whitelist)
|
||||
;;
|
||||
blacklist)
|
||||
;;
|
||||
all-proxy)
|
||||
;;
|
||||
all-bypass)
|
||||
default | whitelist | blacklist | all-proxy | all-bypass)
|
||||
;;
|
||||
*)
|
||||
echo "proxy-suite: route mode must be default, whitelist, blacklist, all-proxy, or all-bypass" >&2
|
||||
|
||||
@@ -1,75 +1,97 @@
|
||||
# Builds proxy-ctl from global proxy-suite state and per-app routing metadata.
|
||||
{
|
||||
packages,
|
||||
singBoxCfg,
|
||||
proxyCfg,
|
||||
perAppRoutingCfg,
|
||||
perAppRoutingTun,
|
||||
perAppRoutingTproxy,
|
||||
perAppZapretCfg,
|
||||
zapretEngine,
|
||||
zapretCutoffEnabled,
|
||||
constants,
|
||||
selectionMode,
|
||||
userControlCfg,
|
||||
subscriptionTagsFile,
|
||||
subscriptionCacheDir,
|
||||
perAppRoutingProfilesFile,
|
||||
proxychainsConfigFile,
|
||||
proxychainsQuietArg,
|
||||
routeModeStateFile,
|
||||
amneziaWgProfileNamesFile,
|
||||
proxyInboundsEnabled,
|
||||
proxyInboundsLinksFile,
|
||||
proxyInboundsSubscriptionsFile,
|
||||
proxyInboundsSubscriptionsBaseUrl,
|
||||
proxyInboundsXray,
|
||||
guiRefreshInterval,
|
||||
}:
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
inherit (ctx)
|
||||
lib
|
||||
localProxy
|
||||
packages
|
||||
cfg
|
||||
singBoxCfg
|
||||
proxyCfg
|
||||
perAppRoutingCfg
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
zapretEngine
|
||||
zapretCutoffEnabled
|
||||
constants
|
||||
selectionMode
|
||||
userControlCfg
|
||||
proxyInboundsCfg
|
||||
proxyInboundsEnabled
|
||||
amneziaWgProfileNamesFile
|
||||
;
|
||||
inherit (ctx.scripts)
|
||||
subscriptionTagsFile
|
||||
subscriptionCacheDir
|
||||
routeModeStateFile
|
||||
proxyInboundsLinksFile
|
||||
proxyInboundsSubscriptionsFile
|
||||
;
|
||||
inherit (ctx.perAppRouting)
|
||||
perAppRoutingProfilesFile
|
||||
proxychainsConfigFile
|
||||
proxychainsQuietArg
|
||||
;
|
||||
proxyInboundsSubscriptionsBaseUrl = proxyInboundsCfg.subscriptions.baseUrl;
|
||||
proxyInboundsXray = "${proxyInboundsCfg.package}/bin/xray";
|
||||
guiRefreshInterval = cfg.gui.refreshInterval;
|
||||
# proxy_ctl.py reads these as "1"/"0" strings.
|
||||
flag = enabled: if enabled then "1" else "0";
|
||||
in
|
||||
{
|
||||
proxyCtl = packages.mkProxyCtl {
|
||||
clashApi = "http://127.0.0.1:${toString singBoxCfg.clashApiPort}";
|
||||
selection = selectionMode;
|
||||
inherit
|
||||
guiRefreshInterval
|
||||
subscriptionTagsFile
|
||||
subscriptionCacheDir
|
||||
perAppRoutingProfilesFile
|
||||
proxychainsConfigFile
|
||||
proxychainsQuietArg
|
||||
routeModeStateFile
|
||||
amneziaWgProfileNamesFile
|
||||
guiRefreshInterval
|
||||
;
|
||||
defaultRouteMode = if (proxyCfg.routing.default == "proxy") then "blacklist" else "whitelist";
|
||||
perAppRoutingEnabled = if perAppRoutingCfg.enable then "1" else "0";
|
||||
perAppRoutingProxychainsEnabled = if perAppRoutingCfg.proxychains.enable then "1" else "0";
|
||||
perAppRoutingTunEnabled = if perAppRoutingTun.enable then "1" else "0";
|
||||
perAppRoutingTproxyEnabled = if perAppRoutingTproxy.enable then "1" else "0";
|
||||
perAppRoutingZapretEnabled = if perAppZapretCfg.enable then "1" else "0";
|
||||
zapretAutoEnabled = if zapretEngine == "zapret2" then "1" else "0";
|
||||
zapretStateDir = constants.zapret2StateDir;
|
||||
zapretCutoffEnabled = if zapretCutoffEnabled then "1" else "0";
|
||||
outboundInventoryFile = constants.outboundInventoryFile;
|
||||
runtimeOutboundsDir = constants.runtimeOutboundsDir;
|
||||
runtimeSubscriptionsDir = constants.runtimeSubscriptionsDir;
|
||||
userControlGroup = userControlCfg.group;
|
||||
inboundsEnabled = if proxyInboundsEnabled then "1" else "0";
|
||||
inboundsLinksFile = proxyInboundsLinksFile;
|
||||
inboundsStatsFile = constants.inboundStatsFile;
|
||||
inboundsXray = proxyInboundsXray;
|
||||
inboundsApi = "127.0.0.1:${toString constants.inboundStatsApiPort}";
|
||||
inboundsSubscriptionsFile = proxyInboundsSubscriptionsFile;
|
||||
inboundsSubscriptionsBaseUrl =
|
||||
if proxyInboundsSubscriptionsBaseUrl == null then "" else proxyInboundsSubscriptionsBaseUrl;
|
||||
autoProxyEnabled = if proxyCfg.autoProxy.enable then "1" else "0";
|
||||
autoProxyStateDir = constants.autoProxyStateDir;
|
||||
torControlSocket = constants.torControlSocket;
|
||||
inherit (constants) stateDir runtimeDir serviceManager;
|
||||
privileged = if constants.privileged then "1" else "0";
|
||||
supervisorCtl = if constants.serviceManager == "supervisor" then constants.systemctl else "";
|
||||
singBox = "${singBoxCfg.package}/bin/sing-box";
|
||||
localProxyUrl = "http://${
|
||||
if proxyCfg.listener.address == "0.0.0.0" then "127.0.0.1" else proxyCfg.listener.address
|
||||
}:${toString proxyCfg.listener.port}";
|
||||
env = {
|
||||
CLASH_API = "http://127.0.0.1:${toString singBoxCfg.clashApiPort}";
|
||||
SELECTION = selectionMode;
|
||||
SUB_TAGS_FILE = toString subscriptionTagsFile;
|
||||
SUB_CACHE_DIR = subscriptionCacheDir;
|
||||
PER_APP_ROUTING_ENABLED = flag perAppRoutingCfg.enable;
|
||||
PER_APP_ROUTING_PROXYCHAINS_ENABLED = flag perAppRoutingCfg.proxychains.enable;
|
||||
PER_APP_ROUTING_TUN_ENABLED = flag perAppRoutingTun.enable;
|
||||
PER_APP_ROUTING_TPROXY_ENABLED = flag perAppRoutingTproxy.enable;
|
||||
PER_APP_ROUTING_ZAPRET_ENABLED = flag perAppZapretCfg.enable;
|
||||
PER_APP_ROUTING_PROFILES_FILE = toString perAppRoutingProfilesFile;
|
||||
PROXYCHAINS_CONFIG = toString proxychainsConfigFile;
|
||||
PROXYCHAINS_QUIET_ARG = lib.removeSuffix " " proxychainsQuietArg;
|
||||
ROUTE_MODE_STATE_FILE = routeModeStateFile;
|
||||
DEFAULT_ROUTE_MODE = if proxyCfg.routing.default == "proxy" then "blacklist" else "whitelist";
|
||||
AWG_PROFILES_FILE = toString amneziaWgProfileNamesFile;
|
||||
INBOUNDS_ENABLED = flag proxyInboundsEnabled;
|
||||
INBOUNDS_LINKS_FILE = proxyInboundsLinksFile;
|
||||
INBOUNDS_STATS_FILE = constants.inboundStatsFile;
|
||||
INBOUNDS_XRAY = proxyInboundsXray;
|
||||
INBOUNDS_API = "127.0.0.1:${toString constants.inboundStatsApiPort}";
|
||||
INBOUNDS_SUBS_FILE = proxyInboundsSubscriptionsFile;
|
||||
INBOUNDS_SUB_BASE_URL =
|
||||
if proxyInboundsSubscriptionsBaseUrl == null then "" else proxyInboundsSubscriptionsBaseUrl;
|
||||
ZAPRET_AUTO_ENABLED = flag (zapretEngine == "zapret2");
|
||||
ZAPRET_STATE_DIR = constants.zapret2StateDir;
|
||||
ZAPRET_CUTOFF_ENABLED = flag zapretCutoffEnabled;
|
||||
OUTBOUND_INVENTORY_FILE = constants.outboundInventoryFile;
|
||||
RUNTIME_OUTBOUNDS_DIR = constants.runtimeOutboundsDir;
|
||||
RUNTIME_SUBS_DIR = constants.runtimeSubscriptionsDir;
|
||||
USER_CONTROL_GROUP = userControlCfg.group;
|
||||
LOCAL_PROXY_URL = "http://${localProxy.hostPart}:${toString proxyCfg.listener.port}";
|
||||
AUTOPROXY_ENABLED = flag proxyCfg.autoProxy.enable;
|
||||
AUTOPROXY_STATE_DIR = constants.autoProxyStateDir;
|
||||
TOR_CONTROL_SOCKET = constants.torControlSocket;
|
||||
SING_BOX = "${singBoxCfg.package}/bin/sing-box";
|
||||
STATE_DIR = constants.stateDir;
|
||||
RUNTIME_DIR = constants.runtimeDir;
|
||||
SERVICE_MANAGER = constants.serviceManager;
|
||||
PRIVILEGED = flag constants.privileged;
|
||||
}
|
||||
// lib.optionalAttrs (constants.serviceManager == "supervisor") {
|
||||
SUPERVISOR_CTL = constants.systemctl;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -3,43 +3,11 @@
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
packages,
|
||||
cfg,
|
||||
tproxyFile,
|
||||
tunFile,
|
||||
perAppTunFile,
|
||||
routeModeRulesFile,
|
||||
proxyInboundsFile,
|
||||
proxyInboundsSpecFile,
|
||||
nftablesRulesFile,
|
||||
perAppTproxyRulesFile,
|
||||
perAppZapretRulesFile,
|
||||
perAppTunChainFile,
|
||||
ip,
|
||||
nft,
|
||||
context,
|
||||
}:
|
||||
|
||||
let
|
||||
context = import ./context.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
packages
|
||||
cfg
|
||||
tproxyFile
|
||||
tunFile
|
||||
perAppTunFile
|
||||
routeModeRulesFile
|
||||
proxyInboundsFile
|
||||
proxyInboundsSpecFile
|
||||
perAppTunChainFile
|
||||
perAppTproxyRulesFile
|
||||
perAppZapretRulesFile
|
||||
ip
|
||||
nft
|
||||
;
|
||||
};
|
||||
|
||||
builders = import ./builders.nix { inherit lib pkgs; };
|
||||
inherit (builders) mkNamedUnits;
|
||||
|
||||
@@ -79,46 +47,12 @@ let
|
||||
builtinTags
|
||||
;
|
||||
constants = derived.constants;
|
||||
routingScripts = import ./routing-scripts.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
builders
|
||||
ip
|
||||
nft
|
||||
nftablesRulesFile
|
||||
constants
|
||||
globalTun
|
||||
globalTproxy
|
||||
perAppRoutingTun
|
||||
;
|
||||
inherit (proxyCfg) ipv6;
|
||||
};
|
||||
routingScripts = import ./routing-scripts.nix { inherit (context) ctx; };
|
||||
|
||||
serviceUnits = import ./units.nix {
|
||||
inherit
|
||||
lib
|
||||
builders
|
||||
proxyCfg
|
||||
proxyEnabled
|
||||
hybridEnabled
|
||||
pureXrayEnabled
|
||||
globalTun
|
||||
globalTproxy
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretEnabled
|
||||
sshProxyOutboundEnabled
|
||||
sshProxyUnitEnabled
|
||||
torOutboundEnabled
|
||||
torOnionEnabled
|
||||
proxyInboundsEnabled
|
||||
proxyInboundsNeedLocalProxy
|
||||
scripts
|
||||
perAppRouting
|
||||
routingScripts
|
||||
;
|
||||
inherit (cfg) geodata;
|
||||
ctx = context.ctx // {
|
||||
inherit routingScripts;
|
||||
};
|
||||
};
|
||||
inherit (serviceUnits)
|
||||
localProxyAuthEnabled
|
||||
|
||||
@@ -1,135 +1,47 @@
|
||||
# App routing backend infrastructure (TUN, TProxy, zapret).
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
cfg,
|
||||
singBoxCfg,
|
||||
proxyCfg,
|
||||
perAppRoutingCfg,
|
||||
perAppRoutingTun,
|
||||
perAppRoutingTproxy,
|
||||
constants,
|
||||
perAppZapretCfg,
|
||||
perAppTunChainFile,
|
||||
perAppTproxyRulesFile,
|
||||
perAppZapretRulesFile,
|
||||
ip,
|
||||
nft,
|
||||
awk,
|
||||
grepBin,
|
||||
findBin,
|
||||
headBin,
|
||||
seqBin,
|
||||
sleepBin,
|
||||
}:
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
builders = import ./builders.nix { inherit lib pkgs; };
|
||||
inherit (builders) mkAnchorService;
|
||||
|
||||
perAppTunSliceName = "proxy-suite-per-app-tun.slice";
|
||||
perAppTproxySliceName = "proxy-suite-per-app-tproxy.slice";
|
||||
perAppZapretSliceName = "proxy-suite-per-app-zapret.slice";
|
||||
|
||||
profiles = import ./per-app-routing/profiles.nix {
|
||||
inherit (constants) runtimeDir;
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
proxyCfg
|
||||
perAppRoutingCfg
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
;
|
||||
};
|
||||
inherit (profiles)
|
||||
effectivePerAppRoutingProfiles
|
||||
effectivePerAppRoutingProfileNames
|
||||
perAppRoutingProfilesFile
|
||||
proxychainsConfigFile
|
||||
proxychainsQuietArg
|
||||
hasProxychainsProfiles
|
||||
hasTunProfiles
|
||||
hasTproxyProfiles
|
||||
hasZapretProfiles
|
||||
inherit (ctx)
|
||||
builders
|
||||
nft
|
||||
awk
|
||||
grepBin
|
||||
findBin
|
||||
headBin
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
;
|
||||
|
||||
backendScripts = import ./per-app-routing/backend-scripts.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
builders
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
constants
|
||||
perAppTunChainFile
|
||||
perAppTproxyRulesFile
|
||||
ip
|
||||
nft
|
||||
seqBin
|
||||
sleepBin
|
||||
;
|
||||
inherit (proxyCfg) ipv6;
|
||||
slices = {
|
||||
perAppTunSliceName = "proxy-suite-per-app-tun.slice";
|
||||
perAppTproxySliceName = "proxy-suite-per-app-tproxy.slice";
|
||||
perAppZapretSliceName = "proxy-suite-per-app-zapret.slice";
|
||||
};
|
||||
inherit (backendScripts)
|
||||
perAppTunUpScript
|
||||
perAppTunDownScript
|
||||
perAppTproxyUpScript
|
||||
perAppTproxyDownScript
|
||||
;
|
||||
|
||||
userRules = import ./per-app-routing/user-rules.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
perAppTunSliceName
|
||||
perAppTproxySliceName
|
||||
perAppZapretSliceName
|
||||
nft
|
||||
awk
|
||||
grepBin
|
||||
findBin
|
||||
headBin
|
||||
;
|
||||
};
|
||||
inherit (userRules)
|
||||
perAppTunUserRuleStart
|
||||
perAppTunUserRuleStop
|
||||
perAppTproxyUserRuleStart
|
||||
perAppTproxyUserRuleStop
|
||||
perAppZapretUserRuleStart
|
||||
perAppZapretUserRuleStop
|
||||
;
|
||||
|
||||
# user-rules.nix is also imported by the checks, so it keeps an explicit argument list.
|
||||
userRules = import ./per-app-routing/user-rules.nix (
|
||||
{
|
||||
inherit (ctx) lib pkgs;
|
||||
inherit
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
nft
|
||||
awk
|
||||
grepBin
|
||||
findBin
|
||||
headBin
|
||||
;
|
||||
}
|
||||
// slices
|
||||
);
|
||||
in
|
||||
{
|
||||
inherit
|
||||
perAppTunSliceName
|
||||
perAppTproxySliceName
|
||||
perAppZapretSliceName
|
||||
perAppTunUpScript
|
||||
perAppTunDownScript
|
||||
perAppTproxyUpScript
|
||||
perAppTproxyDownScript
|
||||
perAppTunUserRuleStart
|
||||
perAppTunUserRuleStop
|
||||
perAppTproxyUserRuleStart
|
||||
perAppTproxyUserRuleStop
|
||||
perAppZapretUserRuleStart
|
||||
perAppZapretUserRuleStop
|
||||
mkAnchorService
|
||||
effectivePerAppRoutingProfiles
|
||||
effectivePerAppRoutingProfileNames
|
||||
perAppRoutingProfilesFile
|
||||
proxychainsConfigFile
|
||||
proxychainsQuietArg
|
||||
hasProxychainsProfiles
|
||||
hasTunProfiles
|
||||
hasTproxyProfiles
|
||||
hasZapretProfiles
|
||||
;
|
||||
slices
|
||||
// import ./per-app-routing/profiles.nix { inherit ctx; }
|
||||
// import ./per-app-routing/backend-scripts.nix { inherit ctx; }
|
||||
// userRules
|
||||
// {
|
||||
inherit (builders) mkAnchorService;
|
||||
}
|
||||
@@ -1,21 +1,23 @@
|
||||
# Per-app TUN and TProxy backend lifecycle scripts.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
builders,
|
||||
perAppRoutingTun,
|
||||
perAppRoutingTproxy,
|
||||
ipv6,
|
||||
constants,
|
||||
perAppTunChainFile,
|
||||
perAppTproxyRulesFile,
|
||||
ip,
|
||||
nft,
|
||||
seqBin,
|
||||
sleepBin,
|
||||
}:
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
inherit (ctx)
|
||||
lib
|
||||
pkgs
|
||||
builders
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
proxyCfg
|
||||
constants
|
||||
perAppTunChainFile
|
||||
perAppTproxyRulesFile
|
||||
ip
|
||||
nft
|
||||
seqBin
|
||||
sleepBin
|
||||
;
|
||||
inherit (proxyCfg) ipv6;
|
||||
inherit (constants)
|
||||
perAppTunIPv6Address
|
||||
perAppTunIPv6RoutePrefix
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
# Per-app routing profile expansion and proxychains config.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
proxyCfg,
|
||||
perAppRoutingCfg,
|
||||
perAppRoutingTun,
|
||||
perAppRoutingTproxy,
|
||||
perAppZapretCfg,
|
||||
runtimeDir,
|
||||
}:
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
inherit (ctx)
|
||||
lib
|
||||
pkgs
|
||||
proxyCfg
|
||||
perAppRoutingCfg
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretCfg
|
||||
constants
|
||||
;
|
||||
inherit (constants) runtimeDir;
|
||||
perAppRoutingProfileNames = map (profile: profile.name) perAppRoutingCfg.profiles;
|
||||
defaultPerAppRoutingProfiles = lib.optionals perAppRoutingCfg.createDefaultProfiles (
|
||||
[
|
||||
@@ -46,9 +48,7 @@ let
|
||||
effectivePerAppRoutingProfileNames = map (profile: profile.name) effectivePerAppRoutingProfiles;
|
||||
|
||||
localProxyAuth = proxyCfg.listener.auth;
|
||||
localProxyAuthEnabled =
|
||||
localProxyAuth.username != null
|
||||
&& (localProxyAuth.password != null || localProxyAuth.passwordFile != null);
|
||||
localProxyAuthEnabled = ctx.localProxy.authEnabled;
|
||||
|
||||
perAppRoutingProfilesFile = pkgs.writeText "proxy-suite-per-app" (
|
||||
builtins.toJSON effectivePerAppRoutingProfiles
|
||||
|
||||
@@ -1,32 +1,33 @@
|
||||
# Start script of the inbound service: renders the listeners with their secrets into the
|
||||
# template and runs XRay.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
proxyCfg,
|
||||
proxyInboundsCfg,
|
||||
proxyInboundsAwg,
|
||||
awgBin,
|
||||
proxyInboundsNeedLocalProxy,
|
||||
torOnionEnabled,
|
||||
proxyInboundViaOutbounds,
|
||||
userControlCfg,
|
||||
userControlAllows,
|
||||
localProxyAuth,
|
||||
localProxyAuthEnabled,
|
||||
localProxyAuthPasswordSource,
|
||||
jq,
|
||||
python3,
|
||||
parserScriptsPythonPath,
|
||||
buildInboundPy,
|
||||
buildOutboundPy,
|
||||
proxyInboundsFile,
|
||||
proxyInboundsSpecFile,
|
||||
builders,
|
||||
constants,
|
||||
}:
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
inherit (ctx)
|
||||
lib
|
||||
pkgs
|
||||
proxyCfg
|
||||
proxyInboundsCfg
|
||||
proxyInboundsAwg
|
||||
awgBin
|
||||
proxyInboundsNeedLocalProxy
|
||||
torOnionEnabled
|
||||
proxyInboundViaOutbounds
|
||||
userControlCfg
|
||||
userControlAllows
|
||||
localProxyAuth
|
||||
localProxyAuthEnabled
|
||||
localProxyAuthPasswordSource
|
||||
jq
|
||||
python3
|
||||
parserScriptsPythonPath
|
||||
buildInboundPy
|
||||
buildOutboundPy
|
||||
proxyInboundsFile
|
||||
proxyInboundsSpecFile
|
||||
builders
|
||||
constants
|
||||
;
|
||||
runtimeDir = "${constants.runtimeDir}/proxy-suite-inbounds";
|
||||
linksFile = "${runtimeDir}/links.json";
|
||||
subscriptionsFile = "${runtimeDir}/subscriptions.json";
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
builders,
|
||||
ip,
|
||||
nft,
|
||||
nftablesRulesFile,
|
||||
constants,
|
||||
globalTun,
|
||||
globalTproxy,
|
||||
perAppRoutingTun,
|
||||
ipv6,
|
||||
}:
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
inherit (ctx)
|
||||
lib
|
||||
pkgs
|
||||
builders
|
||||
ip
|
||||
nft
|
||||
nftablesRulesFile
|
||||
constants
|
||||
globalTun
|
||||
globalTproxy
|
||||
perAppRoutingTun
|
||||
proxyCfg
|
||||
;
|
||||
inherit (proxyCfg) ipv6;
|
||||
inherit (constants)
|
||||
tunAutoRouteTableIndex
|
||||
tunAutoRouteRulePriority
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
{
|
||||
lib,
|
||||
jq,
|
||||
hybridEnabled,
|
||||
xraySidecarRoutingMark,
|
||||
}:
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
inherit (ctx)
|
||||
lib
|
||||
jq
|
||||
hybridEnabled
|
||||
xraySidecarRoutingMark
|
||||
;
|
||||
in
|
||||
|
||||
routingMark: xraySidecarBasePort: xrayDnsBridgePort:
|
||||
|
||||
|
||||
@@ -3,23 +3,24 @@
|
||||
# Everything is emitted as shell functions taking a tag and a file holding the
|
||||
# subscription URL, so a subscription declared in Nix and one added at runtime
|
||||
# under `subscriptions.d/` go through exactly the same code.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
proxyCfg,
|
||||
hybridEnabled,
|
||||
mainBackend,
|
||||
backend,
|
||||
stateDir,
|
||||
runtimeSubscriptionsDir,
|
||||
jq,
|
||||
python3,
|
||||
parserScriptsPythonPath,
|
||||
fetchSubscriptionPy,
|
||||
routingMarkJq,
|
||||
}:
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
inherit (ctx)
|
||||
lib
|
||||
pkgs
|
||||
proxyCfg
|
||||
hybridEnabled
|
||||
mainBackend
|
||||
backend
|
||||
constants
|
||||
jq
|
||||
python3
|
||||
parserScriptsPythonPath
|
||||
fetchSubscriptionPy
|
||||
routingMarkJq
|
||||
;
|
||||
inherit (constants) stateDir runtimeSubscriptionsDir;
|
||||
subscriptionBackend = if hybridEnabled then "hybrid" else mainBackend;
|
||||
subscriptionBackendArg = "--backend ${subscriptionBackend}";
|
||||
subscriptionCacheDir = "${stateDir}/subscriptions/${backend}";
|
||||
|
||||
@@ -1,49 +1,36 @@
|
||||
# Assembles proxy backend startup and control scripts.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
singBoxCfg,
|
||||
proxyCfg,
|
||||
sshProxyCfg,
|
||||
warpCfg,
|
||||
torCfg,
|
||||
awgOutbounds,
|
||||
xrayEnabled,
|
||||
hybridEnabled,
|
||||
pureXrayEnabled,
|
||||
activeBackend,
|
||||
perAppRoutingCfg,
|
||||
userControlCfg,
|
||||
selectionMode,
|
||||
collapseNamedOutbounds,
|
||||
constants,
|
||||
zapretCutoffProxyFallback,
|
||||
jq,
|
||||
python3,
|
||||
singBox,
|
||||
xray,
|
||||
parserScriptsPythonPath,
|
||||
buildOutboundPy,
|
||||
fetchSubscriptionPy,
|
||||
tproxyFile,
|
||||
tunFile,
|
||||
perAppTunFile,
|
||||
routeModeRulesFile,
|
||||
proxyInboundsCfg,
|
||||
proxyInboundsAwg,
|
||||
awgBin,
|
||||
proxyInboundsNeedLocalProxy,
|
||||
torOnionEnabled,
|
||||
proxyInboundsGuardPrivate,
|
||||
proxyInboundViaOutbounds,
|
||||
userControlAllows,
|
||||
buildInboundPy,
|
||||
proxyInboundsFile,
|
||||
proxyInboundsSpecFile,
|
||||
builders,
|
||||
}:
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
inherit (ctx)
|
||||
lib
|
||||
pkgs
|
||||
singBoxCfg
|
||||
proxyCfg
|
||||
activeBackend
|
||||
xrayEnabled
|
||||
hybridEnabled
|
||||
pureXrayEnabled
|
||||
perAppRoutingCfg
|
||||
userControlCfg
|
||||
userControlAllows
|
||||
selectionMode
|
||||
constants
|
||||
zapretCutoffProxyFallback
|
||||
jq
|
||||
python3
|
||||
singBox
|
||||
xray
|
||||
proxyInboundsCfg
|
||||
proxyInboundsGuardPrivate
|
||||
routeModeRulesFile
|
||||
tproxyFile
|
||||
tunFile
|
||||
perAppTunFile
|
||||
proxyInboundsFile
|
||||
proxyInboundsSpecFile
|
||||
builders
|
||||
;
|
||||
globalTproxy = proxyCfg.tproxy;
|
||||
backend = if activeBackend == null then "sing-box" else activeBackend;
|
||||
mainBackend = if pureXrayEnabled then "xray" else "sing-box";
|
||||
@@ -81,23 +68,43 @@ let
|
||||
else
|
||||
" | .routing_mark = ${toString routingMark}";
|
||||
|
||||
subscriptionScripts = import ./script-blocks/subscriptions.nix {
|
||||
inherit (constants) stateDir;
|
||||
# ctx plus this layer's own values; the script blocks read what they need off it. Lazy, so
|
||||
# a block may use a sibling's output (start-scripts uses the subscription helpers).
|
||||
sctx = ctx // {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
proxyCfg
|
||||
hybridEnabled
|
||||
mainBackend
|
||||
backend
|
||||
runtimeSubscriptionsDir
|
||||
jq
|
||||
python3
|
||||
parserScriptsPythonPath
|
||||
fetchSubscriptionPy
|
||||
mainBackend
|
||||
backendArg
|
||||
backendBin
|
||||
globalTproxy
|
||||
localProxyAuth
|
||||
localProxyAuthEnabled
|
||||
localProxyAuthPasswordSource
|
||||
routeModeStateFile
|
||||
xrayLoglevelFile
|
||||
runtimeProxychainsConfig
|
||||
xraySidecarRoutingMark
|
||||
routingMarkJq
|
||||
pinnedOutboundFile
|
||||
runtimeOutboundsDir
|
||||
runtimeSubscriptionsDir
|
||||
outboundInventoryFile
|
||||
clashApi
|
||||
;
|
||||
inherit (subscriptionScripts)
|
||||
subscriptionCacheDir
|
||||
subscriptionCacheHelpersBlock
|
||||
mkSubscriptionLoadHelperBlock
|
||||
mkSubscriptionBlock
|
||||
runtimeSubscriptionsBlock
|
||||
mkSubscriptionFetchBlock
|
||||
runtimeSubscriptionsFetchBlock
|
||||
;
|
||||
inherit (outboundScripts) mkOutboundScript;
|
||||
inherit hybridRuntimeHelpersBlock backendJqFilterFile;
|
||||
};
|
||||
|
||||
subscriptionScripts = import ./script-blocks/subscriptions.nix { ctx = sctx; };
|
||||
inherit (subscriptionScripts)
|
||||
subscriptionCacheDir
|
||||
subscriptionCacheHelpersBlock
|
||||
@@ -110,7 +117,7 @@ let
|
||||
;
|
||||
|
||||
outboundScripts = import ./script-blocks/outbounds.nix {
|
||||
inherit
|
||||
inherit (sctx)
|
||||
lib
|
||||
pkgs
|
||||
singBoxCfg
|
||||
@@ -140,14 +147,7 @@ let
|
||||
};
|
||||
inherit (outboundScripts) mkOutboundScript;
|
||||
|
||||
hybridRuntimeHelpersBlock = import ./script-blocks/hybrid-runtime-helpers.nix {
|
||||
inherit
|
||||
lib
|
||||
jq
|
||||
hybridEnabled
|
||||
xraySidecarRoutingMark
|
||||
;
|
||||
};
|
||||
hybridRuntimeHelpersBlock = import ./script-blocks/hybrid-runtime-helpers.nix { ctx = sctx; };
|
||||
|
||||
backendJqFilter = import ./script-blocks/backend-jq-filter.nix {
|
||||
inherit
|
||||
@@ -160,69 +160,10 @@ let
|
||||
};
|
||||
backendJqFilterFile = pkgs.writeText "proxy-suite-core" backendJqFilter;
|
||||
|
||||
startScripts = import ./start-scripts.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
proxyCfg
|
||||
perAppRoutingCfg
|
||||
userControlCfg
|
||||
userControlAllows
|
||||
globalTproxy
|
||||
xrayEnabled
|
||||
hybridEnabled
|
||||
pureXrayEnabled
|
||||
constants
|
||||
zapretCutoffProxyFallback
|
||||
jq
|
||||
singBox
|
||||
xray
|
||||
backendBin
|
||||
routeModeStateFile
|
||||
routeModeRulesFile
|
||||
xrayLoglevelFile
|
||||
runtimeProxychainsConfig
|
||||
localProxyAuth
|
||||
localProxyAuthEnabled
|
||||
localProxyAuthPasswordSource
|
||||
backendJqFilterFile
|
||||
hybridRuntimeHelpersBlock
|
||||
subscriptionCacheHelpersBlock
|
||||
mkOutboundScript
|
||||
tproxyFile
|
||||
tunFile
|
||||
perAppTunFile
|
||||
;
|
||||
};
|
||||
startScripts = import ./start-scripts.nix { ctx = sctx; };
|
||||
inherit (startScripts) startSocks startTun startPerAppTun;
|
||||
|
||||
proxyInboundsScripts = import ./proxy-inbounds-scripts.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
proxyCfg
|
||||
proxyInboundsCfg
|
||||
proxyInboundsAwg
|
||||
awgBin
|
||||
proxyInboundsNeedLocalProxy
|
||||
torOnionEnabled
|
||||
proxyInboundViaOutbounds
|
||||
userControlCfg
|
||||
userControlAllows
|
||||
localProxyAuth
|
||||
localProxyAuthEnabled
|
||||
localProxyAuthPasswordSource
|
||||
jq
|
||||
python3
|
||||
parserScriptsPythonPath
|
||||
buildInboundPy
|
||||
buildOutboundPy
|
||||
proxyInboundsFile
|
||||
proxyInboundsSpecFile
|
||||
builders
|
||||
constants
|
||||
;
|
||||
};
|
||||
proxyInboundsScripts = import ./proxy-inbounds-scripts.nix { ctx = sctx; };
|
||||
inherit (proxyInboundsScripts) startInbounds collectInboundStats;
|
||||
proxyInboundsLinksFile = proxyInboundsScripts.linksFile;
|
||||
proxyInboundsSubscriptionsFile = proxyInboundsScripts.subscriptionsFile;
|
||||
@@ -271,11 +212,5 @@ in
|
||||
subscriptionUpdateScript
|
||||
subscriptionTagsFile
|
||||
subscriptionCacheDir
|
||||
runtimeProxychainsConfig
|
||||
pinnedOutboundFile
|
||||
runtimeOutboundsDir
|
||||
runtimeSubscriptionsDir
|
||||
outboundInventoryFile
|
||||
clashApi
|
||||
;
|
||||
}
|
||||
@@ -1,38 +1,39 @@
|
||||
# Backend startup script derivations.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
proxyCfg,
|
||||
perAppRoutingCfg,
|
||||
userControlCfg,
|
||||
userControlAllows,
|
||||
globalTproxy,
|
||||
xrayEnabled,
|
||||
hybridEnabled,
|
||||
pureXrayEnabled,
|
||||
constants,
|
||||
zapretCutoffProxyFallback,
|
||||
jq,
|
||||
singBox,
|
||||
xray,
|
||||
backendBin,
|
||||
routeModeStateFile,
|
||||
routeModeRulesFile,
|
||||
xrayLoglevelFile,
|
||||
runtimeProxychainsConfig,
|
||||
localProxyAuth,
|
||||
localProxyAuthEnabled,
|
||||
localProxyAuthPasswordSource,
|
||||
backendJqFilterFile,
|
||||
hybridRuntimeHelpersBlock,
|
||||
subscriptionCacheHelpersBlock,
|
||||
mkOutboundScript,
|
||||
tproxyFile,
|
||||
tunFile,
|
||||
perAppTunFile,
|
||||
}:
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
inherit (ctx)
|
||||
lib
|
||||
pkgs
|
||||
proxyCfg
|
||||
perAppRoutingCfg
|
||||
userControlCfg
|
||||
userControlAllows
|
||||
globalTproxy
|
||||
xrayEnabled
|
||||
hybridEnabled
|
||||
pureXrayEnabled
|
||||
constants
|
||||
zapretCutoffProxyFallback
|
||||
jq
|
||||
singBox
|
||||
xray
|
||||
backendBin
|
||||
routeModeStateFile
|
||||
routeModeRulesFile
|
||||
xrayLoglevelFile
|
||||
runtimeProxychainsConfig
|
||||
localProxyAuth
|
||||
localProxyAuthEnabled
|
||||
localProxyAuthPasswordSource
|
||||
backendJqFilterFile
|
||||
hybridRuntimeHelpersBlock
|
||||
subscriptionCacheHelpersBlock
|
||||
mkOutboundScript
|
||||
tproxyFile
|
||||
tunFile
|
||||
perAppTunFile
|
||||
;
|
||||
inherit (constants)
|
||||
autoProxyStateDir
|
||||
outboundTestPort
|
||||
@@ -60,62 +61,89 @@ let
|
||||
+ .proxyGeo
|
||||
'';
|
||||
|
||||
# Every route mode is the same four assignments over one jq program on the rule buckets.
|
||||
routeModeArms = [
|
||||
{
|
||||
mode = "blacklist";
|
||||
final = "proxy";
|
||||
dns = "remote";
|
||||
rules = ''
|
||||
.common
|
||||
+ (.custom | map(.entries) | add // [])
|
||||
+ .proxyPrimary
|
||||
+ .direct
|
||||
+ .safetyDirect
|
||||
${routeModeBlacklistTail}
|
||||
'';
|
||||
}
|
||||
{
|
||||
mode = "whitelist";
|
||||
final = "direct";
|
||||
dns = "local";
|
||||
rules = ''
|
||||
.common
|
||||
+ (.custom | map(.entries) | add // [])
|
||||
+ .proxyPrimary
|
||||
+ .direct
|
||||
+ .safetyDirect
|
||||
${routeModeBlacklistTail}
|
||||
'';
|
||||
}
|
||||
{
|
||||
# Only the proxy and block lists are kept: everything else follows the final action.
|
||||
mode = "all-proxy";
|
||||
final = "proxy";
|
||||
dns = "remote";
|
||||
clearDns = true;
|
||||
rules = ''
|
||||
.common
|
||||
+ (.custom | map(select(.category == "proxy" or .category == "block") | .entries) | add // [])
|
||||
+ .proxyPrimary
|
||||
+ .safetyDirect
|
||||
${routeModeBlacklistTail}
|
||||
'';
|
||||
}
|
||||
{
|
||||
mode = "all-bypass";
|
||||
final = "direct";
|
||||
dns = "local";
|
||||
clearDns = true;
|
||||
rules = ''
|
||||
.common
|
||||
+ (.custom | map(select(.category == "block") | .entries) | add // [])
|
||||
+ .safetyDirect
|
||||
+ .block
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
# Written out line by line: the block lands inside a `case`, where the indentation of an
|
||||
# interpolated multi-line value would otherwise be lost.
|
||||
mkRouteModeArm =
|
||||
arm:
|
||||
lib.concatStringsSep "\n" (
|
||||
[
|
||||
" ${arm.mode})"
|
||||
" ROUTE_FINAL=\"${arm.final}\""
|
||||
" DNS_FINAL=\"${arm.dns}\""
|
||||
" ROUTE_MODE_ACTIVE=true"
|
||||
]
|
||||
++ lib.optional (arm.clearDns or false) " CLEAR_DNS_RULES=true"
|
||||
++ [ " ROUTE_RULES_JSON=$(${jq} -c '" ]
|
||||
++ map (line: if line == "" then "" else " ${line}") (
|
||||
lib.splitString "\n" (lib.removeSuffix "\n" arm.rules)
|
||||
)
|
||||
++ [
|
||||
" ' \"${routeModeRulesFile}\")"
|
||||
" ;;"
|
||||
]
|
||||
);
|
||||
|
||||
routeModeCaseBlock = ''
|
||||
if [ -r "$ROUTE_MODE_STATE_FILE" ]; then
|
||||
ROUTE_MODE="$(tr -d '\r\n[:space:]' < "$ROUTE_MODE_STATE_FILE" 2>/dev/null || true)"
|
||||
fi
|
||||
case "$ROUTE_MODE" in
|
||||
blacklist)
|
||||
ROUTE_FINAL="proxy"
|
||||
DNS_FINAL="remote"
|
||||
ROUTE_MODE_ACTIVE=true
|
||||
ROUTE_RULES_JSON=$(${jq} -c '
|
||||
.common
|
||||
+ (.custom | map(.entries) | add // [])
|
||||
+ .proxyPrimary
|
||||
+ .direct
|
||||
+ .safetyDirect
|
||||
${routeModeBlacklistTail}
|
||||
' "${routeModeRulesFile}")
|
||||
;;
|
||||
whitelist)
|
||||
ROUTE_FINAL="direct"
|
||||
DNS_FINAL="local"
|
||||
ROUTE_MODE_ACTIVE=true
|
||||
ROUTE_RULES_JSON=$(${jq} -c '
|
||||
.common
|
||||
+ (.custom | map(.entries) | add // [])
|
||||
+ .proxyPrimary
|
||||
+ .direct
|
||||
+ .safetyDirect
|
||||
${routeModeBlacklistTail}
|
||||
' "${routeModeRulesFile}")
|
||||
;;
|
||||
all-proxy)
|
||||
ROUTE_FINAL="proxy"
|
||||
DNS_FINAL="remote"
|
||||
ROUTE_MODE_ACTIVE=true
|
||||
CLEAR_DNS_RULES=true
|
||||
ROUTE_RULES_JSON=$(${jq} -c '
|
||||
.common
|
||||
+ (.custom | map(select(.category == "proxy" or .category == "block") | .entries) | add // [])
|
||||
+ .proxyPrimary
|
||||
+ .safetyDirect
|
||||
${routeModeBlacklistTail}
|
||||
' "${routeModeRulesFile}")
|
||||
;;
|
||||
all-bypass)
|
||||
ROUTE_FINAL="direct"
|
||||
DNS_FINAL="local"
|
||||
ROUTE_MODE_ACTIVE=true
|
||||
CLEAR_DNS_RULES=true
|
||||
ROUTE_RULES_JSON=$(${jq} -c '
|
||||
.common
|
||||
+ (.custom | map(select(.category == "block") | .entries) | add // [])
|
||||
+ .safetyDirect
|
||||
+ .block
|
||||
' "${routeModeRulesFile}")
|
||||
;;
|
||||
case "$ROUTE_MODE" in${lib.concatMapStrings (arm: "\n" + mkRouteModeArm arm) routeModeArms}
|
||||
*)
|
||||
ROUTE_MODE=""
|
||||
;;
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
# Systemd unit definitions for proxy-suite services and timers.
|
||||
{
|
||||
lib,
|
||||
builders,
|
||||
proxyCfg,
|
||||
proxyEnabled,
|
||||
hybridEnabled,
|
||||
pureXrayEnabled,
|
||||
globalTun,
|
||||
globalTproxy,
|
||||
perAppRoutingTun,
|
||||
perAppRoutingTproxy,
|
||||
perAppZapretEnabled,
|
||||
sshProxyOutboundEnabled,
|
||||
sshProxyUnitEnabled,
|
||||
torOutboundEnabled,
|
||||
torOnionEnabled,
|
||||
proxyInboundsEnabled,
|
||||
proxyInboundsNeedLocalProxy,
|
||||
scripts,
|
||||
perAppRouting,
|
||||
routingScripts,
|
||||
geodata,
|
||||
}:
|
||||
{ ctx }:
|
||||
|
||||
let
|
||||
inherit (ctx)
|
||||
lib
|
||||
builders
|
||||
proxyCfg
|
||||
proxyEnabled
|
||||
hybridEnabled
|
||||
pureXrayEnabled
|
||||
globalTun
|
||||
globalTproxy
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
perAppZapretEnabled
|
||||
sshProxyOutboundEnabled
|
||||
sshProxyUnitEnabled
|
||||
torOutboundEnabled
|
||||
torOnionEnabled
|
||||
proxyInboundsEnabled
|
||||
proxyInboundsNeedLocalProxy
|
||||
scripts
|
||||
perAppRouting
|
||||
routingScripts
|
||||
cfg
|
||||
;
|
||||
inherit (cfg) geodata;
|
||||
inherit (builders)
|
||||
mkAnchorService
|
||||
mkRestartingService
|
||||
@@ -58,9 +60,7 @@ let
|
||||
else
|
||||
"sing-box";
|
||||
|
||||
localProxyAuthEnabled =
|
||||
proxyCfg.listener.auth.username != null
|
||||
&& (proxyCfg.listener.auth.password != null || proxyCfg.listener.auth.passwordFile != null);
|
||||
localProxyAuthEnabled = ctx.localProxy.authEnabled;
|
||||
|
||||
# XRay finds geoip.dat/geosite.dat through this; sing-box ignores it.
|
||||
xrayAssetEnv = lib.optionalAttrs (geodata.xray.assets != null) {
|
||||
@@ -336,7 +336,6 @@ let
|
||||
in
|
||||
{
|
||||
inherit
|
||||
serviceNames
|
||||
localProxyAuthEnabled
|
||||
systemServiceEntries
|
||||
userServiceEntries
|
||||
|
||||
@@ -12,20 +12,10 @@ let
|
||||
inherit (derived.constants) unprivilegedServiceConfig;
|
||||
inherit (cfg.host) privileged;
|
||||
|
||||
inherit (derived.localProxy) auth;
|
||||
listener = cfg.proxy.listener;
|
||||
auth = listener.auth;
|
||||
# Tor dials the local proxy by address: a wildcard listener is reached on loopback.
|
||||
proxyHost =
|
||||
if
|
||||
builtins.elem listener.address [
|
||||
"0.0.0.0"
|
||||
"::"
|
||||
]
|
||||
then
|
||||
"127.0.0.1"
|
||||
else
|
||||
listener.address;
|
||||
proxyHostPart = if lib.hasInfix ":" proxyHost then "[${proxyHost}]" else proxyHost;
|
||||
proxyHost = derived.localProxy.host;
|
||||
proxyHostPart = derived.localProxy.hostPart;
|
||||
passwordSource =
|
||||
if auth.passwordFile != null then
|
||||
auth.passwordFile
|
||||
@@ -34,7 +24,7 @@ let
|
||||
else
|
||||
null;
|
||||
viaProxy = t.upstream == "proxy";
|
||||
withProxyAuth = viaProxy && auth.username != null && passwordSource != null;
|
||||
withProxyAuth = viaProxy && derived.localProxy.authEnabled;
|
||||
bridgesEnabled = t.bridges.lines != [ ] || t.bridges.file != null;
|
||||
|
||||
# The control socket's directory: members of userControl.group may use it for
|
||||
|
||||
@@ -10,19 +10,8 @@
|
||||
let
|
||||
w = derived.warpCfg;
|
||||
inherit (derived.constants) unprivilegedServiceConfig;
|
||||
inherit (derived.localProxy) auth host hostPart;
|
||||
listener = cfg.proxy.listener;
|
||||
auth = listener.auth;
|
||||
host =
|
||||
if
|
||||
builtins.elem listener.address [
|
||||
"0.0.0.0"
|
||||
"::"
|
||||
]
|
||||
then
|
||||
"127.0.0.1"
|
||||
else
|
||||
listener.address;
|
||||
hostPart = if lib.hasInfix ":" host then "[${host}]" else host;
|
||||
passwordSource =
|
||||
if auth.passwordFile != null then
|
||||
auth.passwordFile
|
||||
@@ -30,7 +19,7 @@ let
|
||||
pkgs.writeText "proxy-suite-warp" auth.password
|
||||
else
|
||||
null;
|
||||
withProxyAuth = auth.username != null && passwordSource != null;
|
||||
withProxyAuth = derived.localProxy.authEnabled;
|
||||
userinfo = lib.optionalString withProxyAuth ''
|
||||
userinfo=$(${pkgs.jq}/bin/jq -rn --arg u ${lib.escapeShellArg auth.username} \
|
||||
--rawfile p "$CREDENTIALS_DIRECTORY/proxy-password" '"\($u | @uri):\($p | rtrimstr("\n") | @uri)@"')
|
||||
|
||||
@@ -10,10 +10,7 @@
|
||||
|
||||
let
|
||||
inherit (derived.constants) serviceUser runAsServiceUser ifPrivileged;
|
||||
scriptsDir = builtins.path {
|
||||
name = "proxy-suite-scripts";
|
||||
path = ../../scripts;
|
||||
};
|
||||
scriptsDir = import ./lib/scripts-dir.nix { inherit lib; };
|
||||
|
||||
# sing-box's "local" server has no upstream on hosts behind systemd-resolved, so the tunnel
|
||||
# resolves the peer hostname like the main config, with proxy.dns.local. Destinations are
|
||||
|
||||
@@ -14,10 +14,21 @@ let
|
||||
|
||||
zapretCfg = cfg.zapret;
|
||||
perAppZapretCfg = cfg.perAppRouting.zapret;
|
||||
# Global AmneziaWG profiles only: an outbound one leaves the host's routes alone.
|
||||
awgServiceNames = map (name: "proxy-suite-awg-${name}.service") (
|
||||
builtins.attrNames (lib.filterAttrs (_: profile: profile.asOutbound == null) cfg.amneziaWg.profiles)
|
||||
);
|
||||
inherit
|
||||
(import ./zapret/common.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
cfg
|
||||
nft
|
||||
perAppZapretRulesFile
|
||||
;
|
||||
})
|
||||
awgServiceNames
|
||||
perAppConflicts
|
||||
perAppZapretMarkUpScript
|
||||
perAppZapretMarkDownScript
|
||||
;
|
||||
zapretPackages = import ./zapret/packages.nix {
|
||||
inherit
|
||||
lib
|
||||
@@ -47,17 +58,6 @@ let
|
||||
fi
|
||||
'';
|
||||
|
||||
perAppZapretMarkUpScript = pkgs.writeShellScript "proxy-suite-zapret" ''
|
||||
set -euo pipefail
|
||||
${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true
|
||||
${nft} -f ${perAppZapretRulesFile}
|
||||
'';
|
||||
|
||||
perAppZapretMarkDownScript = pkgs.writeShellScript "proxy-suite-zapret" ''
|
||||
set -euo pipefail
|
||||
${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true
|
||||
'';
|
||||
|
||||
exemptStart = ''
|
||||
set -euo pipefail
|
||||
''
|
||||
@@ -108,11 +108,7 @@ in
|
||||
description = "proxy-suite per-app-routing zapret backend";
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
conflicts = [
|
||||
"proxy-suite-tproxy.service"
|
||||
"proxy-suite-tun.service"
|
||||
]
|
||||
++ awgServiceNames;
|
||||
conflicts = perAppConflicts ++ awgServiceNames;
|
||||
preStart = zapretCommonPreStart perAppZapretPackage;
|
||||
runtimeDirectory = "proxy-suite-per-app-zapret";
|
||||
execStart = "${perAppZapretPackage}/opt/zapret/init.d/sysv/zapret start";
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
# What both zapret engines need the same way: which units they must not run beside, the
|
||||
# interfaces to keep out of NFQUEUE, and the per-app mark table's nft hooks.
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
cfg,
|
||||
nft ? null,
|
||||
perAppZapretRulesFile ? null,
|
||||
# zapret v1 names its scripts proxy-suite-zapret, zapret2 proxy-suite-zapret2.
|
||||
scriptName ? "proxy-suite-zapret",
|
||||
}:
|
||||
let
|
||||
dropMarkTable = "${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true";
|
||||
in
|
||||
{
|
||||
# Global AmneziaWG profiles only: an outbound one leaves the host's routes alone.
|
||||
awgServiceNames = map (name: "proxy-suite-awg-${name}.service") (
|
||||
builtins.attrNames (lib.filterAttrs (_: profile: profile.asOutbound == null) cfg.amneziaWg.profiles)
|
||||
);
|
||||
|
||||
tunInterfaces = lib.unique (
|
||||
lib.optional (cfg.proxy.enable && cfg.proxy.tun.enable) cfg.proxy.tun.interface
|
||||
++ lib.optional (cfg.proxy.enable && cfg.perAppRouting.tun.enable) cfg.perAppRouting.tun.interface
|
||||
);
|
||||
|
||||
# The transparent backends steer the same packets; a per-app zapret instance replaces them.
|
||||
perAppConflicts = [
|
||||
"proxy-suite-tproxy.service"
|
||||
"proxy-suite-tun.service"
|
||||
];
|
||||
|
||||
perAppZapretMarkUpScript = pkgs.writeShellScript scriptName ''
|
||||
set -euo pipefail
|
||||
${dropMarkTable}
|
||||
${nft} -f ${perAppZapretRulesFile}
|
||||
'';
|
||||
|
||||
perAppZapretMarkDownScript = pkgs.writeShellScript scriptName ''
|
||||
set -euo pipefail
|
||||
${dropMarkTable}
|
||||
'';
|
||||
}
|
||||
@@ -9,10 +9,7 @@
|
||||
let
|
||||
zapretCfg = cfg.zapret;
|
||||
perAppZapretCfg = cfg.perAppRouting.zapret;
|
||||
tunInterfaces = lib.unique (
|
||||
lib.optional (cfg.proxy.enable && cfg.proxy.tun.enable) cfg.proxy.tun.interface
|
||||
++ lib.optional (cfg.proxy.enable && cfg.perAppRouting.tun.enable) cfg.perAppRouting.tun.interface
|
||||
);
|
||||
inherit (import ./common.nix { inherit lib pkgs cfg; }) tunInterfaces;
|
||||
zapretDomainGroups = import ../zapret-domain-groups.nix { inherit lib zapret; };
|
||||
|
||||
runtimeDeps = lib.attrValues {
|
||||
@@ -84,12 +81,7 @@ let
|
||||
);
|
||||
|
||||
selectedConfigName = lib.strings.sanitizeDerivationName zapretCfg.zapret-discord-youtube.configName;
|
||||
patchConfigScriptSrc = "${
|
||||
builtins.path {
|
||||
name = "proxy-suite-scripts";
|
||||
path = ../../../scripts;
|
||||
}
|
||||
}/patch-zapret-config.py";
|
||||
patchConfigScriptSrc = "${import ../lib/scripts-dir.nix { inherit lib; }}/patch-zapret-config.py";
|
||||
patchConfigScript = "${pkgs.python3}/bin/python3 ${patchConfigScriptSrc}";
|
||||
|
||||
packageBuilder = import ./package-builder.nix {
|
||||
|
||||
@@ -17,10 +17,23 @@ let
|
||||
perAppZapretCfg = cfg.perAppRouting.zapret;
|
||||
cutoffCfg = zapretCfg.zapret2.cutoff;
|
||||
inherit (import ./derived.nix { inherit lib cfg; }) constants userControlAllows;
|
||||
# Global AmneziaWG profiles only: an outbound one leaves the host's routes alone.
|
||||
awgServiceNames = map (name: "proxy-suite-awg-${name}.service") (
|
||||
builtins.attrNames (lib.filterAttrs (_: profile: profile.asOutbound == null) cfg.amneziaWg.profiles)
|
||||
);
|
||||
inherit
|
||||
(import ./zapret/common.nix {
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
cfg
|
||||
nft
|
||||
perAppZapretRulesFile
|
||||
;
|
||||
scriptName = "proxy-suite-zapret2";
|
||||
})
|
||||
awgServiceNames
|
||||
tunInterfaces
|
||||
perAppConflicts
|
||||
perAppZapretMarkUpScript
|
||||
perAppZapretMarkDownScript
|
||||
;
|
||||
|
||||
runtime = import ./zapret2/runtime.nix {
|
||||
inherit
|
||||
@@ -32,11 +45,6 @@ let
|
||||
;
|
||||
};
|
||||
|
||||
tunInterfaces = lib.unique (
|
||||
lib.optional (cfg.proxy.enable && cfg.proxy.tun.enable) cfg.proxy.tun.interface
|
||||
++ lib.optional (cfg.proxy.enable && cfg.perAppRouting.tun.enable) cfg.perAppRouting.tun.interface
|
||||
);
|
||||
|
||||
globalRuntime = runtime.mkRuntime {
|
||||
name = "proxy-suite-zapret2";
|
||||
qnum = constants.zapretGlobalQnum.zapret2;
|
||||
@@ -91,16 +99,6 @@ let
|
||||
;
|
||||
};
|
||||
|
||||
perAppZapretMarkUpScript = pkgs.writeShellScript "proxy-suite-zapret2" ''
|
||||
set -euo pipefail
|
||||
${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true
|
||||
${nft} -f ${perAppZapretRulesFile}
|
||||
'';
|
||||
|
||||
perAppZapretMarkDownScript = pkgs.writeShellScript "proxy-suite-zapret2" ''
|
||||
set -euo pipefail
|
||||
${nft} delete table inet proxy_suite_per_app_zapret_mark 2>/dev/null || true
|
||||
'';
|
||||
in
|
||||
{
|
||||
services.proxy-suite.internal.earlyPackages = [ runtime.package ];
|
||||
@@ -138,11 +136,7 @@ in
|
||||
description = "proxy-suite per-app-routing zapret2 backend";
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
conflicts = [
|
||||
"proxy-suite-tproxy.service"
|
||||
"proxy-suite-tun.service"
|
||||
]
|
||||
++ awgServiceNames;
|
||||
conflicts = perAppConflicts ++ awgServiceNames;
|
||||
preStart = mkPreStart;
|
||||
runtimeDirectory = "proxy-suite-per-app-zapret";
|
||||
stateDirectory = "proxy-suite";
|
||||
|
||||
Reference in new issue
Block a user