blob: 1d8046af9c49153d2af781d913d440531d0daa4a (
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
141
142
143
144
145
146
147
|
# Converts neomutt account options into home-manager email config
{ config, lib, ... }:
let
cfg = config.communication.neomutt;
mbsyncGroupNames = (import ../lib.nix { inherit lib; }).mbsyncGroupNames;
in
{
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 cfg.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) {
inherit (accountInformation.folders) drafts;
}
// lib.optionalAttrs (accountInformation.folders.sent != null) {
inherit (accountInformation.folders) sent;
};
neomutt = {
enable = true;
mailboxType = accountInformation.neomutt.mailbox-type;
extraConfig = accountInformation.neomutt.extraConfig;
};
mbsync = {
enable = true;
create = accountInformation.mbsync.create;
expunge = "both";
patterns = accountInformation.mbsync.patterns;
flatten = accountInformation.mbsync.flatten;
extraConfig = {
account = {
PipelineDepth = 50;
}
// accountInformation.mbsync.extraConfig.account;
channel = accountInformation.mbsync.extraConfig.channel;
local = accountInformation.mbsync.extraConfig.local;
remote = accountInformation.mbsync.extraConfig.remote;
};
groups =
let
group = mbsyncGroupNames accountName;
mkChannels =
sync:
lib.mapAttrs (local: remote: {
farPattern = remote;
nearPattern = local;
extraConfig = {
Create = "Near";
Expunge = "Both";
Sync = sync;
SyncState = "*";
};
}) accountInformation.mbsync.folders.map;
in
{
"${group.full}".channels = mkChannels "All";
"${group.quick}".channels = mkChannels [
"Pull"
"New"
];
};
};
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) cfg.accounts);
};
}
|