From 24805d3ca73f7d4c34239efaa1c73d2d4558a8ea Mon Sep 17 00:00:00 2001 From: SiriusStarr <2049163+SiriusStarr@users.noreply.github.com> Date: Mon, 3 Jul 2023 11:30:11 -0700 Subject: [PATCH] himalaya: fix notmuch backend Previously, IMAP was preferred over notmuch, even if notmuch was configured, causing problems with setting account flavor (which automatically sets IMAP settings). The new backend order is: notmuch > IMAP > maildir This also fixes the notmuch DB path being set to the wrong location. The notmuch DB is located at the maildir base path, not in each account's maildir. --- modules/programs/himalaya.nix | 16 ++++++++++------ .../himalaya/notmuch-sendmail-expected.toml | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/programs/himalaya.nix b/modules/programs/himalaya.nix index 1a57ec893..673bd7de5 100644 --- a/modules/programs/himalaya.nix +++ b/modules/programs/himalaya.nix @@ -8,14 +8,18 @@ let # attrs util that removes entries containing a null value compactAttrs = lib.filterAttrs (_: val: !isNull val); + # Needed for notmuch config, because the DB is here, and not in each account's dir + maildirBasePath = config.accounts.email.maildirBasePath; + # make a himalaya config from a home-manager email account config mkAccountConfig = _: account: let - imapEnabled = !isNull account.imap; - maildirEnabled = !imapEnabled && !isNull account.maildir - && !account.notmuch.enable; - notmuchEnabled = !imapEnabled && !isNull account.maildir - && account.notmuch.enable; + # Use notmuch if it's enabled, otherwise fallback to IMAP then maildir + # Maildir is always set, so there's no easy way to detect if it's being used + notmuchEnabled = account.notmuch.enable; + imapEnabled = !isNull account.imap && !notmuchEnabled; + maildirEnabled = !isNull account.maildir && !imapEnabled + && !notmuchEnabled; globalConfig = { email = account.address; @@ -55,7 +59,7 @@ let notmuchConfig = lib.optionalAttrs notmuchEnabled (compactAttrs { backend = "notmuch"; - notmuch-db-path = account.maildir.absPath; + notmuch-db-path = maildirBasePath; }); smtpConfig = lib.optionalAttrs (!isNull account.smtp) (compactAttrs { diff --git a/tests/modules/programs/himalaya/notmuch-sendmail-expected.toml b/tests/modules/programs/himalaya/notmuch-sendmail-expected.toml index 1eaa511ba..fcc00c7c8 100644 --- a/tests/modules/programs/himalaya/notmuch-sendmail-expected.toml +++ b/tests/modules/programs/himalaya/notmuch-sendmail-expected.toml @@ -5,7 +5,7 @@ backend = "notmuch" default = true display-name = "H. M. Test" email = "hm@example.com" -notmuch-db-path = "/home/hm-user/Maildir/hm@example.com" +notmuch-db-path = "/home/hm-user/Maildir" sender = "sendmail" sendmail-cmd = "msmtp"