2019-08-27 17:24:33 +02:00
{ config , pkgs , lib , . . . }:
2020-04-18 08:46:42 +02:00
let
2020-10-30 11:05:26 +01:00
inherit ( import <niveum/lib> ) kieran ;
2020-10-27 21:27:12 +01:00
nixpkgs-much = import ( pkgs . fetchFromGitHub {
owner = " N i x O S " ;
repo = " n i x p k g s " ;
rev = " 7 c 2 a 3 6 2 b 5 8 a 1 c 2 b a 7 2 d 2 4 a a 3 8 6 9 d a 3 b 1 a 9 1 d 3 9 e 1 " ;
sha256 = " 0 g l 4 x n d y a h a s a 9 d v 5 m i 3 x 9 w 8 s 4 5 7 w l 2 x h 9 l c l d i z c n 1 i r j v k r z s 4 " ;
2020-11-05 21:28:23 +01:00
} ) {
overlays = [
( import <stockholm/krebs/5pkgs/haskell> )
] ;
} ;
2020-10-27 21:27:12 +01:00
much-pkg = nixpkgs-much . haskellPackages . callCabal2nix " m u c h " <niveum/submodules/much> { } ;
much = nixpkgs-much . haskell . lib . dontHaddock much-pkg ;
2020-09-27 19:28:11 +02:00
tagRules = [
{
query = " t o : m i a e n g i a d i n a - p w a @ n o r e p l y . g i t h u b . c o m A N D s u b j e c t : \" P R r u n f a i l e d \" " ;
tags = [ " - n e w " " + d e l e t e d " ] ;
}
{
query = lib . concatStringsSep " O R " [
" f r o m : n o r e p l y - l o c a l - g u i d e s @ g o o g l e . c o m "
" f r o m : g o o g l e - m a p s - n o r e p l y @ g o o g l e . c o m "
" s u b j e c t : f d - n o t i "
" f r o m : n e b e n a n . d e "
" t o : m i a e n g i a d i n a - p w a @ n o r e p l y . g i t h u b . c o m "
] ;
tags = [ " - n e w " ] ;
}
{
query = " t a g : n e w " ;
tags = [ " - n e w " " + i n b o x " ] ;
}
] ;
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 : " e c h o ${ 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 ? " t a g g i n g ${ 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 = " b o t h " ;
expunge = " b o t h " ;
} ;
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
2020-09-24 19:16:36 +02:00
mail-sync = pkgs . writers . writeDashBin " m a i l - s y n c " ''
$ { 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 = [ " n e t w o r k - o n l i n e . t a r g e t " ] ;
startAt = " * : 0 / 1 5 " ;
serviceConfig . User = " k f m " ;
2020-10-17 22:27:22 +02:00
serviceConfig . Type = " o n e s h o t " ;
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 " m u a " ''
if [ $ # -eq 0 ]; then
$ { much } /bin/much-kmein
else
2020-09-24 11:20:37 +02:00
$ { 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 " m a i l - c l e a n " ''
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 / 1 0 " ;
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 [
" w i l d e "
2020-11-05 21:28:23 +01:00
" m a n a k i s h "
2020-10-17 22:27:22 +02:00
] ) ;
2020-09-24 11:12:52 +02:00
programs . msmtp . enable = true ;
programs . mbsync . enable = true ;
programs . notmuch = {
enable = true ;
2020-09-27 19:28:11 +02:00
new . tags = [ " n e w " ] ;
2020-09-24 11:12:52 +02:00
search . excludeTags = [ " d e l e t e d " " s p a m " ] ;
2020-10-17 22:27:42 +02:00
hooks . postNew = generateTaggingScript tagRules ;
2020-10-21 00:35:13 +02:00
extraConfig . muchsync . and_tags = " i n b o x ; u n r e a d " ;
2020-09-24 11:12:52 +02:00
} ;
accounts . email . maildirBasePath = " ${ config . users . users . me . home } / m a i l " ;
2020-04-22 17:42:45 +02:00
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 = " s m t p . f a s t m a i l . c o m " ;
port = 465 ;
tls . enable = true ;
} ;
imap = {
host = " i m a p . f a s t m a i l . c o m " ;
port = 993 ;
tls . enable = true ;
} ;
userName = " k i e r a n @ f y s i . t e c h " ;
address = " k i e r a n @ f y s i . t e c h " ;
2020-10-30 11:05:26 +01:00
realName = kieran . 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 = " m a i l . c o c k . l i " ;
port = 587 ;
2020-07-14 23:51:07 +02:00
tls = {
enable = true ;
useStartTls = true ;
} ;
2020-04-25 21:34:26 +02:00
} ;
imap = {
host = " m a i l . c o c k . l i " ;
port = 993 ;
tls . enable = true ;
} ;
userName = " 2 2 1 0 @ c o c k . l i " ;
address = " 2 2 1 0 @ c o c k . l i " ;
realName = " 2 2 1 0 " ;
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 = " g m a i l . c o m " ;
address = " k i e r a n . m e i n h a r d t @ g m a i l . c o m " ;
2020-10-30 11:05:26 +01:00
realName = kieran . name ;
2020-09-24 11:12:52 +02:00
userName = " k i e r a n . m e i n h a r d t " ;
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 = " [ G m a i l ] / E n t w & A P w - r f e " ;
sent = " [ G m a i l ] / G e s e n d e t " ;
trash = " [ G m a i l ] / P a p i e r k o r b " ;
} ;
} ;
amroplay = enableDefaults {
primary = false ;
flavor = " g m a i l . c o m " ;
address = " a m r o p l a y @ g m a i l . c o m " ;
2020-10-30 11:05:26 +01:00
realName = kieran . name ;
2020-09-24 11:12:52 +02:00
userName = " a m r o p l a y " ;
2020-09-24 19:25:47 +02:00
passwordCommand = pass_ <secrets/mail/gmail/amroplay> ;
2020-09-24 11:12:52 +02:00
folders = {
drafts = " [ G m a i l ] / D r a f t s " ;
sent = " [ G m a i l ] / S e n t M a i l " ;
trash = " [ G m a i l ] / B i n " ;
} ;
} ;
posteo = enableDefaults {
primary = true ;
smtp = {
host = " p o s t e o . d e " ;
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 = " p o s t e o . d e " ;
port = 993 ;
tls . enable = true ;
} ;
address = " k i e r a n . m e i n h a r d t @ p o s t e o . n e t " ;
2020-10-30 11:05:26 +01:00
realName = kieran . name ;
2020-09-24 11:12:52 +02:00
userName = " k i e r a n . m e i n h a r d t @ p o s t e o . n e t " ;
2020-09-24 19:25:47 +02:00
passwordCommand = pass_ <secrets/mail/posteo> ;
2020-09-24 11:12:52 +02:00
} ;
hu-berlin = enableDefaults {
2020-04-22 17:42:45 +02:00
primary = false ;
address = " m e i n h a r k @ h u - b e r l i n . d e " ;
2020-10-30 11:05:26 +01:00
realName = kieran . name ;
2020-04-22 17:42:45 +02:00
userName = " m e i n h a r k " ;
2020-09-24 19:25:47 +02:00
passwordCommand = pass_ <secrets/eduroam/password> ;
2020-04-22 17:42:45 +02:00
smtp = {
host = " m a i l h o s t . c m s . h u - b e r l i n . d e " ;
port = 25 ;
2020-07-14 23:51:07 +02:00
tls = {
enable = true ;
useStartTls = true ;
} ;
2020-04-22 17:42:45 +02:00
} ;
imap = {
host = " m a i l b o x . c m s . h u - b e r l i n . d e " ;
port = 993 ;
tls . enable = true ;
} ;
2020-04-18 17:58:44 +02:00
} ;
2020-12-11 18:43:54 +01:00
hu-berlin-work = enableDefaults {
primary = false ;
address = " m e i n h a k i @ h u - b e r l i n . d e " ;
realName = kieran . name ;
userName = " m e i n h a k i " ;
passwordCommand = pass_ <secrets/mail/meinhaki> ;
smtp = {
host = " m a i l h o s t . c m s . h u - b e r l i n . d e " ;
port = 25 ;
tls = {
enable = true ;
useStartTls = true ;
} ;
} ;
imap = {
host = " m a i l b o x . c m s . h u - b e r l i n . d e " ;
port = 993 ;
tls . enable = true ;
} ;
} ;
2020-09-24 10:35:53 +02:00
} ;
2019-04-20 09:08:39 +02:00
} ;
}