This repository has no description
11 kB
295 lines
1{ self, ... }:
2{
3 perSystem =
4 {
5 pkgs,
6 lib,
7 system,
8 ...
9 }:
10 {
11 packages.mutt =
12 let
13 # Mailboxes configuration from mail.nix
14 mailboxes = {
15 afra = [ "to:afra@afra-berlin.de" ];
16 c-base = [ "to:c-base.org" ];
17 coins = [
18 "to:btce@lassul.us"
19 "to:coinbase@lassul.us"
20 "to:polo@lassul.us"
21 "to:bitwala@lassul.us"
22 "to:payeer@lassul.us"
23 "to:gatehub@lassul.us"
24 "to:bitfinex@lassul.us"
25 "to:binance@lassul.us"
26 "to:bitcoin.de@lassul.us"
27 "to:robinhood@lassul.us"
28 ];
29 dezentrale = [ "to:dezentrale.space" ];
30 dhl = [ "to:dhl@lassul.us" ];
31 dn42 = [ "to:dn42@lists.nox.tf" ];
32 eloop = [ "to:eloop.org" ];
33 github = [ "to:github@lassul.us" ];
34 gmail = [
35 "to:gmail@lassul.us"
36 "to:lassulus@gmail.com"
37 "lassulus@googlemail.com"
38 ];
39 india = [
40 "to:hillhackers@lists.hillhacks.in"
41 "to:hackbeach@lists.hackbeach.in"
42 "to:hackbeach@mail.hackbeach.in"
43 ];
44 kaosstuff = [
45 "to:gearbest@lassul.us"
46 "to:banggood@lassul.us"
47 "to:tomtop@lassul.us"
48 ];
49 lugs = [ "to:lugs@lug-s.org" ];
50 meetup = [ "to:meetup@lassul.us" ];
51 nix = [
52 "to:nix-devel@googlegroups.com"
53 "to:nix@lassul.us"
54 ];
55 patreon = [ "to:patreon@lassul.us" ];
56 paypal = [ "to:paypal@lassul.us" ];
57 ptl = [ "to:ptl@posttenebraslab.ch" ];
58 retiolum = [ "to:lass@mors.r" ];
59 security = [
60 "to:seclists.org"
61 "to:bugtraq"
62 "to:securityfocus@lassul.us"
63 "to:security-announce@lists.apple.com"
64 ];
65 shack = [ "to:shackspace.de" ];
66 steam = [ "to:steam@lassul.us" ];
67 tinc = [
68 "to:tinc@tinc-vpn.org"
69 "to:tinc-devel@tinc-vpn.org"
70 ];
71 wireguard = [ "to:wireguard@lists.zx2c4" ];
72 zzz = [
73 "to:pizza@lassul.us"
74 "to:spam@krebsco.de"
75 ];
76 };
77
78 notmuchConfig = ''
79 [database]
80 path=Maildir
81 mail_root=Maildir
82
83 [user]
84 name=lassulus
85 primary_email=lassulus@lassul.us
86 other_email=lass@mors.r;${lib.concatStringsSep ";" (lib.flatten (lib.attrValues mailboxes))}
87
88 [new]
89 tags=unread;inbox;
90 ignore=
91
92 [search]
93 exclude_tags=deleted;spam;
94
95 [maildir]
96 synchronize_flags=true
97 '';
98
99 mailcap = pkgs.writeText "mailcap" ''
100 text/html; ${pkgs.elinks}/bin/elinks -dump ; copiousoutput;
101 '';
102
103 msmtprc = pkgs.writeText "msmtprc" ''
104 defaults
105 logfile ~/.msmtp.log
106 account prism
107 host prism.r
108 account c-base
109 from lassulus@c-base.org
110 host c-mail.c-base.org
111 port 465
112 tls on
113 tls_starttls off
114 auth on
115 user lassulus
116 passwordeval pass show c-base/pass
117 account default: prism
118 '';
119
120 msmtp = pkgs.writeShellScriptBin "msmtp" ''
121 # Check if prism.r is reachable, fallback to Tor if not
122 if ping -W2 -c1 prism.r >/dev/null 2>&1; then
123 ${pkgs.coreutils}/bin/tee >(${pkgs.notmuch}/bin/notmuch insert +sent) | \
124 ${pkgs.msmtp}/bin/msmtp -C ${msmtprc} "$@"
125 else
126 # Build dependencies lazily for Tor fallback
127 echo "Building tornade and clan-cli for Tor fallback..." >&2
128 tornade_path=$(nix build --no-link --print-out-paths "${self}#tornade")
129 clan_path=$(nix build --no-link --print-out-paths "${self}#clan-cli")
130
131 # Get tor hostname using clan CLI
132 tor_hostname=$(CLAN_DIR="${self}" "$clan_path/bin/clan" vars get prism tor-ssh/tor-hostname)
133
134 # Use tornade to send via Tor
135 ${pkgs.coreutils}/bin/tee >(${pkgs.notmuch}/bin/notmuch insert +sent) | \
136 "$tornade_path/bin/tornade" ssh -T lass@"$tor_hostname" "cat | msmtp -C /etc/msmtprc $*"
137 fi
138 '';
139
140 muttrc = pkgs.writeText "muttrc" ''
141 # read html mails
142 auto_view text/html
143 set mailcap_path = ${mailcap}
144
145 # notmuch
146 set folder="$HOME/Maildir"
147 set nm_default_uri = "notmuch://$HOME/Maildir"
148 set nm_record = yes
149 set nm_record_tags = "-inbox me archive"
150 set spoolfile = +Inbox
151 set virtual_spoolfile = yes
152
153 set sendmail="${msmtp}/bin/msmtp"
154 set from="lassulus@lassul.us"
155 alternates ^.*@lassul\.us$ ^.*@.*\.r$
156 unset envelope_from_address
157 set use_envelope_from
158 set reverse_name
159 set markers=no
160
161 set sort=threads
162
163 set index_format="%4C %Z %?GI?%GI& ? %[%y-%m-%d] %-20.20a %?M?(%3M)& ? %s %> %r %g"
164
165 virtual-mailboxes "Unread" "notmuch://?query=tag:unread"
166 virtual-mailboxes "INBOX" "notmuch://?query=tag:inbox"
167 ${lib.concatMapStringsSep "\n" (
168 i: ''${" "}virtual-mailboxes "${i.name}" "notmuch://?query=tag:${i.name}"''
169 ) (lib.mapAttrsToList lib.nameValuePair mailboxes)}
170 virtual-mailboxes "TODO" "notmuch://?query=tag:TODO"
171 virtual-mailboxes "Starred" "notmuch://?query=tag:*"
172 virtual-mailboxes "Archive" "notmuch://?query=tag:archive"
173 virtual-mailboxes "Sent" "notmuch://?query=tag:sent"
174 virtual-mailboxes "Junk" "notmuch://?query=tag:junk"
175 virtual-mailboxes "All" "notmuch://?query=*"
176
177 tag-transforms "junk" "k" \
178 "unread" "u" \
179 "replied" "↻" \
180 "TODO" "T" \
181
182 # notmuch bindings
183 macro index \\\\ "<vfolder-from-query>"
184 macro index + "<modify-labels>+*\n<sync-mailbox>"
185 macro index - "<modify-labels>-*\n<sync-mailbox>"
186
187 # muchsync
188 bind index \Cr noop
189 macro index \Cr \
190 "<enter-command>unset wait_key<enter> \
191 <sync-mailbox> \
192 <shell-escape>${self.packages.${pkgs.system}.muchsync}/bin/muchsync -vv<enter> \
193 <sync-mailbox>
194
195 #killed
196 bind index d noop
197 bind pager d noop
198
199 bind index S noop
200 bind index s noop
201 bind pager S noop
202 bind pager s noop
203 macro index S "<modify-labels-then-hide>-inbox -unread +junk\n"
204 macro index s "<modify-labels>-junk\n"
205 macro pager S "<modify-labels-then-hide>-inbox -unread +junk\n"
206 macro pager s "<modify-labels>-junk\n"
207
208 bind index A noop
209 bind index a noop
210 bind pager A noop
211 bind pager a noop
212 macro index A "<modify-labels>+archive -unread -inbox\n"
213 macro index a "<modify-labels>-archive\n"
214 macro pager A "<modify-labels>+archive -unread -inbox\n"
215 macro pager a "<modify-labels>-archive\n"
216
217 bind index U noop
218 bind index u noop
219 bind pager U noop
220 bind pager u noop
221 macro index U "<modify-labels>+unread\n"
222 macro index u "<modify-labels>-unread\n"
223 macro pager U "<modify-labels>+unread\n"
224 macro pager u "<modify-labels>-unread\n"
225
226 bind index t noop
227 bind pager t noop
228 macro index t "<modify-labels>"
229
230 # top index bar in email view
231 set pager_index_lines=7
232 # top_index_bar toggle
233 macro pager ,@1 "<enter-command> set pager_index_lines=0; macro pager ] ,@2 'Toggle indexbar<Enter>"
234 macro pager ,@2 "<enter-command> set pager_index_lines=3; macro pager ] ,@3 'Toggle indexbar<Enter>"
235 macro pager ,@3 "<enter-command> set pager_index_lines=7; macro pager ] ,@1 'Toggle indexbar<Enter>"
236 macro pager ] ,@1 'Toggle indexbar
237
238 # scan urls from emails
239 macro index,pager \cb "<pipe-message> ${lib.getExe pkgs.urlscan}<Enter>"
240 macro attach,compose \cb "<pipe-entry> ${lib.getExe pkgs.urlscan}<Enter>"
241
242 # sidebar
243 set sidebar_divider_char = '│'
244 set sidebar_delim_chars = "/"
245 set sidebar_short_path
246 set sidebar_folder_indent
247 set sidebar_visible = yes
248 set sidebar_format = '%D%?F? [%F]?%* %?N?%N/? %?S?%S?'
249 set sidebar_width = 20
250 color sidebar_new yellow red
251
252 # sidebar bindings
253 bind index <left> sidebar-prev
254 bind index <right> sidebar-next
255 bind index <space> sidebar-open
256 # sidebar toggle
257 macro index,pager ,@) "<enter-command> set sidebar_visible=no; macro index,pager [ ,@( 'Toggle sidebar'<Enter>"
258 macro index,pager ,@( "<enter-command> set sidebar_visible=yes; macro index,pager [ ,@) 'Toggle sidebar'<Enter>"
259 macro index,pager [ ,@( 'Toggle sidebar'
260
261 # forward with attachment
262 set mime_forward = no
263 set forward_attachments = yes
264
265 # better handling of long URLs
266 set wrap = 0 # don't wrap lines in the pager
267 set markers = no # don't show + markers for wrapped lines
268 set smart_wrap = yes # wrap at word boundaries when displaying
269 set pager_stop = yes # don't jump to next message at end of pager
270 '';
271
272 in
273 self.libWithPkgs.${pkgs.system}.makeWrapper pkgs.neomutt {
274 runtimeInputs =
275 [
276 pkgs.elinks
277 pkgs.msmtp
278 pkgs.notmuch
279 pkgs.urlscan
280 ]
281 ++ lib.optionals pkgs.stdenv.isLinux [
282 pkgs.iputils
283 ];
284 env = {
285 NOTMUCH_CONFIG = "${pkgs.writeText "notmuch-config" notmuchConfig}";
286 };
287 flags = {
288 "-F" = "${muttrc}";
289 };
290 passthru = {
291 notmuchConfig = notmuchConfig;
292 };
293 };
294 };
295}