neomutt: fix sendMailCommand when msmtp is enabled

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.
This commit is contained in:
Robert Helgesson 2020-02-16 23:08:37 +01:00
parent 7a3e2cc063
commit 5be9aa417a
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
4 changed files with 91 additions and 9 deletions

View file

@ -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);
};
}

View file

@ -1 +1,4 @@
{ neomutt-simple = ./neomutt.nix; }
{
neomutt-simple = ./neomutt.nix;
neomutt-with-msmtp = ./neomutt-with-msmtp.nix;
}

View file

@ -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

View file

@ -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
}
'';
};
}