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

notmuch & neomutt: Control virtualboxes being set in NeoMutt for Notmuch integration (#3143)

Virtual mailboxes (described by Notmuch queries) can now configured for each account in NeoMutt.
Plus, it is possible to disable Notmuch section for a specific account.
This commit is contained in:
Ryan Lahfa 2023-04-24 16:41:29 +02:00 committed by GitHub
parent 6f9781b1b0
commit 0263da497e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 7 deletions

View file

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

View file

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

View file

@ -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.";
};
};
}

View file

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

View file

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

View file

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