1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
Files
niveum/configs/mail.nix

234 lines
6.4 KiB
Nix
Raw Normal View History

{ config, pkgs, lib, ... }:
2020-04-18 08:46:42 +02:00
let
tagRules = [
{
query = "to:miaengiadina-pwa@noreply.github.com AND subject:\"PR run failed\"";
tags = [ "-new" "+deleted" ];
}
{
query = lib.concatStringsSep " OR " [
"from:noreply-local-guides@google.com"
"from:google-maps-noreply@google.com"
"subject:fd-noti"
"from:nebenan.de"
"to:miaengiadina-pwa@noreply.github.com"
];
tags = [ "-new" ];
}
{
query = "tag:new";
tags = [ "-new" "+inbox" ];
}
];
2020-10-19 18:57:07 +02:00
# turns out we have to escape $ because, if the password contains a $, it will get interpolated as a variable by the msmtp `passwordeval` which does: `bash -c "COMMAND; echo"`
pass_ = file: "echo ${lib.escape ["$"] (lib.escapeShellArg (lib.strings.fileContents file))}";
2020-09-24 19:16:36 +02:00
2020-09-24 10:35:53 +02:00
generateTaggingScript = filters:
2020-09-24 11:12:52 +02:00
let
template = { tags, query, message ? "tagging ${query} -> ${lib.concatStringsSep " " tags}", ... }: ''
2020-09-24 10:35:53 +02:00
echo '${message}'
2020-09-24 11:12:52 +02:00
${pkgs.notmuch}/bin/notmuch tag ${lib.concatStringsSep " " tags} -- "${query}"
'';
in lib.concatStringsSep "\n" (map template filters);
2020-09-24 10:35:53 +02:00
2020-04-25 21:34:26 +02:00
enableDefaults = lib.recursiveUpdate {
mbsync = {
enable = true;
create = "both";
expunge = "both";
};
msmtp.enable = true;
2020-09-23 00:33:30 +02:00
notmuch.enable = true;
2020-04-25 21:34:26 +02:00
};
2020-09-24 11:12:52 +02:00
much-pkg = pkgs.haskellPackages.callCabal2nix "much" <niveum/submodules/much> {};
much = pkgs.haskell.lib.dontHaddock much-pkg;
2020-09-24 19:16:36 +02:00
mail-sync = pkgs.writers.writeDashBin "mail-sync" ''
${pkgs.isync}/bin/mbsync --all
${pkgs.notmuch}/bin/notmuch new
'';
2020-06-10 17:37:25 +02:00
in {
2020-09-24 19:16:36 +02:00
environment.variables.NOTMUCH_CONFIG = config.home-manager.users.me.home.sessionVariables.NOTMUCH_CONFIG;
systemd.services.mail-sync = {
enable = true;
wants = [ "network-online.target" ];
startAt = "*:0/15";
serviceConfig.User = "kfm";
2020-10-17 22:27:22 +02:00
serviceConfig.Type = "oneshot";
2020-09-24 19:16:36 +02:00
environment.NOTMUCH_CONFIG = config.home-manager.users.me.home.sessionVariables.NOTMUCH_CONFIG;
2020-10-17 22:27:22 +02:00
script = ''
export PATH=${lib.makeBinPath [ pkgs.muchsync pkgs.notmuch mail-sync ]}
mail-sync
muchsync
'';
2020-09-24 19:16:36 +02:00
};
2020-09-24 10:35:53 +02:00
environment.systemPackages = [
pkgs.neomutt
2020-09-24 11:12:52 +02:00
2020-09-26 21:08:05 +02:00
pkgs.notmuch-addrlookup
2020-09-24 19:16:36 +02:00
mail-sync
2020-10-17 22:27:22 +02:00
pkgs.muchsync
2020-09-24 11:12:52 +02:00
(pkgs.writers.writeDashBin "mua" ''
if [ $# -eq 0 ]; then
${much}/bin/much-kmein
else
${much}/bin/much-kmein -q "$*"
2020-09-24 11:12:52 +02:00
fi
'')
2020-09-24 19:16:36 +02:00
(pkgs.writers.writeDashBin "mail-clean" ''
2020-09-24 10:35:53 +02:00
${pkgs.notmuch}/bin/notmuch search --output files --format=text0 tag:deleted | ${pkgs.findutils}/bin/xargs -r0 rm
${pkgs.notmuch}/bin/notmuch new
'')
];
2019-04-20 09:08:39 +02:00
2020-09-24 19:16:36 +02:00
2020-09-24 11:12:52 +02:00
home-manager.users.me = {
2020-10-17 22:27:22 +02:00
services.muchsync.remotes =
let
muchsyncConfig = host: {
name = host;
value = {
frequency = "*:0/10";
remote.host = host;
remote.checkForModifiedFiles = false;
local.checkForModifiedFiles = false;
# don't run `notmuch new` locally nor remotely because muchsync is only regularly run after `mail-sync`
remote.importNew = false;
local.importNew = false;
};
};
in lib.listToAttrs (map muchsyncConfig [
"wilde"
"homeros"
]);
2020-09-24 11:12:52 +02:00
programs.msmtp.enable = true;
programs.mbsync.enable = true;
programs.notmuch = {
enable = true;
new.tags = [ "new" ];
2020-09-24 11:12:52 +02:00
search.excludeTags = [ "deleted" "spam" ];
2020-10-17 22:27:42 +02:00
hooks.postNew = generateTaggingScript tagRules;
2020-10-21 00:35:13 +02:00
extraConfig.muchsync.and_tags = "inbox;unread";
2020-09-24 11:12:52 +02:00
};
accounts.email.maildirBasePath = "${config.users.users.me.home}/mail";
accounts.email.accounts = {
2020-09-24 11:12:52 +02:00
fysi = enableDefaults {
2020-07-25 09:04:12 +02:00
primary = false;
smtp = {
host = "smtp.fastmail.com";
port = 465;
tls.enable = true;
};
imap = {
host = "imap.fastmail.com";
port = 993;
tls.enable = true;
};
userName = "kieran@fysi.tech";
address = "kieran@fysi.tech";
realName = config.niveum.user.name;
2020-09-24 19:25:47 +02:00
passwordCommand = pass_ <secrets/mail/fastmail>;
2020-09-24 11:12:52 +02:00
};
cock = enableDefaults {
2020-04-25 21:34:26 +02:00
primary = false;
smtp = {
host = "mail.cock.li";
port = 587;
tls = {
enable = true;
useStartTls = true;
};
2020-04-25 21:34:26 +02:00
};
imap = {
host = "mail.cock.li";
port = 993;
tls.enable = true;
};
userName = "2210@cock.li";
address = "2210@cock.li";
realName = "2210";
2020-09-24 19:25:47 +02:00
passwordCommand = pass_ <secrets/mail/cock>;
2020-09-24 11:12:52 +02:00
};
kieran-gmail = enableDefaults {
primary = false;
flavor = "gmail.com";
address = "kieran.meinhardt@gmail.com";
realName = config.niveum.user.name;
userName = "kieran.meinhardt";
2020-09-24 19:25:47 +02:00
passwordCommand = pass_ <secrets/mail/gmail/kieran.meinhardt>;
2020-09-24 11:12:52 +02:00
folders = {
drafts = "[Gmail]/Entw&APw-rfe";
sent = "[Gmail]/Gesendet";
trash = "[Gmail]/Papierkorb";
};
};
amroplay = enableDefaults {
primary = false;
flavor = "gmail.com";
address = "amroplay@gmail.com";
realName = config.niveum.user.name;
userName = "amroplay";
2020-09-24 19:25:47 +02:00
passwordCommand = pass_ <secrets/mail/gmail/amroplay>;
2020-09-24 11:12:52 +02:00
folders = {
drafts = "[Gmail]/Drafts";
sent = "[Gmail]/Sent Mail";
trash = "[Gmail]/Bin";
};
};
posteo = enableDefaults {
primary = true;
smtp = {
host = "posteo.de";
port = 587;
tls = {
enable = true;
useStartTls = true;
2020-09-21 14:48:21 +02:00
};
2020-09-24 11:12:52 +02:00
};
imap = {
host = "posteo.de";
port = 993;
tls.enable = true;
};
address = "kieran.meinhardt@posteo.net";
realName = config.niveum.user.name;
userName = "kieran.meinhardt@posteo.net";
2020-09-24 19:25:47 +02:00
passwordCommand = pass_ <secrets/mail/posteo>;
2020-09-24 11:12:52 +02:00
};
hu-berlin = enableDefaults {
primary = false;
address = "meinhark@hu-berlin.de";
realName = config.niveum.user.name;
userName = "meinhark";
2020-09-24 19:25:47 +02:00
passwordCommand = pass_ <secrets/eduroam/password>;
smtp = {
host = "mailhost.cms.hu-berlin.de";
port = 25;
tls = {
enable = true;
useStartTls = true;
};
};
imap = {
host = "mailbox.cms.hu-berlin.de";
port = 993;
tls.enable = true;
};
};
2020-09-24 10:35:53 +02:00
};
2019-04-20 09:08:39 +02:00
};
}