2024-08-28 02:34:26 +03:00
|
|
|
# SOURCE: https://github.com/bol-van/zapret
|
2024-08-28 01:31:17 +03:00
|
|
|
{ lib, config, pkgs, util, ... }: with lib; let
|
|
|
|
cfg = config.module.zapret;
|
|
|
|
|
|
|
|
whitelist = if cfg.whitelist != null then
|
|
|
|
"--hostlist ${pkgs.writeText "ZapretWhitelist" (util.trimTabs cfg.whitelist)}"
|
|
|
|
else "";
|
|
|
|
|
|
|
|
blacklist = if cfg.blacklist != null then
|
|
|
|
"--hostlist-exclude ${pkgs.writeText "ZapretBlacklist" (util.trimTabs cfg.blacklist)}"
|
|
|
|
else "";
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
module.zapret = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = types.submodule {
|
|
|
|
options = {
|
|
|
|
enable = mkEnableOption "Enable Zapret service.";
|
|
|
|
params = mkOption {
|
2024-08-28 02:38:36 +03:00
|
|
|
default = null;
|
2024-08-28 01:31:17 +03:00
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
whitelist = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
};
|
|
|
|
blacklist = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
};
|
2024-08-28 02:38:36 +03:00
|
|
|
qnum = mkOption {
|
|
|
|
default = 200;
|
|
|
|
type = types.int;
|
|
|
|
};
|
2024-08-28 01:31:17 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
networking.firewall.extraCommands = ''
|
2024-08-28 02:38:36 +03:00
|
|
|
iptables -t mangle -I POSTROUTING -p tcp -m multiport --dports 80,443 -m connbytes --connbytes-dir=original --connbytes-mode=packets --connbytes 1:6 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num ${toString cfg.qnum} --queue-bypass
|
2024-08-28 01:31:17 +03:00
|
|
|
'';
|
|
|
|
|
|
|
|
systemd = {
|
|
|
|
services.zapret = {
|
|
|
|
description = "FRKN";
|
|
|
|
wantedBy = [ ];
|
|
|
|
requires = [ "network.target" ];
|
|
|
|
path = with pkgs; [ zapret ];
|
|
|
|
serviceConfig = {
|
2024-08-28 02:38:36 +03:00
|
|
|
ExecStart = "${pkgs.zapret}/bin/nfqws --pidfile=/run/nfqws.pid ${cfg.params} ${whitelist} ${blacklist} --qnum=${toString cfg.qnum}";
|
2024-08-28 01:31:17 +03:00
|
|
|
Type = "simple";
|
|
|
|
PIDFile = "/run/nfqws.pid";
|
|
|
|
ExecReload = "/bin/kill -HUP $MAINPID";
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec = "5s";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
timers.zapret = {
|
|
|
|
timerConfig = {
|
|
|
|
OnBootSec = 5;
|
|
|
|
Unit = "zapret.service";
|
|
|
|
};
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|