From 171eda1d70dfa980a7dbb378d1c0a2b8b5f67c35 Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Sun, 1 Oct 2023 12:04:09 +0100 Subject: [PATCH] Run davmail with podman container Enable all accounts by default Add easy switch to disable if needed --- home/accounts/email.nix | 62 +++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/home/accounts/email.nix b/home/accounts/email.nix index 729e2406..3bf11414 100644 --- a/home/accounts/email.nix +++ b/home/accounts/email.nix @@ -26,6 +26,7 @@ proton = let host = "127.0.0.1"; tls.enable = false; + accountEnabled = true; in rec { inherit realName; primary = lib.mkDefault true; @@ -44,7 +45,7 @@ passwordCommand = "${pkgs.libsecret}/bin/secret-tool lookup email ${userName}"; imapnotify = { - enable = true; + enable = lib.mkDefault accountEnabled; boxes = [ "INBOX" ]; onNotify = "${pkgs.isync}/bin/mbsync --pull proton:INBOX"; onNotifyPost = @@ -56,7 +57,7 @@ }; }; mbsync = { - enable = true; + enable = lib.mkDefault accountEnabled; create = "both"; expunge = "both"; remove = "both"; @@ -65,15 +66,16 @@ extraConfig.account.AuthMechs = "LOGIN"; }; msmtp = { - enable = true; + enable = lib.mkDefault accountEnabled; extraConfig = { tls = "off"; auth = "login"; }; }; - mu.enable = true; + mu.enable = lib.mkDefault accountEnabled; }; - icloud = rec { + icloud = let accountEnabled = true; + in rec { inherit realName; primary = lib.mkDefault false; # TEMP until proton is fixed maildir.path = "iCloud"; @@ -84,7 +86,7 @@ passwordCommand = "${pkgs.libsecret}/bin/secret-tool lookup email ${userName}"; imapnotify = { - enable = true; + enable = lib.mkDefault accountEnabled; boxes = [ "INBOX" ]; onNotify = "${pkgs.isync}/bin/mbsync --pull icloud:INBOX"; onNotifyPost = @@ -92,19 +94,20 @@ extraConfig.wait = 300; }; mbsync = { - enable = true; + enable = lib.mkDefault accountEnabled; create = "both"; expunge = "both"; remove = "both"; patterns = [ "*" "!Junk" ]; subFolders = "Verbatim"; }; - msmtp.enable = true; - mu.enable = true; + msmtp.enable = lib.mkDefault accountEnabled; + mu.enable = lib.mkDefault accountEnabled; }; ukaea = let host = "127.0.0.1"; tls.enable = false; + accountEnabled = true; in rec { inherit realName; primary = lib.mkDefault false; @@ -123,6 +126,7 @@ passwordCommand = "${pkgs.libsecret}/bin/secret-tool lookup email ${userName}"; imapnotify = { + enable = lib.mkDefault accountEnabled; boxes = [ "INBOX" ]; onNotify = "${pkgs.isync}/bin/mbsync --pull ukaea:INBOX"; onNotifyPost = @@ -134,6 +138,7 @@ }; }; mbsync = { + enable = lib.mkDefault accountEnabled; create = "both"; expunge = "both"; remove = "both"; @@ -143,9 +148,11 @@ extraConfig.account.AuthMechs = "LOGIN"; }; msmtp.extraConfig = { + enable = lib.mkDefault accountEnabled; tls = "off"; auth = "login"; }; + mu.enable = lib.mkDefault accountEnabled; }; }; }; @@ -159,8 +166,7 @@ After = [ "network-online.target" ]; RequiresMountsFor = "%t/containers"; }; - Service = let name = "protonmail-bridge"; - in { + Service = { Environment = "PODMAN_SYSTEMD_UNIT=%n"; Restart = "always"; TimeoutStopSec = 70; @@ -196,12 +202,40 @@ }; davmail = lib.mkIf config.accounts.email.accounts.ukaea.mbsync.enable { Unit = { - Description = "DavMail"; - After = [ "network.target" ]; + Description = "Podman container-davmail.service"; + Documentation = [ "man:podman-generate-systemd(1)" ]; + Wants = [ "network-online.target" ]; + After = [ "network-online.target" ]; + RequiresMountsFor = "%t/containers"; }; Service = { + Environment = "PODMAN_SYSTEMD_UNIT=%n"; Restart = "always"; - ExecStart = "${pkgs.davmail}/bin/davmail -notray"; + TimeoutStopSec = 70; + ExecStart = '' + ${pkgs.podman}/bin/podman run \ + --cidfile=%t/%n.ctr-id \ + --cgroups=no-conmon \ + --rm \ + --sdnotify=conmon \ + --replace \ + -d \ + --name=davmail \ + -p 127.0.0.1:1026:1025 \ + -p 127.0.0.1:1144:1143 \ + -p 127.0.0.1:1080:1080 connectical/davmail + ''; + ExecStop = '' + ${pkgs.podman}/bin/podman stop \ + --ignore -t 10 \ + --cidfile=%t/%n.ctr-id''; + ExecStopPost = '' + ${pkgs.podman}/bin/podman rm \ + -f \ + --ignore -t 10 \ + --cidfile=%t/%n.ctr-id''; + Type = "notify"; + NotifyAccess = "all"; }; Install.WantedBy = [ "graphical-session.target"