From 75c2fb503b999f019929be2dd6f44cc00ff29a1e Mon Sep 17 00:00:00 2001 From: ChUrl Date: Sat, 12 Nov 2022 13:18:46 +0100 Subject: [PATCH] add auto mail sync without imapnotify --- home/christoph/default.nix | 2 ++ home/modules/email.nix | 29 +++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/home/christoph/default.nix b/home/christoph/default.nix index 691c203d..b8ee51b5 100644 --- a/home/christoph/default.nix +++ b/home/christoph/default.nix @@ -40,6 +40,8 @@ in rec { email = { enable = true; + autosync = true; + imapnotify = false; # Use kmail as viewer for stuff synced by mbsync kmail = { diff --git a/home/modules/email.nix b/home/modules/email.nix index e52ce7bb..10756de1 100644 --- a/home/modules/email.nix +++ b/home/modules/email.nix @@ -15,6 +15,9 @@ in { options.modules.email = { enable = mkEnableOpt "Email"; + autosync = mkEnableOpt "Automatically call \"notmuch new\" via systemd timer"; + imapnotify = mkEnableOpt "Use imapnotify to sync and index mail automatically"; + kmail = { enable = mkEnableOpt "Kmail"; autostart = mkEnableOpt "Autostart Kmail"; @@ -47,7 +50,25 @@ in { }; # TODO: imapnotify can't parse the configuration, HM bug? - services.imapnotify.enable = true; + services.imapnotify.enable = cfg.imapnotify; + + # Autosync, don't need imapnotify when enabled + systemd.user.services.mail-autosync = (mkIf cfg.autosync) { + Unit = { Description = "Automatic notmuch/mbsync synchronization"; }; + Service = { + Type = "oneshot"; + # ExecStart = "${pkgs.isync}/bin/mbsync -a"; + ExecStart = "${pkgs.notmuch}/bin/notmuch new"; + }; + }; + systemd.user.timers.mail-autosync = (mkIf cfg.autosync) { + Unit = { Description = "Automatic notmuch/mbsync synchronization"; }; + Timer = { + OnBootSec = "30"; + OnUnitActiveSec = "5m"; + }; + Install = { WantedBy = [ "timers.target" ]; }; + }; accounts.email.accounts = { urpost = { @@ -69,7 +90,7 @@ in { }; msmtp.enable = true; # Smtp notmuch.enable = true; - imapnotify.enable = true; + imapnotify.enable = cfg.imapnotify; imapnotify.onNotify = { mail = "${pkgs.notmuch}/bin/notmuch new && ${pkgs.libnotify}/bin/notify-send 'New mail arrived on Urpost'"; }; @@ -96,7 +117,7 @@ in { }; msmtp.enable = true; # Smtp notmuch.enable = true; - imapnotify.enable = true; + imapnotify.enable = cfg.imapnotify; imapnotify.onNotify = { mail = "${pkgs.notmuch}/bin/notmuch new && ${pkgs.libnotify}/bin/notify-send 'New mail arrived on HHU'"; }; @@ -123,7 +144,7 @@ in { }; msmtp.enable = true; # Smtp notmuch.enable = true; - imapnotify.enable = true; + imapnotify.enable = cfg.imapnotify; imapnotify.onNotify = { mail = "${pkgs.notmuch}/bin/notmuch new && ${pkgs.libnotify}/bin/notify-send 'New mail arrived on GMail'"; };