mirror of
https://github.com/nix-community/home-manager.git
synced 2026-01-12 01:59:37 +08: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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user