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:
parent
c1761366b5
commit
cbf0667037
|
@ -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}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
neomutt-simple = ./neomutt.nix;
|
||||
neomutt-with-msmtp = ./neomutt-with-msmtp.nix;
|
||||
neomutt-not-primary = ./neomutt-not-primary.nix;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,13 @@ set delete = yes
|
|||
|
||||
|
||||
|
||||
|
||||
# Register accounts
|
||||
# register account hm@example.com
|
||||
mailboxes "/home/hm-user/Mail/hm@example.com/Inbox"
|
||||
folder-hook /home/hm-user/Mail/hm@example.com/ " \
|
||||
source /home/hm-user/.config/neomutt/hm@example.com "
|
||||
source /home/hm-user/.config/neomutt/hm@example.com
|
||||
|
||||
|
||||
# Source primary account
|
||||
source /home/hm-user/.config/neomutt/hm@example.com
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
# Generated by Home Manager.
|
||||
set header_cache = "/home/hm-user/.cache/neomutt/headers/"
|
||||
set message_cachedir = "/home/hm-user/.cache/neomutt/messages/"
|
||||
set editor = "$EDITOR"
|
||||
set implicit_autoview = yes
|
||||
|
||||
alternative_order text/enriched text/plain text
|
||||
|
||||
set delete = yes
|
||||
|
||||
# Binds
|
||||
|
||||
|
||||
# Macros
|
||||
|
||||
|
||||
|
||||
|
||||
# Extra configuration
|
||||
|
||||
|
||||
|
||||
|
||||
# Register accounts
|
||||
# register account hm-account
|
||||
mailboxes "/home/hm-user/Mail/hm-account/Inbox"
|
||||
folder-hook /home/hm-user/Mail/hm-account/ " \
|
||||
source /home/hm-user/.config/neomutt/hm-account "
|
||||
|
||||
|
||||
# Source primary account
|
||||
source /home/hm-user/.config/neomutt/hm-account
|
26
tests/modules/programs/neomutt/neomutt-not-primary.nix
Normal file
26
tests/modules/programs/neomutt/neomutt-not-primary.nix
Normal file
|
@ -0,0 +1,26 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
imports = [ ../../accounts/email-test-accounts.nix ];
|
||||
|
||||
config = {
|
||||
accounts.email.accounts = {
|
||||
"hm@example.com".maildir = null;
|
||||
hm-account.neomutt.enable = true;
|
||||
};
|
||||
|
||||
programs.neomutt.enable = true;
|
||||
|
||||
nixpkgs.overlays =
|
||||
[ (self: super: { neomutt = pkgs.writeScriptBin "dummy-neomutt" ""; }) ];
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.config/neomutt/neomuttrc
|
||||
assertFileContent home-files/.config/neomutt/neomuttrc ${
|
||||
./neomutt-not-primary-expected.conf
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue