aboutsummaryrefslogtreecommitdiffstats
path: root/modules/communication/neomutt/account/default.nix
blob: 61256e1ddbe0a2323ddd66bdb5886ddea6c02a65 (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
# Converts neomutt account options into home-manager email config
{ config, lib, ... }:
{
  imports = [
    ./assertions.nix
  ];

  options.communication.neomutt.accounts = lib.mkOption {
    type = lib.types.attrsOf (
      lib.types.submodule {
        imports = [
          ./flavors/gmail
          ./options.nix
          ./sync-channel.nix
        ];
      }
    );
    default = { };
    description = "Specification of email accounts.";
  };

  config = lib.mkIf config.communication.neomutt.enable {
    accounts.email.accounts = lib.mapAttrs (accountName: accountInformation: {
      inherit (accountInformation) address primary;

      realName = accountInformation.real-name;

      userName =
        if accountInformation.username != null then
          accountInformation.username
        else
          accountInformation.address;

      passwordCommand =
        if accountInformation.password-gopass-secret != null then
          "${lib.getExe config.security.gopass.package} -o ${accountInformation.password-gopass-secret}"
        else
          null;

      flavor = accountInformation.flavor;
      inherit (accountInformation) aliases;

      folders = {
        inherit (accountInformation.folders) inbox trash;
      }
      // lib.optionalAttrs (accountInformation.folders.drafts != null) {
        drafts = accountInformation.folders.drafts;
      }
      // lib.optionalAttrs (accountInformation.folders.sent != null) {
        sent = accountInformation.folders.sent;
      };

      neomutt = {
        enable = true;
        mailboxType = accountInformation.neomutt.mailbox-type;
        extraConfig = accountInformation.neomutt.extraConfig;
      };

      mbsync = {
        enable = true;
        create = accountInformation.mbsync.create;
        patterns = accountInformation.mbsync.patterns;
        flatten = accountInformation.mbsync.flatten;
        extraConfig = {
          account = accountInformation.mbsync.extraConfig.account;
          channel = accountInformation.mbsync.extraConfig.channel;
          local = accountInformation.mbsync.extraConfig.local;
          remote = accountInformation.mbsync.extraConfig.remote;
        };
      };

      notmuch = {
        enable = true;
        neomutt = {
          enable = true;
          virtualMailboxes = accountInformation.notmuch.neomutt.virtual-mailboxes;
        };
      };

      imap = lib.optionalAttrs (accountInformation.imap.host != null) {
        host = accountInformation.imap.host;
        port = accountInformation.imap.port;
        tls = {
          enable = accountInformation.imap.tls.enable;
          useStartTls = accountInformation.imap.tls.use-start-tls;
        };
      };

      smtp = lib.optionalAttrs (accountInformation.smtp.host != null) {
        host = accountInformation.smtp.host;
        port = accountInformation.smtp.port;
        tls = {
          enable = accountInformation.smtp.tls.enable;
          useStartTls = accountInformation.smtp.tls.use-start-tls;
        };
      };

      gpg = lib.optionalAttrs (accountInformation.gpg.key != null) {
        key = accountInformation.gpg.key;
        signByDefault = accountInformation.gpg.sign-by-default;
        encryptByDefault = accountInformation.gpg.encrypt-by-default;
      };

      signature =
        lib.optionalAttrs
          (accountInformation.signature.text != null || accountInformation.signature.command != null)
          {
            text = accountInformation.signature.text;
            command = accountInformation.signature.command;
            showSignature = accountInformation.signature.show-signature;
          };
    }) (lib.filterAttrs (n: a: a.enable) config.communication.neomutt.accounts);
  };
}