programs.neomutt: Fix eval error when primary account not enabled (#1873)

* neomutt: Fix eval error when primary account not enabled

If neomutt is enabled for an account, but not the primary account, the
configuration will fail with "list index 0 is out of bounds".

This adds the first neomutt-enabled account as a fallback.

* neomutt: add regression test/update tests
This commit is contained in:
Rodney Lorrimar 2021-03-29 14:44:47 +10:00 committed by GitHub
parent c1761366b5
commit cbf0667037
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 5 deletions

View file

@ -279,7 +279,11 @@ in {
in foldl' (a: b: a // b) { } (map rcFile neomuttAccounts);
xdg.configFile."neomutt/neomuttrc" = mkIf (neomuttAccounts != [ ]) {
text = let primary = filter (a: a.primary) neomuttAccounts;
text = let
# Find the primary account, if it has neomutt enabled;
# otherwise use the first neomutt account as primary.
primary =
head (filter (a: a.primary) neomuttAccounts ++ neomuttAccounts);
in ''
# Generated by Home Manager.
set header_cache = "${config.xdg.cacheHome}/neomutt/headers/"
@ -304,9 +308,13 @@ in {
${optionsStr cfg.settings}
${cfg.extraConfig}
'' + concatMapStringsSep "\n" registerAccount neomuttAccounts +
# source primary account
"source ${accountFilename (builtins.head primary)}";
# Register accounts
${concatMapStringsSep "\n" registerAccount neomuttAccounts}
# Source primary account
source ${accountFilename primary}
'';
};
};
}