nixos-config/modules/workstation/home-manager/mail.nix

142 lines
4.1 KiB
Nix

# TODO: Clean this mess
{
lib,
config,
extraInfo,
...
}:
with lib;
let
mailAccountModule = types.submodule {
options = {
isPrimary = mkOption {
type = types.bool;
default = false;
};
mailAddress = mkOption { type = types.str; };
mailPasswdEval = mkOption { type = types.str; };
imapHost = mkOption { type = types.str; };
smtpHost = mkOption { type = types.str; };
};
};
defaultExtraMailboxes = [
"Archive"
"Junk"
"Drafts"
"Sent"
"Trash"
];
signature = {
text = ''
Victor Mignot
'';
showSignature = "append";
};
mailDefaults = {
"perso" = {
isPrimary = true;
mailAddress = extraInfo.mail.personal.address;
mailPasswdEval = mkDefault "";
imapHost = extraInfo.mail.personal.imapServer;
smtpHost = extraInfo.mail.personal.smtpServer;
};
"public" = {
mailAddress = extraInfo.mail.public.address;
mailPasswdEval = mkDefault "";
imapHost = extraInfo.mail.public.imapServer;
smtpHost = extraInfo.mail.public.smtpServer;
};
};
in
{
options.my.communications.mail = {
enable = mkOption {
type = types.bool;
default = true;
};
accounts = mkOption {
type = types.attrsOf mailAccountModule;
};
};
config = mkIf config.my.communications.mail.enable {
my.communications.mail.accounts = mailDefaults;
accounts.email.accounts = builtins.mapAttrs (name: value: {
primary = value.isPrimary;
address = value.mailAddress;
userName = value.mailAddress;
realName = "Victor Mignot";
imap.host = value.imapHost;
smtp.host = value.smtpHost;
passwordCommand = value.mailPasswdEval;
inherit signature;
mbsync = {
enable = true;
create = "both";
expunge = "both";
patterns = [ "*" ];
subFolders = "Verbatim";
};
msmtp.enable = true;
neomutt = {
enable = true;
mailboxName = "${name}/Inbox";
extraMailboxes = map (mb: {
mailbox = mb;
name = "${name}/${mb}";
}) defaultExtraMailboxes;
};
}) config.my.communications.mail.accounts;
services.mbsync.enable = true;
programs.mbsync.enable = true;
programs.msmtp.enable = true;
accounts.email.maildirBasePath = "Mail";
programs.neomutt = {
enable = true;
sidebar.enable = true;
checkStatsInterval = 30;
sort = "reverse-date";
extraConfig = ''
set edit_headers = yes
set use_from = yes
set send_charset = "utf-8"
color body brightwhite default ^[[:space:]].*
color body yellow default ^(diff).*
color body brightwhite default ^(\s).*
color body cyan default ^(Signed-off-by).*
color body cyan default ^(Docker-DCO-1.1-Signed-off-by).*
color body brightwhite default ^(Cc)
color body yellow default "^diff \-.*"
color body brightwhite default "^index [a-f0-9].*"
color body brightblue default "^---$"
color body white default "^\-\-\- .*"
color body white default "^[\+]{3} .*"
color body green default "^[\+][^\+]+.*"
color body red default "^\-[^\-]+.*"
color body brightblue default "^@@ .*"
color body green default "LGTM"
color body brightmagenta default "-- Commit Summary --"
color body brightmagenta default "-- File Changes --"
color body brightmagenta default "-- Patch Links --"
color body green default "^Merged #.*"
color body red default "^Closed #.*"
color body brightblue default "^Reply to this email.*"
'';
};
};
}