diff options
Diffstat (limited to 'modules/private')
-rw-r--r-- | modules/private/mail/postfix.nix | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/modules/private/mail/postfix.nix b/modules/private/mail/postfix.nix index fcb0ce2..a679027 100644 --- a/modules/private/mail/postfix.nix +++ b/modules/private/mail/postfix.nix | |||
@@ -1,4 +1,4 @@ | |||
1 | { lib, pkgs, config, myconfig, ... }: | 1 | { lib, pkgs, config, myconfig, ... }: |
2 | { | 2 | { |
3 | config = lib.mkIf config.myServices.mail.enable { | 3 | config = lib.mkIf config.myServices.mail.enable { |
4 | services.duplyBackup.profiles.mail.excludeFile = '' | 4 | services.duplyBackup.profiles.mail.excludeFile = '' |
@@ -97,6 +97,43 @@ | |||
97 | ]; | 97 | ]; |
98 | }; | 98 | }; |
99 | services.postfix = { | 99 | services.postfix = { |
100 | extraAliases = let | ||
101 | toScript = name: script: pkgs.writeScript name '' | ||
102 | #! ${pkgs.stdenv.shell} | ||
103 | mail=$(${pkgs.coreutils}/bin/cat -) | ||
104 | output=$(echo "$mail" | ${script} 2>&1) | ||
105 | ret=$? | ||
106 | |||
107 | if [ "$ret" != "0" ]; then | ||
108 | echo "$mail" \ | ||
109 | | ${pkgs.procmail}/bin/formail -i "X-Return-Code: $ret" \ | ||
110 | | /run/wrappers/bin/sendmail -i scripts_error+${name}@mail.immae.eu | ||
111 | |||
112 | messageId=$(echo "$mail" | ${pkgs.procmail}/bin/formail -x "Message-Id:") | ||
113 | repeat=$(echo "$mail" | ${pkgs.procmail}/bin/formail -X "From:" -X "Received:") | ||
114 | |||
115 | ${pkgs.coreutils}/bin/cat <<EOF | /run/wrappers/bin/sendmail -i scripts_error+${name}@mail.immae.eu | ||
116 | $repeat | ||
117 | To: scripts_error+${name}@mail.immae.eu | ||
118 | Subject: Log from script error | ||
119 | Content-Type: text/plain; charset="UTF-8" | ||
120 | Content-Transfer-Encoding: 8bit | ||
121 | References:$messageId | ||
122 | MIME-Version: 1.0 | ||
123 | X-Return-Code: $ret | ||
124 | |||
125 | Error code: $ret | ||
126 | Output of message: | ||
127 | -------------- | ||
128 | $output | ||
129 | -------------- | ||
130 | EOF | ||
131 | fi | ||
132 | ''; | ||
133 | scripts = lib.attrsets.mapAttrs (n: v: | ||
134 | toScript n (pkgs.callPackage (builtins.fetchGit { url = v.src.url; ref = "master"; rev = v.src.rev; }) { scriptEnv = v.env; }) | ||
135 | ) myconfig.env.mail.scripts; | ||
136 | in builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v: ''${n}: "|${v}"'') scripts); | ||
100 | mapFiles = let | 137 | mapFiles = let |
101 | recipient_maps = let | 138 | recipient_maps = let |
102 | name = n: i: "relay_${n}_${toString i}"; | 139 | name = n: i: "relay_${n}_${toString i}"; |
@@ -120,8 +157,19 @@ | |||
120 | ) | 157 | ) |
121 | ) myconfig.env.mail.postfix.backup_domains | 158 | ) myconfig.env.mail.postfix.backup_domains |
122 | ); | 159 | ); |
160 | virtual_map = { | ||
161 | virtual = pkgs.writeText "postfix-virtual" ( | ||
162 | builtins.concatStringsSep "\n" ( | ||
163 | lib.attrsets.mapAttrsToList ( | ||
164 | n: v: '' | ||
165 | script_${n}@mail.immae.eu ${n}@localhost, scripts@mail.immae.eu | ||
166 | '' | ||
167 | ) myconfig.env.mail.scripts | ||
168 | ) | ||
169 | ); | ||
170 | }; | ||
123 | in | 171 | in |
124 | recipient_maps // relay_restrictions; | 172 | recipient_maps // relay_restrictions // virtual_map; |
125 | config = { | 173 | config = { |
126 | ### postfix module overrides | 174 | ### postfix module overrides |
127 | readme_directory = "${pkgs.postfix}/share/postfix/doc"; | 175 | readme_directory = "${pkgs.postfix}/share/postfix/doc"; |
@@ -130,10 +178,11 @@ | |||
130 | smtp_tls_key_file = lib.mkForce ""; | 178 | smtp_tls_key_file = lib.mkForce ""; |
131 | 179 | ||
132 | message_size_limit = "1073741824"; # Don't put 0 here, it's not equivalent to "unlimited" | 180 | message_size_limit = "1073741824"; # Don't put 0 here, it's not equivalent to "unlimited" |
181 | mailbox_size_limit = "1073741825"; # Workaround, local delivered mails should all go through scripts | ||
133 | alias_database = "\$alias_maps"; | 182 | alias_database = "\$alias_maps"; |
134 | 183 | ||
135 | ### Virtual mailboxes config | 184 | ### Virtual mailboxes config |
136 | virtual_alias_maps = "mysql:${config.secrets.fullPaths."postfix/mysql_alias_maps"}"; | 185 | virtual_alias_maps = "hash:/etc/postfix/virtual mysql:${config.secrets.fullPaths."postfix/mysql_alias_maps"}"; |
137 | virtual_mailbox_domains = myconfig.env.mail.postfix.additional_mailbox_domains | 186 | virtual_mailbox_domains = myconfig.env.mail.postfix.additional_mailbox_domains |
138 | ++ lib.remove "localhost.immae.eu" (lib.remove null (lib.flatten (map | 187 | ++ lib.remove "localhost.immae.eu" (lib.remove null (lib.flatten (map |
139 | (zone: map | 188 | (zone: map |