diff --git a/modules/programs/neomutt-accounts.nix b/modules/programs/neomutt-accounts.nix index 94f97e91..27e3b122 100644 --- a/modules/programs/neomutt-accounts.nix +++ b/modules/programs/neomutt-accounts.nix @@ -21,6 +21,23 @@ let }; in { + options.notmuch.neomutt = { + enable = mkEnableOption "Notmuch support in NeoMutt" // { default = true; }; + + virtualMailboxes = mkOption { + type = types.listOf (types.submodule ./notmuch-virtual-mailbox.nix); + example = [{ + name = "My INBOX"; + query = "tag:inbox"; + }]; + default = [{ + name = "My INBOX"; + query = "tag:inbox"; + }]; + description = "List of virtual mailboxes using Notmuch queries"; + }; + }; + options.neomutt = { enable = mkEnableOption "NeoMutt"; diff --git a/modules/programs/neomutt.nix b/modules/programs/neomutt.nix index 75508303..65f3144f 100644 --- a/modules/programs/neomutt.nix +++ b/modules/programs/neomutt.nix @@ -3,7 +3,6 @@ with lib; let - cfg = config.programs.neomutt; neomuttAccounts = @@ -89,6 +88,14 @@ let }; }; + mkNotmuchVirtualboxes = virtualMailboxes: + "${concatStringsSep "\n" (map ({ name, query, limit, type }: + '' + virtual-mailboxes "${name}" "notmuch://?query=${lib.escapeURL query}${ + optionalString (limit != null) "&limit=${toString limit}" + }${optionalString (type != null) "&type=${type}"}"'') + virtualMailboxes)}"; + setOption = n: v: if v == null then "unset ${n}" else "set ${n}=${v}"; escape = replaceStrings [ "%" ] [ "%25" ]; @@ -188,10 +195,13 @@ let ''; notmuchSection = account: - with account; '' + let virtualMailboxes = account.notmuch.neomutt.virtualMailboxes; + in with account; '' # notmuch section set nm_default_uri = "notmuch://${config.accounts.email.maildirBasePath}" - virtual-mailboxes "My INBOX" "notmuch://?query=tag:inbox" + ${optionalString + (notmuch.neomutt.enable && builtins.length virtualMailboxes > 0) + (mkNotmuchVirtualboxes virtualMailboxes)} ''; accountStr = account: @@ -234,7 +244,9 @@ let ${account.neomutt.extraConfig} ${signature} - '' + optionalString account.notmuch.enable (notmuchSection account); + '' + + optionalString (account.notmuch.enable && account.notmuch.neomutt.enable) + (notmuchSection account); in { options = { diff --git a/modules/programs/notmuch-virtual-mailbox.nix b/modules/programs/notmuch-virtual-mailbox.nix new file mode 100644 index 00000000..72a78842 --- /dev/null +++ b/modules/programs/notmuch-virtual-mailbox.nix @@ -0,0 +1,33 @@ +{ config, lib, ... }: +with lib; { + options = { + name = mkOption { + type = types.str; + example = "My INBOX"; + default = "My INBOX"; + description = "Name to display"; + }; + + query = mkOption { + type = types.str; + example = "tag:inbox"; + default = "tag:inbox"; + description = "Notmuch query"; + }; + + limit = mkOption { + type = types.nullOr types.int; + example = 10; + default = null; + description = "Restricts number of messages/threads in the result."; + }; + + type = mkOption { + type = types.nullOr (types.enum ([ "threads" "messages" ])); + example = "threads"; + default = null; + description = + "Reads all matching messages or whole-threads. The default is 'messages' or nm_query_type."; + }; + }; +} diff --git a/tests/modules/programs/neomutt/hm-example.com-expected b/tests/modules/programs/neomutt/hm-example.com-expected index 78b75636..51fdcc6e 100644 --- a/tests/modules/programs/neomutt/hm-example.com-expected +++ b/tests/modules/programs/neomutt/hm-example.com-expected @@ -35,4 +35,4 @@ color status cyan default unset signature # notmuch section set nm_default_uri = "notmuch:///home/hm-user/Mail" -virtual-mailboxes "My INBOX" "notmuch://?query=tag:inbox" +virtual-mailboxes "My INBOX" "notmuch://?query=tag%3Ainbox" diff --git a/tests/modules/programs/neomutt/hm-example.com-signature-command-expected b/tests/modules/programs/neomutt/hm-example.com-signature-command-expected index dfc8bc39..c3b35067 100644 --- a/tests/modules/programs/neomutt/hm-example.com-signature-command-expected +++ b/tests/modules/programs/neomutt/hm-example.com-signature-command-expected @@ -35,4 +35,4 @@ 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" +virtual-mailboxes "My INBOX" "notmuch://?query=tag%3Ainbox" diff --git a/tests/modules/programs/neomutt/hm-example.com-signature-expected b/tests/modules/programs/neomutt/hm-example.com-signature-expected index 441374a9..66e941c1 100644 --- a/tests/modules/programs/neomutt/hm-example.com-signature-expected +++ b/tests/modules/programs/neomutt/hm-example.com-signature-expected @@ -35,4 +35,4 @@ 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" +virtual-mailboxes "My INBOX" "notmuch://?query=tag%3Ainbox"