feat(accounts): add emails workflow settings

This commit is contained in:
Yorick Barbanneau 2025-08-04 02:04:30 +02:00
parent 0cd88af42b
commit c31fdd0739
7 changed files with 279 additions and 184 deletions

View file

@ -1,7 +1,8 @@
{ lib, config, pkgs, ... }:
{ lib, config, pkgs, inputs, ... }:
with lib;
let
cfg = config.modules.email;
secretsDirectory = "${(builtins.toString inputs.nix-private)}/secrets";
in
{
options.modules.email = {
@ -21,6 +22,15 @@ in
};
config = mkIf cfg.enable {
sops = let
secretList = lib.mapAttrs' ( name: value:
nameValuePair ( value.secret.key ) ({
sopsFile = "${secretsDirectory}/${value.secret.file}";
})
) cfg.accountConfigs;
in {
secrets = secretList;
};
accounts.email = let
defaultSetting = {
mbsync = {
@ -28,20 +38,16 @@ in
create = "maildir";
expunge = "both";
};
aerc = {
msmtp = {
enable = true;
extraAccounts ={
source = "notmuch://~/mail";
maildir-store = "~/mail";
default = "Inbox";
postpone = "Drafts";
copy-to = "Sent";
use-envelope-from = true;
};
};
notmuch = {
enable = true;
};
neomutt = {
enable = true;
showDefaultMailbox = false;
};
};
accountsList = lib.mapAttrs ( name: value: lib.recursiveUpdate defaultSetting value.config ) cfg.accountConfigs;
in {
@ -49,16 +55,15 @@ in
accounts = lib.recursiveUpdate accountsList { "${cfg.primary}".primary = true; };
};
# programs.notmuch = {
# enable = true;
# new.tags = [ "new" ];
# hooks.postNew = ''
# ${pkgs.afew}/bin/afew -t -n
# ${pkgs.afew}/bin/afew -w -n
# '';
# };
programs.afew = {
programs.afew = let
mailMoverRules = lib.mergeAttrsList (
lib.attrsets.mapAttrsToList (
n: v:
if lib.hasAttrByPath ["afew" "mailMover"] v then
v.afew.mailMover
else {}
) cfg.accountConfigs);
in {
enable = true;
extraConfig = ''
[FolderNameFilter]
@ -66,6 +71,9 @@ in
folder_transforms = archives:archive
maildir_separator = /
[MailMover]
folders = ${lib.concatStringsSep " " (lib.unique (lib.mapAttrsToList (n: v: "${n}") mailMoverRules))}
rename = True
${lib.concatStringsSep "\n" (lib.mapAttrsToList (n: v: "${n} = ${toString v}") mailMoverRules)}
[SpamFilter]
[KillThreadsFilter]
[ArchiveSentMailsFilter]
@ -73,73 +81,124 @@ in
[InboxFilter]
'';
};
programs.aerc = {
programs.neomutt = let
accountMacros = lib.imap1 (
i:
elem: elem // {
map = ["index" "pager"];
key = "<F${(toString (i + 1))}>";
}) (
lib.attrsets.mapAttrsToList (
n: _:
{ "action" = "<sync-mailbox><refresh><enter-command>source ~/.config/neomutt/${n}<enter><change-folder>=Inbox<enter><change-vfolder>Unread<enter>";}
) inputs.nix-private.mail);
in {
enable = true;
extraConfig = {
general = {
unsafe-accounts-conf = true;
};
ui = {
column-subject = ''
{{if .ThreadPrefix}}{{.Style (printf "%s " .ThreadPrefix) "thread"}}{{- end }}{{.Subject}}
'';
column-flags = ''
{{.Flags | join " "}}
'';
index-columns = ''
flags:5,name<20%,subject,date>=
'';
thread-prefix-tip = " ";
thread-prefix-indent = "";
thread-prefix-stem = "";
thread-prefix-limb = "";
thread-prefix-folded = "+";
thread-prefix-unfolded = "";
thread-prefix-first-child = "";
thread-prefix-has-siblings = "";
thread-prefix-orphan = " ";
thread-prefix-dummy = "";
thread-prefix-lone = " ";
thread-prefix-last-sibling = "";
completion-popovers = true;
icon-attachment = "󰁦";
icon-replied = "";
icon-forwarded = "";
icon-new = "";
icon-old = "";
icon-unencrypted = "";
icon-encrypted = "";
icon-signed = "󰏫";
icon-signed-encrypted = "";
icon-invalid = "󰏯";
icon-unknown = "󰷭";
threading-enabled = true;
};
statusline = {
status-columns=''
left<*,right>*
'';
column-left = ''
{{.Style (printf " %s " (toUpper .Account)) "statusline_account" }}\
{{.Style (printf " %s | 󰉉 %s " .Folder (humanReadable .Size)) "statusline_folder"}}\
{{ if .ContentInfo }}{{.Style (printf " %s " .ContentInfo) "statusline_contentinfo"}}{{- end }}
'';
column-center = ''
{{.Style .PendingKeys "statusline_center"}}
'';
};
filters = {
"text/plain" = " wrap -w 100 | colorize";
"text/html" = "! html";
"text/calendar" = "calendar";
"message/delivery-status" = "colorize";
"message/rfc822" = "colorize";
".headers" = "colorize";
};
};
stylesets = {
default = (builtins.readFile ./files/default.theme);
unmailboxes = true;
editor = "nvim +/^$/ +':nohl'";
settings = {
sleep_time = "1";
mbox_type = "Maildir";
header_color_partial = "yes";
duplicate_threads = "yes";
index_format = "'%4C| %24.24?GS?%F %GS &%F? %?GR?%GR &%?GU?%GU & ??%?GA?%GA & ?%?GE?%GE & ?%?M?󰘕 %s&%s? %* %?g? %g? %<[y?%<[m?%<[d?%9[%H:%M ]&%9[%a %d ]>&%9[%b %d ]>&%9[%m/%y ]>'";
sort_aux = "last-date-sent";
mail_check = "120";
hidden_tags = "inbox,unread,draft,flagged,passed,replied,signed,encrypted,attachment,sent";
markers = "no";
wrap = "90";
smart_wrap = "yes";
reflow_text = "yes";
reflow_wrap = "90";
text_flowed = "yes";
search_context = "3";
pager_context = "5";
pager_index_lines = "10";
rfc2047_parameters = "yes";
edit_headers = "yes";
send_charset = "utf-8";
envelope_from = "yes";
my_status = "' %o/%m | %l 󰉉 | %f %* Sort: %s-%S Pos: %P '";
my_pager = "' %F | %s %* Pos: %P '";
compose_format = "' COMPOSE %a | 󰉉 %l'";
query_command = "'${pkgs.khard}/bin/khard email --parsable --search-in-source-files %s'";
};
extraConfig = ''
${(builtins.readFile ./files/theme.muttrc)}
charset-hook ^iso-8859-1$ cp1252
ignore *
unignore from date subject to cc bcc tags user-agent x-mailer
auto_view text/x-vcard text/html text/enriched text/calendar
alternative_order text/html text/enriched text/plain text/*
tag-transforms "attachment" "󰁦" \
"encrypted" "󱧈" \
"signed" "󱅞" \
"unread" "" \
"replied" ""
tag-formats "attachment" "GA" \
"encrypted" "GE" \
"signed" "GS" \
"unread" "GU" \
"replied" "GR"
'';
binds = [
{ map = [ "attach" "browser" "index" "pager" ]; key = "g"; action = "noop"; }
{ map = [ "attach" "browser" "index" "pager" ]; key = "G"; action = "noop"; }
{ map = [ "index" ]; key = "q"; action = "noop";}
{ map = [ "pager" ]; key = "Q"; action = "noop";}
{ map = [ "attach" "browser" "index" ]; key = "gg"; action = "first-entry";}
{ map = [ "attach" "browser" "index" ]; key = "G"; action = "last-entry";}
{ map = [ "pager" ]; key = "gg"; action = "top"; }
{ map = [ "pager" ]; key = "G"; action = "bottom"; }
{ map = [ "pager" ]; key = "k"; action = "previous-line"; }
{ map = [ "pager" ]; key = "j"; action = "next-line"; }
# Scrolling
{ map = [ "attach" "browser" "pager" "index" ]; key = "\\CF"; action = "next-page";}
{ map = [ "attach" "browser" "pager" "index" ]; key = "\\CB"; action = "previous-page";}
{ map = [ "attach" "browser" "pager" "index" ]; key = "\\Cu"; action = "half-up";}
{ map = [ "attach" "browser" "pager" "index" ]; key = "\\Cd"; action = "half-down";}
{ map = [ "browser" "pager" ]; key = "\\Ce"; action = "next-line";}
{ map = [ "browser" "pager" ]; key = "\\Cy"; action = "previous-line";}
{ map = [ "index" ]; key = "\\Ce"; action = "next-line";}
{ map = [ "index" ]; key = "\\Cy"; action = "previous-line";}
# Delete
{ map = [ "pager" "index" ]; key = "d "; action = "noop";}
{ map = [ "pager" "index" ]; key = "dd "; action = "delete-message";}
# Reply
{ map =[ "pager" "index" ]; key = "R "; action = "group-reply";}
# sidebar
{ map = [ "index" "pager" ]; key = "<f12>"; action = "sidebar-toggle-visible";}
{ map = [ "index" "pager" ]; key = "{"; action = "sidebar-prev";}
{ map = [ "index" "pager" ]; key = "}"; action = "sidebar-next";}
{ map = [ "index" "pager" ]; key = "|"; action = "sidebar-open";}
# open virtual folder
{ map = [ "index" "pager" ]; key = "X"; action = "noop";}
{ map = [ "index" "pager" ]; key = "X"; action = "change-vfolder";}
# read entire thread of the current message
{ map = [ "index" "pager" ]; key = "+"; action = "entire-thread";}
# generate virtual folder from query
{ map = [ "index" "pager" ]; key = "\\eX"; action = "vfolder-from-query";}
# generate virtual folder from query with time window
{ map = [ "index" ]; key = "<"; action = "vfolder-window-backward";}
{ map = [ "index" ]; key = ">"; action = "vfolder-window-forward";}
{ map = [ "index" "pager" ]; key = "\\CD"; action = "modify-tags";}
# Editor
{ map = [ "editor" ]; key = "<Tab>"; action = "complete-query";}
{ map = [ "editor" ]; key = "^T "; action = "complete";}
];
macros = [
#Define some macros here
] ++ accountMacros;
};
programs.mbsync = {
enable = true;
@ -147,7 +206,17 @@ in
services.mbsync = {
enable = true;
postExec = "${pkgs.notmuch}/bin/notmuch new";
package = config.programs.mbsync.package;
};
programs.notmuch = {
enable = true;
new.tags = [ "new" ];
hooks.postNew = ''
${pkgs.afew}/bin/afew --tag --new
${pkgs.afew}/bin/afew --move --all
'';
};
programs.msmtp = {
enable = true;
};
};
}