summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hosts/surtr/email/default.nix8
-rw-r--r--modules/postfwd.nix27
2 files changed, 30 insertions, 5 deletions
diff --git a/hosts/surtr/email/default.nix b/hosts/surtr/email/default.nix
index 66c39e8f..4d75dfae 100644
--- a/hosts/surtr/email/default.nix
+++ b/hosts/surtr/email/default.nix
@@ -902,9 +902,13 @@ in {
902 902
903 services.postfwd = { 903 services.postfwd = {
904 enable = true; 904 enable = true;
905 cache = false;
905 rules = '' 906 rules = ''
906 id=RCPT01; protocol_state=DATA; protocol_state=END-OF-MESSAGE; action=rcpt(ccert_subject/100/3600/set(HIT_RATELIMIT=1,HIT_RATECOUNT=$$ratecount,HIT_RATELIMIT_LIMIT=100,HIT_RATELIMIT_INTERVAL=3600)) 907 id=RCPT_SASL01; protocol_state=DATA; protocol_state=END-OF-MESSAGE; sasl_username!=; action=rcpt(sasl_username/100/3600/set(HIT_RATELIMIT=1,HIT_RATECOUNT=$$ratecount,HIT_RATELIMIT_LIMIT=100,HIT_RATELIMIT_INTERVAL=3600))
907 id=RCPT02; protocol_state=DATA; protocol_state=END-OF-MESSAGE; action=rcpt(ccert_subject/1000/86400/set(HIT_RATELIMIT=1,HIT_RATECOUNT=$$ratecount,HIT_RATELIMIT_LIMIT=1000,HIT_RATELIMIT_INTERVAL=86400)) 908 id=RCPT_SASL02; protocol_state=DATA; protocol_state=END-OF-MESSAGE; sasl_username!=; action=rcpt(sasl_username/1000/86400/set(HIT_RATELIMIT=1,HIT_RATECOUNT=$$ratecount,HIT_RATELIMIT_LIMIT=1000,HIT_RATELIMIT_INTERVAL=86400))
909
910 id=RCPT_CCERT01; protocol_state=DATA; protocol_state=END-OF-MESSAGE; ccert_subject!=; action=rcpt(ccert_subject/100/3600/set(HIT_RATELIMIT=1,HIT_RATECOUNT=$$ratecount,HIT_RATELIMIT_LIMIT=100,HIT_RATELIMIT_INTERVAL=3600))
911 id=RCPT_CCERT02; protocol_state=DATA; protocol_state=END-OF-MESSAGE; ccert_subject!=; action=rcpt(ccert_subject/1000/86400/set(HIT_RATELIMIT=1,HIT_RATECOUNT=$$ratecount,HIT_RATELIMIT_LIMIT=1000,HIT_RATELIMIT_INTERVAL=86400))
908 912
909 id=JUMP_REJECT_RL; HIT_RATELIMIT=="1"; action=jump(REJECT_RL) 913 id=JUMP_REJECT_RL; HIT_RATELIMIT=="1"; action=jump(REJECT_RL)
910 914
diff --git a/modules/postfwd.nix b/modules/postfwd.nix
index e10c04a7..2ecfe9ab 100644
--- a/modules/postfwd.nix
+++ b/modules/postfwd.nix
@@ -9,6 +9,10 @@ in {
9 services.postfwd = with types; { 9 services.postfwd = with types; {
10 enable = mkEnableOption "postfwd3 - postfix firewall daemon"; 10 enable = mkEnableOption "postfwd3 - postfix firewall daemon";
11 11
12 cache = mkEnableOption "postfwd3 cache" // {
13 default = true;
14 };
15
12 rules = mkOption { 16 rules = mkOption {
13 type = lines; 17 type = lines;
14 default = ""; 18 default = "";
@@ -25,7 +29,7 @@ in {
25 serviceConfig = { 29 serviceConfig = {
26 Type = "forking"; 30 Type = "forking";
27 31
28 ExecStart = "${pkgs.postfwd}/bin/postfwd3 ${escapeShellArgs [ 32 ExecStart = "${pkgs.postfwd}/bin/postfwd3 ${escapeShellArgs ([
29 "-vv" 33 "-vv"
30 "--daemon" "--user" "postfwd" "--group" "postfwd" 34 "--daemon" "--user" "postfwd" "--group" "postfwd"
31 "--pidfile" "/run/postfwd3/postfwd3.pid" 35 "--pidfile" "/run/postfwd3/postfwd3.pid"
@@ -34,11 +38,14 @@ in {
34 "--save_rates" "/var/lib/postfwd/rates" 38 "--save_rates" "/var/lib/postfwd/rates"
35 "--save_groups" "/var/lib/postfwd/groups" 39 "--save_groups" "/var/lib/postfwd/groups"
36 "--summary" "3600" 40 "--summary" "3600"
41 "--file" (pkgs.writeText "postfwd3-rules" cfg.rules)
42 ] ++ lib.optionals cfg.cache [
37 "--cache" "600" 43 "--cache" "600"
38 "--cache_proto" "unix" 44 "--cache_proto" "unix"
39 "--cache_port" "/run/postfwd3/cache.sock" 45 "--cache_port" "/run/postfwd3/cache.sock"
40 "--file" (pkgs.writeText "postfwd3-rules" cfg.rules) 46 ] ++ lib.optionals (!cfg.cache) [
41 ]}"; 47 "--cache" "0"
48 ])}";
42 PIDFile = "/run/postfwd3/postfwd3.pid"; 49 PIDFile = "/run/postfwd3/postfwd3.pid";
43 50
44 Restart = "always"; 51 Restart = "always";
@@ -78,5 +85,19 @@ in {
78 IPAddressDeny = "any"; 85 IPAddressDeny = "any";
79 }; 86 };
80 }; 87 };
88
89 environment.systemPackages = [
90 (pkgs.postfwd.overrideAttrs (oldAttrs: {
91 nativeBuildInputs = (oldAttrs.nativeBuildInputs or []) ++ [ pkgs.makeWrapper pkgs.coreutils ];
92
93 postInstall = ''
94 ${oldAttrs.postInstall or ""}
95
96 wrapProgram $out/bin/postfwd3 \
97 --add-flags "--proto unix --port /run/postfwd3/postfwd3.sock"
98 ln -s postfwd3 $out/bin/postfwd
99 '';
100 }))
101 ];
81 }; 102 };
82} 103}