1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-05 16:41:04 +01:00

neomutt: improve error when no way to send mail

f there's an account under accounts.email.accounts with neomutt.enable set to true but neither passwordCommand nor neomutt.sendMailCommand set, then building the Neomutt rc file will fail. Ensure that failure has a useful error message, rather than a confusing type error.

While we're here, make the module code slightly less repetitious by just building the set of email accounts that have Neomutt enabled once, rather than multiple times in multiple contexts.
This commit is contained in:
Adam Dinwoodie 2025-07-09 21:33:38 +01:00 committed by GitHub
parent bec8ff3981
commit 206ed3c714
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,7 @@ let
concatStringsSep
concatMapStringsSep
filter
filterAttrs
isString
mkIf
mkOption
@ -19,22 +20,20 @@ let
cfg = config.programs.neomutt;
neomuttAccounts = filter (a: a.neomutt.enable) (attrValues config.accounts.email.accounts);
neomuttAccountsCfg = filterAttrs (n: a: a.neomutt.enable) config.accounts.email.accounts;
neomuttAccounts = attrValues neomuttAccountsCfg;
accountCommandNeeded = lib.any (
a:
a.neomutt.enable
&& (
a.neomutt.mailboxType == "imap"
|| (lib.any (m: !isString m && m.type == "imap") a.neomutt.extraMailboxes)
)
) (attrValues config.accounts.email.accounts);
a.neomutt.mailboxType == "imap"
|| (lib.any (m: !isString m && m.type == "imap") a.neomutt.extraMailboxes)
) neomuttAccounts;
accountCommand =
let
imapAccounts = filter (
a: a.neomutt.enable && a.imap.host != null && a.userName != null && a.passwordCommand != null
) (attrValues config.accounts.email.accounts);
a: a.imap.host != null && a.userName != null && a.passwordCommand != null
) neomuttAccounts;
accountCase =
account:
let
@ -538,12 +537,17 @@ in
);
};
assertions = [
{
assertion = ((filter (b: (lib.length (lib.toList b.map)) == 0) (cfg.binds ++ cfg.macros)) == [ ]);
message = "The 'programs.neomutt.(binds|macros).map' list must contain at least one element.";
}
];
assertions =
[
{
assertion = ((filter (b: (lib.length (lib.toList b.map)) == 0) (cfg.binds ++ cfg.macros)) == [ ]);
message = "The 'programs.neomutt.(binds|macros).map' list must contain at least one element.";
}
]
++ lib.mapAttrsToList (n: a: {
assertion = a.neomutt.sendMailCommand != null || a.passwordCommand != null;
message = "'accounts.email.accounts.${n}' needs either 'neomutt.sendMailCommand' or 'passwordCommand' set.";
}) neomuttAccountsCfg;
warnings =
let