From 5be9aa417a3993c3fe246c775cae7152ad5ca97d Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 16 Feb 2020 23:08:37 +0100 Subject: [PATCH] neomutt: fix sendMailCommand when msmtp is enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This resolves the error The option `accounts.email.accounts.xyz.neomutt.sendMailCommand` is defined both null and not null, in `…/home-manager/modules/accounts/email.nix' and `…/home-manager/modules/accounts/email.nix'. that would occur previously when both neomutt and msmtp were enabled for an account. --- modules/programs/neomutt-accounts.nix | 18 ++++---- tests/modules/programs/neomutt/default.nix | 5 ++- .../hm-example.com-msmtp-expected.conf | 33 ++++++++++++++ .../programs/neomutt/neomutt-with-msmtp.nix | 44 +++++++++++++++++++ 4 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 tests/modules/programs/neomutt/hm-example.com-msmtp-expected.conf create mode 100644 tests/modules/programs/neomutt/neomutt-with-msmtp.nix diff --git a/modules/programs/neomutt-accounts.nix b/modules/programs/neomutt-accounts.nix index 033db38eb..009cf1fa7 100644 --- a/modules/programs/neomutt-accounts.nix +++ b/modules/programs/neomutt-accounts.nix @@ -8,7 +8,16 @@ with lib; sendMailCommand = mkOption { type = types.nullOr types.str; - default = null; + default = if config.msmtp.enable then + "msmtpq --read-envelope-from --read-recipients" + else + null; + defaultText = literalExample '' + if config.msmtp.enable then + "msmtpq --read-envelope-from --read-recipients" + else + null + ''; example = "msmtpq --read-envelope-from --read-recipients"; description = '' Command to send a mail. If not set, neomutt will be in charge of sending mails. @@ -24,11 +33,4 @@ with lib; ''; }; }; - - config = mkIf config.neomutt.enable { - neomutt.sendMailCommand = mkOptionDefault (if config.msmtp.enable then - "msmtpq --read-envelope-from --read-recipients" - else - null); - }; } diff --git a/tests/modules/programs/neomutt/default.nix b/tests/modules/programs/neomutt/default.nix index 289f2705e..aef9f37e0 100644 --- a/tests/modules/programs/neomutt/default.nix +++ b/tests/modules/programs/neomutt/default.nix @@ -1 +1,4 @@ -{ neomutt-simple = ./neomutt.nix; } +{ + neomutt-simple = ./neomutt.nix; + neomutt-with-msmtp = ./neomutt-with-msmtp.nix; +} diff --git a/tests/modules/programs/neomutt/hm-example.com-msmtp-expected.conf b/tests/modules/programs/neomutt/hm-example.com-msmtp-expected.conf new file mode 100644 index 000000000..1850620f3 --- /dev/null +++ b/tests/modules/programs/neomutt/hm-example.com-msmtp-expected.conf @@ -0,0 +1,33 @@ +# Generated by Home Manager. +set ssl_force_tls = yes +set certificate_file=/etc/ssl/certs/ca-certificates.crt + +# GPG section +set crypt_use_gpgme = yes +set crypt_autosign = no +set pgp_use_gpg_agent = yes +set mbox_type = Maildir +set sort = "threads" + +# MTA section +set sendmail='msmtpq --read-envelope-from --read-recipients' + + + + + +# MRA section +set folder='/home/hm-user/Mail/hm@example.com' +set from='hm@example.com' +set postponed='+Drafts' +set realname='H. M. Test' +set record='+Sent' +set spoolfile='+Inbox' +set trash='+Trash' +color status cyan default + + + +# Extra configuration +color status cyan default + diff --git a/tests/modules/programs/neomutt/neomutt-with-msmtp.nix b/tests/modules/programs/neomutt/neomutt-with-msmtp.nix new file mode 100644 index 000000000..5f94d21a1 --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-with-msmtp.nix @@ -0,0 +1,44 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + config = { + home.username = "hm-user"; + home.homeDirectory = "/home/hm-user"; + xdg.configHome = mkForce "/home/hm-user/.config"; + xdg.cacheHome = mkForce "/home/hm-user/.cache"; + + accounts.email.accounts = { + "hm@example.com" = { + primary = true; + msmtp.enable = true; + neomutt = { + enable = true; + extraConfig = '' + color status cyan default + ''; + }; + imap.port = 993; + }; + }; + + programs.neomutt.enable = true; + + nixpkgs.overlays = + [ (self: super: { neomutt = pkgs.writeScriptBin "dummy-neomutt" ""; }) ]; + + nmt.script = '' + assertFileExists home-files/.config/neomutt/neomuttrc + assertFileExists home-files/.config/neomutt/hm@example.com + assertFileContent home-files/.config/neomutt/neomuttrc ${ + ./neomutt-expected.conf + } + assertFileContent home-files/.config/neomutt/hm@example.com ${ + ./hm-example.com-msmtp-expected.conf + } + ''; + }; +}