diff --git a/modules/programs/neomutt.nix b/modules/programs/neomutt.nix index f5e43698f..96360cb28 100644 --- a/modules/programs/neomutt.nix +++ b/modules/programs/neomutt.nix @@ -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} + ''; }; }; } diff --git a/tests/modules/programs/neomutt/default.nix b/tests/modules/programs/neomutt/default.nix index aef9f37e0..5a13c9168 100644 --- a/tests/modules/programs/neomutt/default.nix +++ b/tests/modules/programs/neomutt/default.nix @@ -1,4 +1,5 @@ { neomutt-simple = ./neomutt.nix; neomutt-with-msmtp = ./neomutt-with-msmtp.nix; + neomutt-not-primary = ./neomutt-not-primary.nix; } diff --git a/tests/modules/programs/neomutt/neomutt-expected.conf b/tests/modules/programs/neomutt/neomutt-expected.conf index 7711aa5a6..18cac44a9 100644 --- a/tests/modules/programs/neomutt/neomutt-expected.conf +++ b/tests/modules/programs/neomutt/neomutt-expected.conf @@ -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 \ No newline at end of file + + +# Source primary account +source /home/hm-user/.config/neomutt/hm@example.com diff --git a/tests/modules/programs/neomutt/neomutt-not-primary-expected.conf b/tests/modules/programs/neomutt/neomutt-not-primary-expected.conf new file mode 100644 index 000000000..ed1286c70 --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-not-primary-expected.conf @@ -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 diff --git a/tests/modules/programs/neomutt/neomutt-not-primary.nix b/tests/modules/programs/neomutt/neomutt-not-primary.nix new file mode 100644 index 000000000..10e9791de --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-not-primary.nix @@ -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 + } + ''; + }; +}