diff options
Diffstat (limited to 'modules/private/mail/postfix.nix')
-rw-r--r-- | modules/private/mail/postfix.nix | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/modules/private/mail/postfix.nix b/modules/private/mail/postfix.nix index 8fe06da..51f4de7 100644 --- a/modules/private/mail/postfix.nix +++ b/modules/private/mail/postfix.nix | |||
@@ -1,4 +1,4 @@ | |||
1 | { lib, pkgs, config, nodes, name, ... }: | 1 | { lib, pkgs, config, nodes, ... }: |
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 = '' |
@@ -220,7 +220,13 @@ | |||
220 | ''; | 220 | ''; |
221 | scripts = lib.attrsets.mapAttrs (n: v: | 221 | scripts = lib.attrsets.mapAttrs (n: v: |
222 | toScript n (pkgs.callPackage (builtins.fetchGit { url = v.src.url; ref = "master"; rev = v.src.rev; }) { scriptEnv = v.env; }) | 222 | toScript n (pkgs.callPackage (builtins.fetchGit { url = v.src.url; ref = "master"; rev = v.src.rev; }) { scriptEnv = v.env; }) |
223 | ) config.myEnv.mail.scripts; | 223 | ) config.myEnv.mail.scripts // { |
224 | testmail = pkgs.writeScript "testmail" '' | ||
225 | #! ${pkgs.stdenv.shell} | ||
226 | ${pkgs.coreutils}/bin/touch \ | ||
227 | "/var/lib/naemon/checks/email/$(${pkgs.procmail}/bin/formail -x To: | ${pkgs.coreutils}/bin/tr -d ' <>')" | ||
228 | ''; | ||
229 | }; | ||
224 | in builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v: ''${n}: "|${v}"'') scripts); | 230 | in builtins.concatStringsSep "\n" (lib.attrsets.mapAttrsToList (n: v: ''${n}: "|${v}"'') scripts); |
225 | mapFiles = let | 231 | mapFiles = let |
226 | recipient_maps = let | 232 | recipient_maps = let |
@@ -246,8 +252,12 @@ | |||
246 | ) config.myEnv.mail.postfix.backup_domains | 252 | ) config.myEnv.mail.postfix.backup_domains |
247 | ); | 253 | ); |
248 | virtual_map = { | 254 | virtual_map = { |
249 | virtual = pkgs.writeText "postfix-virtual" ( | 255 | virtual = let |
256 | cfg = config.myEnv.monitoring.email_check.eldiron; | ||
257 | address = "${cfg.mail_address}@${cfg.mail_domain}"; | ||
258 | in pkgs.writeText "postfix-virtual" ( | ||
250 | builtins.concatStringsSep "\n" ( | 259 | builtins.concatStringsSep "\n" ( |
260 | ["${address} testmail@localhost"] ++ | ||
251 | lib.attrsets.mapAttrsToList ( | 261 | lib.attrsets.mapAttrsToList ( |
252 | n: v: lib.optionalString v.external '' | 262 | n: v: lib.optionalString v.external '' |
253 | script_${n}@mail.immae.eu ${n}@localhost, scripts@mail.immae.eu | 263 | script_${n}@mail.immae.eu ${n}@localhost, scripts@mail.immae.eu |
@@ -425,5 +435,25 @@ | |||
425 | "smtp.immae.eu" = null; | 435 | "smtp.immae.eu" = null; |
426 | }; | 436 | }; |
427 | }; | 437 | }; |
438 | system.activationScripts.testmail = { | ||
439 | deps = [ "users" ]; | ||
440 | text = let | ||
441 | allCfg = config.myEnv.monitoring.email_check; | ||
442 | cfg = allCfg.eldiron; | ||
443 | reverseTargets = builtins.attrNames (lib.attrsets.filterAttrs (k: v: builtins.elem "eldiron" v.targets) allCfg); | ||
444 | to_email = cfg': host': | ||
445 | let sep = if lib.strings.hasInfix "+" cfg'.mail_address then "_" else "+"; | ||
446 | in "${cfg'.mail_address}${sep}${host'}@${cfg'.mail_domain}"; | ||
447 | mails_to_receive = builtins.concatStringsSep " " (map (to_email cfg) reverseTargets); | ||
448 | in '' | ||
449 | install -m 0555 -o nobody -g nogroup -d /var/lib/naemon/checks/email | ||
450 | for f in ${mails_to_receive}; do | ||
451 | if [ ! -f /var/lib/naemon/checks/email/$f ]; then | ||
452 | install -m 0644 -o nobody -g nogroup /dev/null -T /var/lib/naemon/checks/email/$f | ||
453 | touch -m -d @0 /var/lib/naemon/checks/email/$f | ||
454 | fi | ||
455 | done | ||
456 | ''; | ||
457 | }; | ||
428 | }; | 458 | }; |
429 | } | 459 | } |