summaryrefslogtreecommitdiff
path: root/modules/mail/default.nix
blob: 1d023e6bbbfe7815a24df31fb0a9a59d1b9c355c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
{ config, pkgs, ... }:
let
  mbsyncConf = ./mbsyncrc;
in
{
  environment.systemPackages = with pkgs; [
    isync
    msmtp
    neomutt
    notmuch
    w3m
    links2
  ];

  environment.shellAliases = {
    mutt = "neomutt";
  };

  sops.secrets = {
    "mail/oxapentane.com" = {
      owner = config.users.users."0xa".name;
    };
    "mail/shipunov.xyz" = {
      owner = config.users.users."0xa".name;
    };
    "mail/dvb.solutions" = {
      owner = config.users.users."0xa".name;
    };
    "mail/tlm.solutions" = {
      owner = config.users.users."0xa".name;
    };
  };

  programs.msmtp = {
    enable = true;
    setSendmail = true;
    extraConfig = ''
      account mail@oxapentane.com
      host smtp.migadu.com
      port 587
      from *@oxapentane.com
      user mail@oxapentane.com
      passwordeval cat ${config.sops.secrets."mail/oxapentane.com".path}
      auth on
      tls on
      tls_trust_file	/etc/ssl/certs/ca-certificates.crt
      logfile ~/.msmtp.log

      account grigory@shipunov.xyz
      host smtp.migadu.com
      port 587
      from *@shipunov.xyz
      user grigory@shipunov.xyz
      passwordeval cat ${config.sops.secrets."mail/shipunov.xyz".path}
      auth on
      tls on
      tls_trust_file	/etc/ssl/certs/ca-certificates.crt
      logfile ~/.msmtp.log

      account dump@dvb.solutions
      host smtp.migadu.com
      port 587
      from dump@dvb.solutions
      user dump@dvb.solutions
      passwordeval cat ${config.sops.secrets."mail/dvb.solutions".path}
      auth on
      tls on
      tls_trust_file	/etc/ssl/certs/ca-certificates.crt
      logfile ~/.msmtp.log

      account grigory@tlm.solutions
      host smtp.migadu.com
      port 587
      from grigory@tlm.solutions
      user grigory@tlm.solutions
      passwordeval cat ${config.sops.secrets."mail/tlm.solutions".path}
      auth on
      tls on
      tls_trust_file	/etc/ssl/certs/ca-certificates.crt
      logfile ~/.msmtp.log
    '';
  };

  systemd.user = {

    # Service and timer to sync imap to local maildir
    services.mbsync = {
      enable = true;
      after = [
        "graphical.target"
        "network-online.target"
      ];
      script = ''
        ${pkgs.isync}/bin/mbsync -q -a --config=${mbsyncConf}
      '';
      serviceConfig = {
        Type = "oneshot";
      };
    };

    timers.mbsync = {
      enable = true;
      wantedBy = [ "timers.target" ];
      timerConfig = {
        Unit = "mbsync.service";
        OnBootSec = "5m";
        OnUnitInactiveSec = "11m";
      };
    };

    # service and timer to flush the msmtp queue
    services.flush-msmtpq = {
      enable = true;
      after = [
        "graphical.target"
        "network-online.target"
      ];
      script = ''
        ${pkgs.msmtp}/bin/msmtp-queue -r
      '';
      serviceConfig = {
        Type = "oneshot";
      };
      environment = {
        EMAIL_CONN_TEST = "x"; # connection test is broken
      };
    };

    timers.flush-msmtpq = {
      enable = true;
      wantedBy = [ "timers.target" ];
      timerConfig = {
        Unit = "flush-msmtpq.service";
        OnBootSec = "11m";
        OnUnitInactiveSec = "13m";
      };
    };

  };
}