1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

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

View file

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

View file

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

View file

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

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