refactor: remove duplication

This commit is contained in:
FUFSoB committed 2026-09-18 21:39:18 +05:00
1 parent f7036f6075
commit 8a4ba2db6a
109 files changed
+2206 -3078

No files matched your search

+42
View File
@@ -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}
'';
}
+2 -10
View File
@@ -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 {