nix: fix flake:nixpkgs
[sourcephile-nix.git] / hosts / mermet / dovecot.nix
index 82acd7cb83d54a42ec28cbed9e392b227debb805..915e5493f1b1164b1c0771cb280d282308152556 100644 (file)
@@ -78,6 +78,11 @@ systemd.services.dovecot2 = {
      ${stateDir}/mail
   '';
   */
+  preStart = ''
+    ln -fns -t ${stateDir}/virtual/ \
+      ${dovecot-virtual-all}/All \
+      ${dovecot-virtual-recents}/Recents
+  '';
   serviceConfig = {
     #ExecStart = lib.mkForce "${pkgs.utillinux}/bin/setarch x86_64 --addr-no-randomize /bin/sh -c 'LD_PRELOAD=${pkgs.gcc-unwrapped.lib}/lib/libasan.so ${pkgs.dovecot}/sbin/dovecot -F'";
     # Dovecot2 does not work with environment.memoryAllocator.provider="scudo"
@@ -85,6 +90,7 @@ systemd.services.dovecot2 = {
     # Scudo ERROR: CHECK failed at /build/compiler-rt-7.1.0.src/lib/scudo/../sanitizer_common/sanitizer_allocator_primary64.h:
     # 644 ((beg)) == ((address_range.MapOrDie(beg, size))) (4398046511092, 4398046507008)
     BindReadOnlyPaths = [ "/dev/null:/etc/ld-nix.so.preload" ];
+    StateDirectory = ["dovecot/virtual"];
   };
 };
 #users.users."${dovecot2.mailUser}".isSystemUser = true; # Fix nixpkgs
@@ -93,6 +99,15 @@ networking.nftables.ruleset = ''
   #add rule inet filter net2fw tcp dport 995 counter accept comment "POP3S"
   add rule inet filter net2fw tcp dport 4190 counter accept comment "Sieve"
 '';
+fileSystems."/var/lib/dovecot" = {
+  device = "rpool/var/mail";
+  fsType = "zfs";
+};
+services.sanoid.datasets."rpool/var/mail" = {
+  use_template = [ "snap" ];
+  hourly = 12;
+  daily = 7;
+};
 services.dovecot2 = {
   enable = true;
   modules = [
@@ -273,7 +288,7 @@ services.dovecot2 = {
     protocol lda {
       hostname = ${networking.domain}
       mail_plugins = $mail_plugins sieve
-      postmaster_address = postmaster+dovecot+lda@${networking.domain}
+      postmaster_address = root+dovecot+lda@${networking.domain}
       syslog_facility = mail
     }
     lda_mailbox_autocreate = yes
@@ -281,7 +296,7 @@ services.dovecot2 = {
 
     protocol lmtp {
       mail_plugins = $mail_plugins sieve
-      postmaster_address = postmaster+dovecot+lmtp@${networking.domain}
+      postmaster_address = root+dovecot+lmtp@${networking.domain}
     }
     service lmtp {
       process_min_avail = ${toString host.CPUs}
@@ -482,7 +497,7 @@ services.dovecot2 = {
           USER=$2
           cat << EOF | ${pkgs.dovecot}/libexec/dovecot/dovecot-lda -d $USER -o
           "plugin/quota=maildir:User quota:noenforcing"
-          From: postmaster@${networking.domain}
+          From: root+docevot@${networking.domain}
           Subject: [WARNING] your mailbox is now $PERCENT% full.
 
           Please remove some mails to make room for new ones.