From 9ce6977fe76fb408042a432e314764f8d1d86263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Wed, 21 Jun 2023 10:59:29 +0200 Subject: [PATCH] himalaya: adjust module for 0.8.X (#4093) Added notmuch support, and adjust password commands configuration. --- modules/programs/himalaya.nix | 36 +++++++++++++------ .../programs/himalaya/basic-expected.toml | 10 ++++-- tests/modules/programs/himalaya/basic.nix | 4 +-- tests/modules/programs/himalaya/default.nix | 1 + .../programs/himalaya/imap-smtp-expected.toml | 10 ++++-- .../programs/himalaya/maildir-sendmail.nix | 6 ++-- .../himalaya/notmuch-sendmail-expected.toml | 16 +++++++++ .../programs/himalaya/notmuch-sendmail.nix | 36 +++++++++++++++++++ 8 files changed, 98 insertions(+), 21 deletions(-) create mode 100644 tests/modules/programs/himalaya/notmuch-sendmail-expected.toml create mode 100644 tests/modules/programs/himalaya/notmuch-sendmail.nix diff --git a/modules/programs/himalaya.nix b/modules/programs/himalaya.nix index 54f8d1ec..1a57ec89 100644 --- a/modules/programs/himalaya.nix +++ b/modules/programs/himalaya.nix @@ -11,6 +11,12 @@ let # 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; + globalConfig = { email = account.address; display-name = account.realName; @@ -31,22 +37,26 @@ let signature-delim = account.signature.delimiter; }; - imapConfig = lib.optionalAttrs (!isNull account.imap) (compactAttrs { + imapConfig = lib.optionalAttrs imapEnabled (compactAttrs { backend = "imap"; imap-host = account.imap.host; imap-port = account.imap.port; imap-ssl = account.imap.tls.enable; imap-starttls = account.imap.tls.useStartTls; imap-login = account.userName; - imap-passwd-cmd = builtins.concatStringsSep " " account.passwordCommand; + imap-auth = "passwd"; + imap-passwd.cmd = builtins.concatStringsSep " " account.passwordCommand; }); - maildirConfig = - lib.optionalAttrs (isNull account.imap && !isNull account.maildir) - (compactAttrs { - backend = "maildir"; - maildir-root-dir = account.maildir.absPath; - }); + maildirConfig = lib.optionalAttrs maildirEnabled (compactAttrs { + backend = "maildir"; + maildir-root-dir = account.maildir.absPath; + }); + + notmuchConfig = lib.optionalAttrs notmuchEnabled (compactAttrs { + backend = "notmuch"; + notmuch-db-path = account.maildir.absPath; + }); smtpConfig = lib.optionalAttrs (!isNull account.smtp) (compactAttrs { sender = "smtp"; @@ -55,14 +65,18 @@ let smtp-ssl = account.smtp.tls.enable; smtp-starttls = account.smtp.tls.useStartTls; smtp-login = account.userName; - smtp-passwd-cmd = builtins.concatStringsSep " " account.passwordCommand; + smtp-auth = "passwd"; + smtp-passwd.cmd = builtins.concatStringsSep " " account.passwordCommand; }); sendmailConfig = - lib.optionalAttrs (isNull account.smtp) { sender = "sendmail"; }; + lib.optionalAttrs (isNull account.smtp && !isNull account.msmtp) { + sender = "sendmail"; + sendmail-cmd = "${pkgs.msmtp}/bin/msmtp"; + }; config = globalConfig // signatureConfig // imapConfig // maildirConfig - // smtpConfig // sendmailConfig; + // notmuchConfig // smtpConfig // sendmailConfig; in lib.recursiveUpdate config account.himalaya.settings; diff --git a/tests/modules/programs/himalaya/basic-expected.toml b/tests/modules/programs/himalaya/basic-expected.toml index abda4a13..2df6b85f 100644 --- a/tests/modules/programs/himalaya/basic-expected.toml +++ b/tests/modules/programs/himalaya/basic-expected.toml @@ -3,16 +3,16 @@ backend = "imap" default = true display-name = "H. M. Test" email = "hm@example.com" +imap-auth = "passwd" imap-host = "imap.example.com" imap-login = "home.manager" -imap-passwd-cmd = "password-command" imap-port = 993 imap-ssl = true imap-starttls = false sender = "smtp" +smtp-auth = "passwd" smtp-host = "smtp.example.com" smtp-login = "home.manager" -smtp-passwd-cmd = "password-command" smtp-port = 465 smtp-ssl = true smtp-starttls = false @@ -22,3 +22,9 @@ drafts = "Drafts" inbox = "Inbox" sent = "Sent" trash = "Trash" + +["hm@example.com".imap-passwd] +cmd = "password-command" + +["hm@example.com".smtp-passwd] +cmd = "password-command" diff --git a/tests/modules/programs/himalaya/basic.nix b/tests/modules/programs/himalaya/basic.nix index e2a8fa83..1555d1e9 100644 --- a/tests/modules/programs/himalaya/basic.nix +++ b/tests/modules/programs/himalaya/basic.nix @@ -10,8 +10,8 @@ with lib; imap.port = 993; smtp.port = 465; himalaya.enable = true; - himalaya.backend = "deprecated"; - himalaya.sender = "deprecated"; + himalaya.backend = test.asserts.warnings.expected; + himalaya.sender = test.asserts.warnings.expected; }; }; diff --git a/tests/modules/programs/himalaya/default.nix b/tests/modules/programs/himalaya/default.nix index e5473344..b357361e 100644 --- a/tests/modules/programs/himalaya/default.nix +++ b/tests/modules/programs/himalaya/default.nix @@ -2,4 +2,5 @@ himalaya-basic = ./basic.nix; himalaya-imap-smtp = ./imap-smtp.nix; himalaya-maildir-sendmail = ./maildir-sendmail.nix; + himalaya-notmuch-sendmail = ./notmuch-sendmail.nix; } diff --git a/tests/modules/programs/himalaya/imap-smtp-expected.toml b/tests/modules/programs/himalaya/imap-smtp-expected.toml index bcfee047..6db2542d 100644 --- a/tests/modules/programs/himalaya/imap-smtp-expected.toml +++ b/tests/modules/programs/himalaya/imap-smtp-expected.toml @@ -7,16 +7,16 @@ display-name = "H. M. Test" email = "hm@example.com" email-listing-page-size = 50 folder-listing-page-size = 50 +imap-auth = "passwd" imap-host = "imap.example.com" imap-login = "home.manager" -imap-passwd-cmd = "password-command" imap-port = 143 imap-ssl = false imap-starttls = false sender = "smtp" +smtp-auth = "passwd" smtp-host = "smtp.example.com" smtp-login = "home.manager" -smtp-passwd-cmd = "password-command" smtp-port = 465 smtp-ssl = true smtp-starttls = true @@ -27,3 +27,9 @@ drafts = "D" inbox = "In2" sent = "Out" trash = "Trash" + +["hm@example.com".imap-passwd] +cmd = "password-command" + +["hm@example.com".smtp-passwd] +cmd = "password-command" diff --git a/tests/modules/programs/himalaya/maildir-sendmail.nix b/tests/modules/programs/himalaya/maildir-sendmail.nix index a9d15d22..d40f39ba 100644 --- a/tests/modules/programs/himalaya/maildir-sendmail.nix +++ b/tests/modules/programs/himalaya/maildir-sendmail.nix @@ -11,12 +11,10 @@ with lib; realName = "H. M. Test"; passwordCommand = "password-command"; folders = { trash = "Deleted"; }; + msmtp.enable = true; himalaya = { enable = true; - settings = { - sender = "sendmail"; - sendmail-cmd = "msmtp"; - }; + settings = { sendmail-cmd = "msmtp"; }; }; }; }; diff --git a/tests/modules/programs/himalaya/notmuch-sendmail-expected.toml b/tests/modules/programs/himalaya/notmuch-sendmail-expected.toml new file mode 100644 index 00000000..1eaa511b --- /dev/null +++ b/tests/modules/programs/himalaya/notmuch-sendmail-expected.toml @@ -0,0 +1,16 @@ +email-listing-page-size = 50 + +["hm@example.com"] +backend = "notmuch" +default = true +display-name = "H. M. Test" +email = "hm@example.com" +notmuch-db-path = "/home/hm-user/Maildir/hm@example.com" +sender = "sendmail" +sendmail-cmd = "msmtp" + +["hm@example.com".folder-aliases] +drafts = "Drafts" +inbox = "Inbox" +sent = "Sent" +trash = "Deleted" diff --git a/tests/modules/programs/himalaya/notmuch-sendmail.nix b/tests/modules/programs/himalaya/notmuch-sendmail.nix new file mode 100644 index 00000000..ff96dfd1 --- /dev/null +++ b/tests/modules/programs/himalaya/notmuch-sendmail.nix @@ -0,0 +1,36 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + accounts.email.accounts = { + "hm@example.com" = { + primary = true; + address = "hm@example.com"; + userName = "home.manager"; + realName = "H. M. Test"; + passwordCommand = "password-command"; + folders = { trash = "Deleted"; }; + notmuch.enable = true; + msmtp.enable = true; + himalaya = { + enable = true; + settings = { sendmail-cmd = "msmtp"; }; + }; + }; + }; + + programs.himalaya = { + enable = true; + settings = { email-listing-page-size = 50; }; + }; + + test.stubs.himalaya = { }; + + nmt.script = '' + assertFileExists home-files/.config/himalaya/config.toml + assertFileContent home-files/.config/himalaya/config.toml ${ + ./notmuch-sendmail-expected.toml + } + ''; +}