diff --git a/modules/accounts/email.nix b/modules/accounts/email.nix index e48024e02..72eb538b2 100644 --- a/modules/accounts/email.nix +++ b/modules/accounts/email.nix @@ -44,6 +44,15 @@ let ''; }; + command = mkOption { + type = with types; nullOr path; + default = null; + example = literalExpression '' + pkgs.writeScript "signature" "echo This is my signature" + ''; + description = "A command that generates a signature."; + }; + showSignature = mkOption { type = types.enum [ "append" "attach" "none" ]; default = "none"; diff --git a/modules/programs/neomutt.nix b/modules/programs/neomutt.nix index b3e928183..75508303e 100644 --- a/modules/programs/neomutt.nix +++ b/modules/programs/neomutt.nix @@ -196,7 +196,16 @@ let accountStr = account: with account; - '' + let + signature = if account.signature.showSignature == "none" then + "unset signature" + else if account.signature.command != null then + ''set signature = "${account.signature.command}|"'' + else + "set signature = ${ + pkgs.writeText "signature.txt" account.signature.text + }"; + in '' # Generated by Home Manager. set ssl_force_tls = yes set certificate_file=${toString config.accounts.email.certificatesFile} @@ -223,11 +232,9 @@ let # Extra configuration ${account.neomutt.extraConfig} - '' + (if (account.signature.showSignature == "none") then '' - unset signature - '' else '' - set signature = ${pkgs.writeText "signature.txt" account.signature.text} - '') + optionalString account.notmuch.enable (notmuchSection account); + + ${signature} + '' + optionalString account.notmuch.enable (notmuchSection account); in { options = { diff --git a/tests/modules/programs/neomutt/default.nix b/tests/modules/programs/neomutt/default.nix index 62319dd36..8216017c1 100644 --- a/tests/modules/programs/neomutt/default.nix +++ b/tests/modules/programs/neomutt/default.nix @@ -9,4 +9,6 @@ neomutt-with-gpg = ./neomutt-with-gpg.nix; neomutt-no-folder-change = ./neomutt-no-folder-change.nix; neomutt-with-named-mailboxes = ./neomutt-with-named-mailboxes.nix; + neomutt-with-signature = ./neomutt-with-signature.nix; + neomutt-with-signature-command = ./neomutt-with-signature-command.nix; } diff --git a/tests/modules/programs/neomutt/hm-example.com-expected b/tests/modules/programs/neomutt/hm-example.com-expected index 74fbf6b1a..78b756364 100644 --- a/tests/modules/programs/neomutt/hm-example.com-expected +++ b/tests/modules/programs/neomutt/hm-example.com-expected @@ -31,6 +31,7 @@ set trash='+Trash' # Extra configuration color status cyan default + unset signature # notmuch section set nm_default_uri = "notmuch:///home/hm-user/Mail" diff --git a/tests/modules/programs/neomutt/hm-example.com-gpg-expected.conf b/tests/modules/programs/neomutt/hm-example.com-gpg-expected.conf index 8c5c10439..576064243 100644 --- a/tests/modules/programs/neomutt/hm-example.com-gpg-expected.conf +++ b/tests/modules/programs/neomutt/hm-example.com-gpg-expected.conf @@ -30,4 +30,5 @@ set trash='+Trash' # Extra configuration + unset signature diff --git a/tests/modules/programs/neomutt/hm-example.com-msmtp-expected.conf b/tests/modules/programs/neomutt/hm-example.com-msmtp-expected.conf index 8ccd3629a..354cc43ee 100644 --- a/tests/modules/programs/neomutt/hm-example.com-msmtp-expected.conf +++ b/tests/modules/programs/neomutt/hm-example.com-msmtp-expected.conf @@ -30,4 +30,5 @@ set trash='+Trash' # Extra configuration color status cyan default + unset signature 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 index 22fcf7884..e5dee0616 100644 --- 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 @@ -28,4 +28,5 @@ set trash='+Trash' # Extra configuration + unset signature diff --git a/tests/modules/programs/neomutt/hm-example.com-signature-command-expected b/tests/modules/programs/neomutt/hm-example.com-signature-command-expected new file mode 100644 index 000000000..dfc8bc39a --- /dev/null +++ b/tests/modules/programs/neomutt/hm-example.com-signature-command-expected @@ -0,0 +1,38 @@ +# 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 smtp_pass="`password-command`" +set smtp_url='smtps://home.manager@smtp.example.com' + + + + + +# MRA section +set folder='/home/hm-user/Mail/hm@example.com' +set from='hm@example.com' +set postponed='+Drafts' +set realname='H. M. Test' +set record='+Sent' +set spoolfile='+Inbox' +set trash='+Trash' + + +# Extra configuration +color status cyan default + + +set signature = "/nix/store/00000000000000000000000000000000-signature|" +# notmuch section +set nm_default_uri = "notmuch:///home/hm-user/Mail" +virtual-mailboxes "My INBOX" "notmuch://?query=tag:inbox" diff --git a/tests/modules/programs/neomutt/hm-example.com-signature-expected b/tests/modules/programs/neomutt/hm-example.com-signature-expected new file mode 100644 index 000000000..441374a9b --- /dev/null +++ b/tests/modules/programs/neomutt/hm-example.com-signature-expected @@ -0,0 +1,38 @@ +# 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 smtp_pass="`password-command`" +set smtp_url='smtps://home.manager@smtp.example.com' + + + + + +# MRA section +set folder='/home/hm-user/Mail/hm@example.com' +set from='hm@example.com' +set postponed='+Drafts' +set realname='H. M. Test' +set record='+Sent' +set spoolfile='+Inbox' +set trash='+Trash' + + +# Extra configuration +color status cyan default + + +set signature = /nix/store/00000000000000000000000000000000-signature.txt +# notmuch section +set nm_default_uri = "notmuch:///home/hm-user/Mail" +virtual-mailboxes "My INBOX" "notmuch://?query=tag:inbox" diff --git a/tests/modules/programs/neomutt/neomutt-with-signature-command.nix b/tests/modules/programs/neomutt/neomutt-with-signature-command.nix new file mode 100644 index 000000000..97c2001f9 --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-with-signature-command.nix @@ -0,0 +1,45 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + config = { + accounts.email.accounts = { + "hm@example.com" = { + notmuch.enable = true; + neomutt = { + enable = true; + extraConfig = '' + color status cyan default + ''; + }; + imap.port = 993; + signature = { + showSignature = "append"; + command = pkgs.writeScript "signature" "echo This is my signature"; + }; + }; + }; + + programs.neomutt = { + enable = true; + vimKeys = false; + }; + + test.stubs.neomutt = { }; + + nmt.script = '' + assertFileExists home-files/.config/neomutt/neomuttrc + assertFileExists home-files/.config/neomutt/hm@example.com + assertFileContent home-files/.config/neomutt/neomuttrc ${ + ./neomutt-expected.conf + } + expectedSignature=$(normalizeStorePaths "home-files/.config/neomutt/hm@example.com") + assertFileContent "$expectedSignature" ${ + ./hm-example.com-signature-command-expected + } + ''; + }; +} diff --git a/tests/modules/programs/neomutt/neomutt-with-signature.nix b/tests/modules/programs/neomutt/neomutt-with-signature.nix new file mode 100644 index 000000000..9461976d3 --- /dev/null +++ b/tests/modules/programs/neomutt/neomutt-with-signature.nix @@ -0,0 +1,48 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + imports = [ ../../accounts/email-test-accounts.nix ]; + + config = { + accounts.email.accounts = { + "hm@example.com" = { + notmuch.enable = true; + neomutt = { + enable = true; + extraConfig = '' + color status cyan default + ''; + }; + imap.port = 993; + signature = { + showSignature = "append"; + text = '' + -- + Test Signature + ''; + }; + }; + }; + + programs.neomutt = { + enable = true; + vimKeys = false; + }; + + test.stubs.neomutt = { }; + + nmt.script = '' + assertFileExists home-files/.config/neomutt/neomuttrc + assertFileExists home-files/.config/neomutt/hm@example.com + assertFileContent home-files/.config/neomutt/neomuttrc ${ + ./neomutt-expected.conf + } + expectedSignature=$(normalizeStorePaths "home-files/.config/neomutt/hm@example.com") + assertFileContent "$expectedSignature" ${ + ./hm-example.com-signature-expected + } + ''; + }; +}