summaryrefslogtreecommitdiff
path: root/modules/profiles/email.nix
blob: 4c8d6eb619d1fdd37d25d7b610794afbf00a159e (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
{
  config,
  lib,
  pkgs,
  this,
  ...
}:
with lib;
let
  cfg = config.nixfiles.modules.profiles.email;
in
{
  options.nixfiles.modules.profiles.email.enable = mkEnableOption "Local Email management" // {
    default = this.isHeadful;
  };

  config = mkIf cfg.enable {
    nixfiles.modules.gnupg.enable = true;

    hm = {
      accounts.email = {
        maildirBasePath = "${config.my.home}/doc/mail";

        accounts =
          let
            mkAccount =
              attrs:
              mkMerge [
                {
                  mbsync = {
                    enable = true;
                    create = "both";
                    expunge = "both";
                    patterns = [ "*" ];
                  };
                  msmtp.enable = true;
                  mu.enable = true;
                  thunderbird = {
                    enable = true;
                    settings = id: {
                      "mail.identity.id_${id}.compose_html" = false;
                      "mail.identity.id_${id}.reply_on_top" = 0;
                    };
                  };
                }
                attrs
              ];

            getPassword =
              {
                path,
                line ? 0,
              }:
              assert (builtins.isInt line);
              concatStringsSep " " (
                [
                  (getExe config.hm.programs.password-store.package)
                  "show"
                  path
                ]
                ++ optionals (line > 0) [
                  "|"
                  (getExe pkgs.gnused)
                  "-e"
                  "'${toString line}!d'"
                ]
              );
          in
          {
            shire = mkAccount rec {
              address = my.email;
              aliases = [
                address
                "frodo@rohan.net"
                "azahi@shire.net"
              ];
              realName = my.fullname;
              signature = {
                showSignature = "append";
                text = ''
                  Please consider using plain text when replying!
                  ~    https://useplaintext.email/#etiquette    ~
                '';
              };
              gpg = {
                inherit (my.pgp) key;
                signByDefault = false;
                encryptByDefault = false;
              };

              primary = true;

              imap = {
                host = "shire.net";
                port = 993;
                tls.enable = true;
              };
              smtp = {
                host = "shire.net";
                port = 465;
                tls.enable = true;
              };
              userName = "azahi@shire.net";
              passwordCommand = getPassword { path = "email/shire.net/azahi"; };
            };

            yandex = mkAccount rec {
              address = "username@ya.ru";
              aliases = [
                address
                "username@yandex.ru"
              ];
              realName = "Firstname Lastname";

              flavor = "yandex.com";
              userName = "username@yandex.ru";
              passwordCommand = getPassword {
                path = "email/yandex.ru/username";
                line = 2;
              };
            };
          };
      };

      programs = {
        mbsync.enable = true;
        msmtp.enable = true;
        mu.enable = true;
      };
    };
  };
}