From 225bf275ba8ea3f23728685c12b902dedcd3a666 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Mon, 12 Apr 2021 11:25:02 -0600 Subject: [PATCH] neomutt: make folder change when sourcing account optional This adds an option for disabling setting the folder when sourcing accounts in neomutt. --- modules/programs/neomutt.nix | 12 ++++++-- tests/modules/programs/neomutt/default.nix | 1 + ...example.com-no-folder-change-expected.conf | 30 +++++++++++++++++++ .../neomutt/neomutt-no-folder-change.nix | 30 +++++++++++++++++++ 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 tests/modules/programs/neomutt/hm-example.com-no-folder-change-expected.conf create mode 100644 tests/modules/programs/neomutt/neomutt-no-folder-change.nix diff --git a/modules/programs/neomutt.nix b/modules/programs/neomutt.nix index 14e763cc0..dbfe88990 100644 --- a/modules/programs/neomutt.nix +++ b/modules/programs/neomutt.nix @@ -124,9 +124,10 @@ let genMaildirAccountConfig = account: with account; let - folderHook = mapAttrsToList setOption (genCommonFolderHooks account // { - folder = "'${account.maildir.absPath}'"; - }); + folderHook = mapAttrsToList setOption (genCommonFolderHooks account + // optionalAttrs cfg.changeFolderWhenSourcingAccount { + folder = "'${account.maildir.absPath}'"; + }); in '' ${concatStringsSep "\n" folderHook} ''; @@ -266,6 +267,11 @@ in { description = "Extra configuration appended to the end."; }; + changeFolderWhenSourcingAccount = + mkEnableOption "changing the folder when sourcing an account" // { + default = true; + }; + extraConfig = mkOption { type = types.lines; default = ""; diff --git a/tests/modules/programs/neomutt/default.nix b/tests/modules/programs/neomutt/default.nix index b26923f79..d24813545 100644 --- a/tests/modules/programs/neomutt/default.nix +++ b/tests/modules/programs/neomutt/default.nix @@ -7,4 +7,5 @@ neomutt-with-binds-invalid-settings = ./neomutt-with-binds-invalid-settings.nix; neomutt-with-gpg = ./neomutt-with-gpg.nix; + neomutt-no-folder-change = ./neomutt-no-folder-change.nix; } diff --git a/tests/modules/programs/neomutt/hm-example.com-no-folder-change-expected.conf b/tests/modules/programs/neomutt/hm-example.com-no-folder-change-expected.conf new file mode 100644 index 000000000..03ea3b31a --- /dev/null +++ b/tests/modules/programs/neomutt/hm-example.com-no-folder-change-expected.conf @@ -0,0 +1,30 @@ +# Generated by Home Manager. +set ssl_force_tls = yes +set certificate_file=/etc/ssl/certs/ca-certificates.crt + +# GPG section +set crypt_use_gpgme = yes +set crypt_autosign = no +set crypt_opportunistic_encrypt = no +set pgp_use_gpg_agent = yes +set mbox_type = Maildir +set sort = "threads" + +# MTA section +set sendmail='msmtpq --read-envelope-from --read-recipients' + + + + + +# MRA section +set from='hm@example.com' +set postponed='+Drafts' +set realname='H. M. Test' +set record='+Sent' +set spoolfile='+Inbox' +set trash='+Trash' + + +# Extra configuration + diff --git a/tests/modules/programs/neomutt/neomutt-no-folder-change.nix b/tests/modules/programs/neomutt/neomutt-no-folder-change.nix new file mode 100644 index 000000000..db7246604 --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-no-folder-change.nix @@ -0,0 +1,30 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + config = { + accounts.email.accounts = { + "hm@example.com" = { + msmtp.enable = true; + neomutt.enable = true; + imap.port = 993; + }; + }; + + programs.neomutt.enable = true; + programs.neomutt.changeFolderWhenSourcingAccount = false; + + nixpkgs.overlays = + [ (self: super: { neomutt = pkgs.writeScriptBin "dummy-neomutt" ""; }) ]; + + nmt.script = '' + assertFileExists home-files/.config/neomutt/hm@example.com + assertFileContent home-files/.config/neomutt/hm@example.com ${ + ./hm-example.com-no-folder-change-expected.conf + } + ''; + }; +}