Commit | Line | Data |
---|---|---|
d8c18af8 AW |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2015 Andy Wingo <wingo@igalia.com> | |
8d9bb4b4 | 3 | ;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org> |
82ccc499 | 4 | ;;; Copyright © 2017 Carlo Zancanaro <carlo@zancanaro.id.au> |
c3f146e7 | 5 | ;;; Copyright © 2017, 2020 Tobias Geerinckx-Rice <me@tobias.gr> |
ace8e269 | 6 | ;;; Copyright © 2019 Kristofer Buffington <kristoferbuffington@gmail.com> |
d8c18af8 AW |
7 | ;;; |
8 | ;;; This file is part of GNU Guix. | |
9 | ;;; | |
10 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
11 | ;;; under the terms of the GNU General Public License as published by | |
12 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
13 | ;;; your option) any later version. | |
14 | ;;; | |
15 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
16 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;;; GNU General Public License for more details. | |
19 | ;;; | |
20 | ;;; You should have received a copy of the GNU General Public License | |
21 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
22 | ;;; | |
23 | ;;; Some of the help text was taken from the default dovecot.conf files. | |
24 | ||
25 | (define-module (gnu services mail) | |
26 | #:use-module (gnu services) | |
27 | #:use-module (gnu services base) | |
5305ed20 | 28 | #:use-module (gnu services configuration) |
0190c1c0 | 29 | #:use-module (gnu services shepherd) |
d8c18af8 AW |
30 | #:use-module (gnu system pam) |
31 | #:use-module (gnu system shadow) | |
32 | #:use-module (gnu packages mail) | |
33 | #:use-module (gnu packages admin) | |
34 | #:use-module (gnu packages tls) | |
35 | #:use-module (guix records) | |
36 | #:use-module (guix packages) | |
37 | #:use-module (guix gexp) | |
d8c18af8 | 38 | #:use-module (ice-9 match) |
82ccc499 | 39 | #:use-module (ice-9 format) |
8d17cf1c | 40 | #:use-module (srfi srfi-1) |
5305ed20 | 41 | #:export (dovecot-service |
24e96431 | 42 | dovecot-service-type |
d8c18af8 AW |
43 | dovecot-configuration |
44 | opaque-dovecot-configuration | |
45 | ||
46 | dict-configuration | |
47 | passdb-configuration | |
48 | userdb-configuration | |
49 | unix-listener-configuration | |
50 | fifo-listener-configuration | |
51 | inet-listener-configuration | |
52 | service-configuration | |
53 | protocol-configuration | |
54 | plugin-configuration | |
55 | mailbox-configuration | |
f88371e8 SB |
56 | namespace-configuration |
57 | ||
58 | opensmtpd-configuration | |
59 | opensmtpd-configuration? | |
60 | opensmtpd-service-type | |
82ccc499 CZ |
61 | %default-opensmtpd-config-file |
62 | ||
8d17cf1c CZ |
63 | mail-aliases-service-type |
64 | ||
82ccc499 CZ |
65 | exim-configuration |
66 | exim-configuration? | |
67 | exim-service-type | |
412e6396 SB |
68 | %default-exim-config-file |
69 | ||
70 | imap4d-configuration | |
71 | imap4d-configuration? | |
72 | imap4d-service-type | |
f7dbf186 | 73 | %default-imap4d-config-file)) |
d8c18af8 AW |
74 | |
75 | ;;; Commentary: | |
76 | ;;; | |
77 | ;;; This module provides service definitions for the Dovecot POP3 and IMAP | |
78 | ;;; mail server. | |
79 | ;;; | |
80 | ;;; Code: | |
81 | ||
56aef188 CL |
82 | (define (uglify-field-name field-name) |
83 | (let ((str (symbol->string field-name))) | |
84 | (string-join (string-split (if (string-suffix? "?" str) | |
85 | (substring str 0 (1- (string-length str))) | |
86 | str) | |
87 | #\-) | |
88 | "_"))) | |
89 | ||
90 | (define (serialize-field field-name val) | |
91 | (format #t "~a=~a\n" (uglify-field-name field-name) val)) | |
92 | ||
93 | (define (serialize-string field-name val) | |
94 | (serialize-field field-name val)) | |
95 | ||
96 | (define (space-separated-string-list? val) | |
97 | (and (list? val) | |
98 | (and-map (lambda (x) | |
99 | (and (string? x) (not (string-index x #\space)))) | |
100 | val))) | |
101 | (define (serialize-space-separated-string-list field-name val) | |
a1640091 AA |
102 | (match val |
103 | (() #f) | |
104 | (_ (serialize-field field-name (string-join val " "))))) | |
d8c18af8 AW |
105 | |
106 | (define (comma-separated-string-list? val) | |
107 | (and (list? val) | |
108 | (and-map (lambda (x) | |
109 | (and (string? x) (not (string-index x #\,)))) | |
110 | val))) | |
111 | (define (serialize-comma-separated-string-list field-name val) | |
112 | (serialize-field field-name (string-join val ","))) | |
113 | ||
56aef188 CL |
114 | (define (file-name? val) |
115 | (and (string? val) | |
116 | (string-prefix? "/" val))) | |
117 | (define (serialize-file-name field-name val) | |
118 | (serialize-string field-name val)) | |
119 | ||
d8c18af8 AW |
120 | (define (colon-separated-file-name-list? val) |
121 | (and (list? val) | |
122 | ;; Trailing slashes not needed and not | |
123 | (and-map file-name? val))) | |
124 | (define (serialize-colon-separated-file-name-list field-name val) | |
125 | (serialize-field field-name (string-join val ":"))) | |
126 | ||
56aef188 CL |
127 | (define (serialize-boolean field-name val) |
128 | (serialize-string field-name (if val "yes" "no"))) | |
129 | ||
d8c18af8 AW |
130 | (define (non-negative-integer? val) |
131 | (and (exact-integer? val) (not (negative? val)))) | |
132 | (define (serialize-non-negative-integer field-name val) | |
133 | (serialize-field field-name val)) | |
134 | ||
135 | (define (hours? val) (non-negative-integer? val)) | |
136 | (define (serialize-hours field-name val) | |
137 | (serialize-field field-name (format #f "~a hours" val))) | |
138 | ||
139 | (define (free-form-fields? val) | |
140 | (match val | |
141 | (() #t) | |
ad34409e | 142 | ((((? symbol?) . (? string?)) . val) (free-form-fields? val)) |
d8c18af8 AW |
143 | (_ #f))) |
144 | (define (serialize-free-form-fields field-name val) | |
145 | (for-each (match-lambda ((k . v) (serialize-field k v))) val)) | |
146 | ||
147 | (define (free-form-args? val) | |
148 | (match val | |
149 | (() #t) | |
ad34409e | 150 | ((((? symbol?) . (? string?)) . val) (free-form-args? val)) |
d8c18af8 AW |
151 | (_ #f))) |
152 | (define (serialize-free-form-args field-name val) | |
153 | (serialize-field field-name | |
154 | (string-join | |
155 | (map (match-lambda ((k . v) (format #t "~a=~a" k v))) val) | |
156 | " "))) | |
157 | ||
158 | (define-configuration dict-configuration | |
159 | (entries | |
160 | (free-form-fields '()) | |
161 | "A list of key-value pairs that this dict should hold.")) | |
162 | ||
163 | (define (serialize-dict-configuration field-name val) | |
164 | (format #t "dict {\n") | |
165 | (serialize-configuration val dict-configuration-fields) | |
166 | (format #t "}\n")) | |
167 | ||
168 | (define-configuration passdb-configuration | |
169 | (driver | |
170 | (string "pam") | |
171 | "The driver that the passdb should use. Valid values include | |
172 | @samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and | |
173 | @samp{static}.") | |
174 | (args | |
deb36188 CL |
175 | (space-separated-string-list '()) |
176 | "Space separated list of arguments to the passdb driver.")) | |
d8c18af8 AW |
177 | |
178 | (define (serialize-passdb-configuration field-name val) | |
179 | (format #t "passdb {\n") | |
180 | (serialize-configuration val passdb-configuration-fields) | |
181 | (format #t "}\n")) | |
182 | (define (passdb-configuration-list? val) | |
183 | (and (list? val) (and-map passdb-configuration? val))) | |
184 | (define (serialize-passdb-configuration-list field-name val) | |
185 | (for-each (lambda (val) (serialize-passdb-configuration field-name val)) val)) | |
186 | ||
187 | (define-configuration userdb-configuration | |
188 | (driver | |
189 | (string "passwd") | |
190 | "The driver that the userdb should use. Valid values include | |
191 | @samp{passwd} and @samp{static}.") | |
192 | (args | |
deb36188 CL |
193 | (space-separated-string-list '()) |
194 | "Space separated list of arguments to the userdb driver.") | |
d8c18af8 AW |
195 | (override-fields |
196 | (free-form-args '()) | |
197 | "Override fields from passwd.")) | |
198 | ||
199 | (define (serialize-userdb-configuration field-name val) | |
200 | (format #t "userdb {\n") | |
201 | (serialize-configuration val userdb-configuration-fields) | |
202 | (format #t "}\n")) | |
203 | (define (userdb-configuration-list? val) | |
204 | (and (list? val) (and-map userdb-configuration? val))) | |
205 | (define (serialize-userdb-configuration-list field-name val) | |
206 | (for-each (lambda (val) (serialize-userdb-configuration field-name val)) val)) | |
207 | ||
208 | (define-configuration unix-listener-configuration | |
209 | (path | |
eba56076 CL |
210 | (string (configuration-missing-field 'unix-listener 'path)) |
211 | "Path to the file, relative to @code{base-dir} field. This is also used as | |
212 | the section name.") | |
d8c18af8 AW |
213 | (mode |
214 | (string "0600") | |
215 | "The access mode for the socket.") | |
216 | (user | |
217 | (string "") | |
218 | "The user to own the the socket.") | |
219 | (group | |
220 | (string "") | |
221 | "The group to own the socket.")) | |
222 | ||
223 | (define (serialize-unix-listener-configuration field-name val) | |
224 | (format #t "unix_listener ~a {\n" (unix-listener-configuration-path val)) | |
225 | (serialize-configuration val (cdr unix-listener-configuration-fields)) | |
226 | (format #t "}\n")) | |
227 | ||
228 | (define-configuration fifo-listener-configuration | |
229 | (path | |
eba56076 CL |
230 | (string (configuration-missing-field 'fifo-listener 'path)) |
231 | "Path to the file, relative to @code{base-dir} field. This is also used as | |
232 | the section name.") | |
d8c18af8 AW |
233 | (mode |
234 | (string "0600") | |
235 | "The access mode for the socket.") | |
236 | (user | |
237 | (string "") | |
238 | "The user to own the the socket.") | |
239 | (group | |
240 | (string "") | |
241 | "The group to own the socket.")) | |
242 | ||
243 | (define (serialize-fifo-listener-configuration field-name val) | |
244 | (format #t "fifo_listener ~a {\n" (fifo-listener-configuration-path val)) | |
245 | (serialize-configuration val (cdr fifo-listener-configuration-fields)) | |
246 | (format #t "}\n")) | |
247 | ||
248 | (define-configuration inet-listener-configuration | |
249 | (protocol | |
5305ed20 | 250 | (string (configuration-missing-field 'inet-listener 'protocol)) |
d8c18af8 AW |
251 | "The protocol to listen for.") |
252 | (address | |
253 | (string "") | |
254 | "The address on which to listen, or empty for all addresses.") | |
255 | (port | |
256 | (non-negative-integer | |
5305ed20 | 257 | (configuration-missing-field 'inet-listener 'port)) |
d8c18af8 AW |
258 | "The port on which to listen.") |
259 | (ssl? | |
260 | (boolean #t) | |
261 | "Whether to use SSL for this service; @samp{yes}, @samp{no}, or | |
262 | @samp{required}.")) | |
263 | ||
264 | (define (serialize-inet-listener-configuration field-name val) | |
265 | (format #t "inet_listener ~a {\n" (inet-listener-configuration-protocol val)) | |
266 | (serialize-configuration val (cdr inet-listener-configuration-fields)) | |
267 | (format #t "}\n")) | |
268 | ||
269 | (define (listener-configuration? val) | |
270 | (or (unix-listener-configuration? val) | |
271 | (fifo-listener-configuration? val) | |
272 | (inet-listener-configuration? val))) | |
273 | (define (serialize-listener-configuration field-name val) | |
274 | (cond | |
275 | ((unix-listener-configuration? val) | |
276 | (serialize-unix-listener-configuration field-name val)) | |
277 | ((fifo-listener-configuration? val) | |
278 | (serialize-fifo-listener-configuration field-name val)) | |
279 | ((inet-listener-configuration? val) | |
280 | (serialize-inet-listener-configuration field-name val)) | |
5305ed20 | 281 | (else (configuration-field-error field-name val)))) |
d8c18af8 AW |
282 | (define (listener-configuration-list? val) |
283 | (and (list? val) (and-map listener-configuration? val))) | |
284 | (define (serialize-listener-configuration-list field-name val) | |
285 | (for-each (lambda (val) | |
286 | (serialize-listener-configuration field-name val)) | |
287 | val)) | |
288 | ||
289 | (define-configuration service-configuration | |
290 | (kind | |
5305ed20 | 291 | (string (configuration-missing-field 'service 'kind)) |
d8c18af8 AW |
292 | "The service kind. Valid values include @code{director}, |
293 | @code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap}, | |
294 | @code{pop3}, @code{auth}, @code{auth-worker}, @code{dict}, | |
295 | @code{tcpwrap}, @code{quota-warning}, or anything else.") | |
296 | (listeners | |
297 | (listener-configuration-list '()) | |
298 | "Listeners for the service. A listener is either an | |
299 | @code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or | |
300 | an @code{inet-listener-configuration}.") | |
8d9bb4b4 CL |
301 | (client-limit |
302 | (non-negative-integer 0) | |
303 | "Maximum number of simultaneous client connections per process. Once this | |
304 | number of connections is received, the next incoming connection will prompt | |
305 | Dovecot to spawn another process. If set to 0, @code{default-client-limit} is | |
306 | used instead.") | |
d8c18af8 AW |
307 | (service-count |
308 | (non-negative-integer 1) | |
309 | "Number of connections to handle before starting a new process. | |
310 | Typically the only useful values are 0 (unlimited) or 1. 1 is more | |
311 | secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.") | |
be8dd4a5 CL |
312 | (process-limit |
313 | (non-negative-integer 0) | |
314 | "Maximum number of processes that can exist for this service. If set to 0, | |
315 | @code{default-process-limit} is used instead.") | |
d8c18af8 AW |
316 | (process-min-avail |
317 | (non-negative-integer 0) | |
318 | "Number of processes to always keep waiting for more connections.") | |
319 | ;; FIXME: Need to be able to take the default for this value from other | |
320 | ;; parts of the config. | |
321 | (vsz-limit | |
322 | (non-negative-integer #e256e6) | |
323 | "If you set @samp{service-count 0}, you probably need to grow | |
324 | this.")) | |
325 | ||
326 | (define (serialize-service-configuration field-name val) | |
327 | (format #t "service ~a {\n" (service-configuration-kind val)) | |
328 | (serialize-configuration val (cdr service-configuration-fields)) | |
329 | (format #t "}\n")) | |
330 | (define (service-configuration-list? val) | |
331 | (and (list? val) (and-map service-configuration? val))) | |
332 | (define (serialize-service-configuration-list field-name val) | |
333 | (for-each (lambda (val) | |
334 | (serialize-service-configuration field-name val)) | |
335 | val)) | |
336 | ||
337 | (define-configuration protocol-configuration | |
338 | (name | |
5305ed20 | 339 | (string (configuration-missing-field 'protocol 'name)) |
d8c18af8 AW |
340 | "The name of the protocol.") |
341 | (auth-socket-path | |
342 | (string "/var/run/dovecot/auth-userdb") | |
343 | "UNIX socket path to master authentication server to find users. | |
344 | This is used by imap (for shared users) and lda.") | |
345 | (mail-plugins | |
346 | (space-separated-string-list '("$mail_plugins")) | |
347 | "Space separated list of plugins to load.") | |
348 | (mail-max-userip-connections | |
349 | (non-negative-integer 10) | |
350 | "Maximum number of IMAP connections allowed for a user from each IP | |
351 | address. NOTE: The username is compared case-sensitively.")) | |
352 | ||
353 | (define (serialize-protocol-configuration field-name val) | |
354 | (format #t "protocol ~a {\n" (protocol-configuration-name val)) | |
355 | (serialize-configuration val (cdr protocol-configuration-fields)) | |
356 | (format #t "}\n")) | |
357 | (define (protocol-configuration-list? val) | |
358 | (and (list? val) (and-map protocol-configuration? val))) | |
359 | (define (serialize-protocol-configuration-list field-name val) | |
360 | (serialize-field 'protocols | |
361 | (string-join (map protocol-configuration-name val) " ")) | |
362 | (for-each (lambda (val) | |
363 | (serialize-protocol-configuration field-name val)) | |
364 | val)) | |
365 | ||
366 | (define-configuration plugin-configuration | |
367 | (entries | |
368 | (free-form-fields '()) | |
369 | "A list of key-value pairs that this dict should hold.")) | |
370 | ||
371 | (define (serialize-plugin-configuration field-name val) | |
372 | (format #t "plugin {\n") | |
373 | (serialize-configuration val plugin-configuration-fields) | |
374 | (format #t "}\n")) | |
375 | ||
376 | (define-configuration mailbox-configuration | |
377 | (name | |
378 | (string (error "mailbox name is required")) | |
379 | "Name for this mailbox.") | |
380 | ||
381 | (auto | |
382 | (string "no") | |
383 | "@samp{create} will automatically create this mailbox. | |
384 | @samp{subscribe} will both create and subscribe to the mailbox.") | |
385 | ||
386 | (special-use | |
387 | (space-separated-string-list '()) | |
388 | "List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154. | |
389 | Valid values are @code{\\All}, @code{\\Archive}, @code{\\Drafts}, | |
390 | @code{\\Flagged}, @code{\\Junk}, @code{\\Sent}, and @code{\\Trash}.")) | |
391 | ||
392 | (define (serialize-mailbox-configuration field-name val) | |
393 | (format #t "mailbox \"~a\" {\n" (mailbox-configuration-name val)) | |
394 | (serialize-configuration val (cdr mailbox-configuration-fields)) | |
395 | (format #t "}\n")) | |
396 | (define (mailbox-configuration-list? val) | |
397 | (and (list? val) (and-map mailbox-configuration? val))) | |
398 | (define (serialize-mailbox-configuration-list field-name val) | |
399 | (for-each (lambda (val) | |
400 | (serialize-mailbox-configuration field-name val)) | |
401 | val)) | |
402 | ||
403 | (define-configuration namespace-configuration | |
404 | (name | |
405 | (string (error "namespace name is required")) | |
406 | "Name for this namespace.") | |
407 | ||
408 | (type | |
409 | (string "private") | |
410 | "Namespace type: @samp{private}, @samp{shared} or @samp{public}.") | |
411 | ||
412 | (separator | |
413 | (string "") | |
414 | "Hierarchy separator to use. You should use the same separator for | |
415 | all namespaces or some clients get confused. @samp{/} is usually a good | |
416 | one. The default however depends on the underlying mail storage | |
417 | format.") | |
418 | ||
419 | (prefix | |
420 | (string "") | |
421 | "Prefix required to access this namespace. This needs to be | |
422 | different for all namespaces. For example @samp{Public/}.") | |
423 | ||
424 | (location | |
425 | (string "") | |
426 | "Physical location of the mailbox. This is in same format as | |
427 | mail_location, which is also the default for it.") | |
428 | ||
429 | (inbox? | |
430 | (boolean #f) | |
431 | "There can be only one INBOX, and this setting defines which | |
432 | namespace has it.") | |
433 | ||
434 | (hidden? | |
435 | (boolean #f) | |
436 | "If namespace is hidden, it's not advertised to clients via NAMESPACE | |
437 | extension. You'll most likely also want to set @samp{list? #f}. This is mostly | |
438 | useful when converting from another server with different namespaces | |
439 | which you want to deprecate but still keep working. For example you can | |
440 | create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/} | |
441 | and @samp{mail/}.") | |
442 | ||
443 | (list? | |
444 | (boolean #t) | |
445 | "Show the mailboxes under this namespace with LIST command. This | |
446 | makes the namespace visible for clients that don't support NAMESPACE | |
447 | extension. The special @code{children} value lists child mailboxes, but | |
448 | hides the namespace prefix.") | |
449 | ||
450 | (subscriptions? | |
451 | (boolean #t) | |
452 | "Namespace handles its own subscriptions. If set to @code{#f}, the | |
453 | parent namespace handles them. The empty prefix should always have this | |
454 | as @code{#t}.)") | |
455 | ||
456 | (mailboxes | |
457 | (mailbox-configuration-list '()) | |
458 | "List of predefined mailboxes in this namespace.")) | |
459 | ||
460 | (define (serialize-namespace-configuration field-name val) | |
461 | (format #t "namespace ~a {\n" (namespace-configuration-name val)) | |
462 | (serialize-configuration val (cdr namespace-configuration-fields)) | |
463 | (format #t "}\n")) | |
464 | (define (list-of-namespace-configuration? val) | |
465 | (and (list? val) (and-map namespace-configuration? val))) | |
466 | (define (serialize-list-of-namespace-configuration field-name val) | |
467 | (for-each (lambda (val) | |
468 | (serialize-namespace-configuration field-name val)) | |
469 | val)) | |
470 | ||
471 | (define-configuration dovecot-configuration | |
472 | (dovecot | |
473 | (package dovecot) | |
474 | "The dovecot package.") | |
475 | ||
476 | (listen | |
477 | (comma-separated-string-list '("*" "::")) | |
478 | "A list of IPs or hosts where to listen in for connections. @samp{*} | |
479 | listens in all IPv4 interfaces, @samp{::} listens in all IPv6 | |
480 | interfaces. If you want to specify non-default ports or anything more | |
481 | complex, customize the address and port fields of the | |
482 | @samp{inet-listener} of the specific services you are interested in.") | |
483 | ||
d8c18af8 AW |
484 | (dict |
485 | (dict-configuration (dict-configuration)) | |
486 | "Dict configuration, as created by the @code{dict-configuration} | |
487 | constructor.") | |
488 | ||
489 | (passdbs | |
490 | (passdb-configuration-list (list (passdb-configuration (driver "pam")))) | |
491 | "List of passdb configurations, each one created by the | |
492 | @code{passdb-configuration} constructor.") | |
493 | ||
494 | (userdbs | |
495 | (userdb-configuration-list (list (userdb-configuration (driver "passwd")))) | |
496 | "List of userdb configurations, each one created by the | |
497 | @code{userdb-configuration} constructor.") | |
498 | ||
499 | (plugin-configuration | |
500 | (plugin-configuration (plugin-configuration)) | |
501 | "Plug-in configuration, created by the @code{plugin-configuration} | |
502 | constructor.") | |
503 | ||
504 | (namespaces | |
505 | (list-of-namespace-configuration | |
506 | (list | |
507 | (namespace-configuration | |
508 | (name "inbox") | |
509 | (prefix "") | |
510 | (inbox? #t) | |
511 | (mailboxes | |
512 | (list | |
513 | (mailbox-configuration (name "Drafts") (special-use '("\\Drafts"))) | |
514 | (mailbox-configuration (name "Junk") (special-use '("\\Junk"))) | |
515 | (mailbox-configuration (name "Trash") (special-use '("\\Trash"))) | |
516 | (mailbox-configuration (name "Sent") (special-use '("\\Sent"))) | |
517 | (mailbox-configuration (name "Sent Messages") (special-use '("\\Sent"))) | |
518 | (mailbox-configuration (name "Drafts") (special-use '("\\Drafts")))))))) | |
519 | "List of namespaces. Each item in the list is created by the | |
520 | @code{namespace-configuration} constructor.") | |
521 | ||
522 | (base-dir | |
523 | (file-name "/var/run/dovecot/") | |
524 | "Base directory where to store runtime data.") | |
525 | ||
526 | (login-greeting | |
527 | (string "Dovecot ready.") | |
528 | "Greeting message for clients.") | |
529 | ||
530 | (login-trusted-networks | |
531 | (space-separated-string-list '()) | |
532 | "List of trusted network ranges. Connections from these IPs are | |
533 | allowed to override their IP addresses and ports (for logging and for | |
534 | authentication checks). @samp{disable-plaintext-auth} is also ignored | |
535 | for these networks. Typically you'd specify your IMAP proxy servers | |
536 | here.") | |
537 | ||
538 | (login-access-sockets | |
539 | (space-separated-string-list '()) | |
540 | "List of login access check sockets (e.g. tcpwrap).") | |
541 | ||
542 | (verbose-proctitle? | |
543 | (boolean #f) | |
544 | "Show more verbose process titles (in ps). Currently shows user name | |
545 | and IP address. Useful for seeing who are actually using the IMAP | |
546 | processes (e.g. shared mailboxes or if same uid is used for multiple | |
547 | accounts).") | |
548 | ||
549 | (shutdown-clients? | |
550 | (boolean #t) | |
551 | "Should all processes be killed when Dovecot master process shuts down. | |
552 | Setting this to @code{#f} means that Dovecot can be upgraded without | |
553 | forcing existing client connections to close (although that could also | |
554 | be a problem if the upgrade is e.g. because of a security fix).") | |
555 | ||
556 | (doveadm-worker-count | |
557 | (non-negative-integer 0) | |
558 | "If non-zero, run mail commands via this many connections to doveadm | |
559 | server, instead of running them directly in the same process.") | |
560 | ||
561 | (doveadm-socket-path | |
562 | (string "doveadm-server") | |
563 | "UNIX socket or host:port used for connecting to doveadm server.") | |
564 | ||
565 | (import-environment | |
566 | (space-separated-string-list '("TZ")) | |
567 | "List of environment variables that are preserved on Dovecot startup | |
568 | and passed down to all of its child processes. You can also give | |
569 | key=value pairs to always set specific settings.") | |
570 | ||
571 | ;;; Authentication processes | |
572 | ||
573 | (disable-plaintext-auth? | |
574 | (boolean #t) | |
575 | "Disable LOGIN command and all other plaintext authentications unless | |
576 | SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP | |
577 | matches the local IP (i.e. you're connecting from the same computer), | |
578 | the connection is considered secure and plaintext authentication is | |
579 | allowed. See also ssl=required setting.") | |
580 | ||
581 | (auth-cache-size | |
582 | (non-negative-integer 0) | |
583 | "Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled. | |
584 | Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set | |
585 | for caching to be used.") | |
586 | ||
587 | (auth-cache-ttl | |
588 | (string "1 hour") | |
589 | "Time to live for cached data. After TTL expires the cached record | |
590 | is no longer used, *except* if the main database lookup returns internal | |
591 | failure. We also try to handle password changes automatically: If | |
592 | user's previous authentication was successful, but this one wasn't, the | |
593 | cache isn't used. For now this works only with plaintext | |
594 | authentication.") | |
595 | ||
596 | (auth-cache-negative-ttl | |
597 | (string "1 hour") | |
598 | "TTL for negative hits (user not found, password mismatch). | |
599 | 0 disables caching them completely.") | |
600 | ||
601 | (auth-realms | |
602 | (space-separated-string-list '()) | |
603 | "List of realms for SASL authentication mechanisms that need them. | |
604 | You can leave it empty if you don't want to support multiple realms. | |
605 | Many clients simply use the first one listed here, so keep the default | |
606 | realm first.") | |
607 | ||
608 | (auth-default-realm | |
609 | (string "") | |
610 | "Default realm/domain to use if none was specified. This is used for | |
611 | both SASL realms and appending @@domain to username in plaintext | |
612 | logins.") | |
613 | ||
614 | (auth-username-chars | |
615 | (string | |
616 | "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@") | |
617 | "List of allowed characters in username. If the user-given username | |
618 | contains a character not listed in here, the login automatically fails. | |
619 | This is just an extra check to make sure user can't exploit any | |
620 | potential quote escaping vulnerabilities with SQL/LDAP databases. If | |
621 | you want to allow all characters, set this value to empty.") | |
622 | ||
623 | (auth-username-translation | |
624 | (string "") | |
625 | "Username character translations before it's looked up from | |
626 | databases. The value contains series of from -> to characters. For | |
627 | example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are | |
628 | translated to @samp{@@}.") | |
629 | ||
630 | (auth-username-format | |
631 | (string "%Lu") | |
632 | "Username formatting before it's looked up from databases. You can | |
633 | use the standard variables here, e.g. %Lu would lowercase the username, | |
634 | %n would drop away the domain if it was given, or @samp{%n-AT-%d} would | |
635 | change the @samp{@@} into @samp{-AT-}. This translation is done after | |
636 | @samp{auth-username-translation} changes.") | |
637 | ||
638 | (auth-master-user-separator | |
639 | (string "") | |
640 | "If you want to allow master users to log in by specifying the master | |
641 | username within the normal username string (i.e. not using SASL | |
642 | mechanism's support for it), you can specify the separator character | |
643 | here. The format is then <username><separator><master username>. | |
644 | UW-IMAP uses @samp{*} as the separator, so that could be a good | |
645 | choice.") | |
646 | ||
647 | (auth-anonymous-username | |
648 | (string "anonymous") | |
649 | "Username to use for users logging in with ANONYMOUS SASL | |
650 | mechanism.") | |
651 | ||
652 | (auth-worker-max-count | |
653 | (non-negative-integer 30) | |
654 | "Maximum number of dovecot-auth worker processes. They're used to | |
655 | execute blocking passdb and userdb queries (e.g. MySQL and PAM). | |
656 | They're automatically created and destroyed as needed.") | |
657 | ||
658 | (auth-gssapi-hostname | |
659 | (string "") | |
660 | "Host name to use in GSSAPI principal names. The default is to use | |
661 | the name returned by gethostname(). Use @samp{$ALL} (with quotes) to | |
662 | allow all keytab entries.") | |
663 | ||
664 | (auth-krb5-keytab | |
665 | (string "") | |
666 | "Kerberos keytab to use for the GSSAPI mechanism. Will use the | |
667 | system default (usually /etc/krb5.keytab) if not specified. You may | |
668 | need to change the auth service to run as root to be able to read this | |
669 | file.") | |
670 | ||
671 | (auth-use-winbind? | |
672 | (boolean #f) | |
673 | "Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon | |
674 | and @samp{ntlm-auth} helper. | |
675 | <doc/wiki/Authentication/Mechanisms/Winbind.txt>.") | |
676 | ||
677 | (auth-winbind-helper-path | |
678 | (file-name "/usr/bin/ntlm_auth") | |
679 | "Path for Samba's @samp{ntlm-auth} helper binary.") | |
680 | ||
681 | (auth-failure-delay | |
682 | (string "2 secs") | |
683 | "Time to delay before replying to failed authentications.") | |
684 | ||
685 | (auth-ssl-require-client-cert? | |
686 | (boolean #f) | |
687 | "Require a valid SSL client certificate or the authentication | |
688 | fails.") | |
689 | ||
690 | (auth-ssl-username-from-cert? | |
691 | (boolean #f) | |
692 | "Take the username from client's SSL certificate, using | |
693 | @code{X509_NAME_get_text_by_NID()} which returns the subject's DN's | |
694 | CommonName.") | |
695 | ||
696 | (auth-mechanisms | |
697 | (space-separated-string-list '("plain")) | |
698 | "List of wanted authentication mechanisms. Supported mechanisms are: | |
699 | @samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5}, | |
700 | @samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi}, | |
701 | @samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also | |
702 | @samp{disable-plaintext-auth} setting.") | |
703 | ||
704 | (director-servers | |
705 | (space-separated-string-list '()) | |
706 | "List of IPs or hostnames to all director servers, including ourself. | |
707 | Ports can be specified as ip:port. The default port is the same as what | |
708 | director service's @samp{inet-listener} is using.") | |
709 | ||
710 | (director-mail-servers | |
711 | (space-separated-string-list '()) | |
712 | "List of IPs or hostnames to all backend mail servers. Ranges are | |
713 | allowed too, like 10.0.0.10-10.0.0.30.") | |
714 | ||
715 | (director-user-expire | |
716 | (string "15 min") | |
717 | "How long to redirect users to a specific server after it no longer | |
718 | has any connections.") | |
719 | ||
d8c18af8 AW |
720 | (director-username-hash |
721 | (string "%Lu") | |
722 | "How the username is translated before being hashed. Useful values | |
723 | include %Ln if user can log in with or without @@domain, %Ld if mailboxes | |
724 | are shared within domain.") | |
725 | ||
726 | ;;; Log destination. | |
727 | ||
728 | (log-path | |
729 | (string "syslog") | |
730 | "Log file to use for error messages. @samp{syslog} logs to syslog, | |
731 | @samp{/dev/stderr} logs to stderr.") | |
732 | ||
733 | (info-log-path | |
734 | (string "") | |
735 | "Log file to use for informational messages. Defaults to | |
736 | @samp{log-path}.") | |
737 | ||
738 | (debug-log-path | |
739 | (string "") | |
740 | "Log file to use for debug messages. Defaults to | |
741 | @samp{info-log-path}.") | |
742 | ||
743 | (syslog-facility | |
744 | (string "mail") | |
745 | "Syslog facility to use if you're logging to syslog. Usually if you | |
746 | don't want to use @samp{mail}, you'll use local0..local7. Also other | |
747 | standard facilities are supported.") | |
748 | ||
749 | (auth-verbose? | |
750 | (boolean #f) | |
751 | "Log unsuccessful authentication attempts and the reasons why they | |
752 | failed.") | |
753 | ||
5b3d3cf7 CB |
754 | (auth-verbose-passwords |
755 | (string "no") | |
d8c18af8 AW |
756 | "In case of password mismatches, log the attempted password. Valid |
757 | values are no, plain and sha1. sha1 can be useful for detecting brute | |
758 | force password attempts vs. user simply trying the same password over | |
759 | and over again. You can also truncate the value to n chars by appending | |
760 | \":n\" (e.g. sha1:6).") | |
761 | ||
762 | (auth-debug? | |
763 | (boolean #f) | |
764 | "Even more verbose logging for debugging purposes. Shows for example | |
765 | SQL queries.") | |
766 | ||
767 | (auth-debug-passwords? | |
768 | (boolean #f) | |
769 | "In case of password mismatches, log the passwords and used scheme so | |
770 | the problem can be debugged. Enabling this also enables | |
771 | @samp{auth-debug}.") | |
772 | ||
773 | (mail-debug? | |
774 | (boolean #f) | |
775 | "Enable mail process debugging. This can help you figure out why | |
776 | Dovecot isn't finding your mails.") | |
777 | ||
778 | (verbose-ssl? | |
779 | (boolean #f) | |
780 | "Show protocol level SSL errors.") | |
781 | ||
782 | (log-timestamp | |
783 | (string "\"%b %d %H:%M:%S \"") | |
784 | "Prefix for each line written to log file. % codes are in | |
785 | strftime(3) format.") | |
786 | ||
787 | (login-log-format-elements | |
788 | (space-separated-string-list | |
789 | '("user=<%u>" "method=%m" "rip=%r" "lip=%l" "mpid=%e" "%c")) | |
790 | "List of elements we want to log. The elements which have a | |
791 | non-empty variable value are joined together to form a comma-separated | |
792 | string.") | |
793 | ||
794 | (login-log-format | |
795 | (string "%$: %s") | |
796 | "Login log format. %s contains @samp{login-log-format-elements} | |
797 | string, %$ contains the data we want to log.") | |
798 | ||
799 | (mail-log-prefix | |
28c03b45 | 800 | (string "\"%s(%u)<%{pid}><%{session}>: \"") |
d8c18af8 AW |
801 | "Log prefix for mail processes. See doc/wiki/Variables.txt for list |
802 | of possible variables you can use.") | |
803 | ||
804 | (deliver-log-format | |
805 | (string "msgid=%m: %$") | |
806 | "Format to use for logging mail deliveries. You can use variables: | |
807 | @table @code | |
808 | @item %$ | |
809 | Delivery status message (e.g. @samp{saved to INBOX}) | |
810 | @item %m | |
811 | Message-ID | |
812 | @item %s | |
813 | Subject | |
814 | @item %f | |
815 | From address | |
816 | @item %p | |
817 | Physical size | |
818 | @item %w | |
819 | Virtual size. | |
820 | @end table") | |
821 | ||
822 | ;;; Mailbox locations and namespaces | |
823 | ||
824 | (mail-location | |
825 | (string "") | |
826 | "Location for users' mailboxes. The default is empty, which means | |
827 | that Dovecot tries to find the mailboxes automatically. This won't work | |
828 | if the user doesn't yet have any mail, so you should explicitly tell | |
829 | Dovecot the full location. | |
830 | ||
831 | If you're using mbox, giving a path to the INBOX | |
832 | file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot | |
833 | where the other mailboxes are kept. This is called the \"root mail | |
834 | directory\", and it must be the first path given in the | |
835 | @samp{mail-location} setting. | |
836 | ||
837 | There are a few special variables you can use, eg.: | |
838 | ||
839 | @table @samp | |
840 | @item %u | |
841 | username | |
842 | @item %n | |
843 | user part in user@@domain, same as %u if there's no domain | |
844 | @item %d | |
845 | domain part in user@@domain, empty if there's no domain | |
846 | @item %h | |
847 | home director | |
848 | @end table | |
849 | ||
850 | See doc/wiki/Variables.txt for full list. Some examples: | |
851 | @table @samp | |
852 | @item maildir:~/Maildir | |
853 | @item mbox:~/mail:INBOX=/var/mail/%u | |
854 | @item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/% | |
855 | @end table") | |
856 | ||
857 | (mail-uid | |
858 | (string "") | |
859 | "System user and group used to access mails. If you use multiple, | |
860 | userdb can override these by returning uid or gid fields. You can use | |
861 | either numbers or names. <doc/wiki/UserIds.txt>.") | |
862 | ||
863 | (mail-gid | |
864 | (string "") | |
865 | "") | |
866 | ||
867 | (mail-privileged-group | |
868 | (string "") | |
869 | "Group to enable temporarily for privileged operations. Currently | |
870 | this is used only with INBOX when either its initial creation or | |
871 | dotlocking fails. Typically this is set to \"mail\" to give access to | |
872 | /var/mail.") | |
873 | ||
874 | (mail-access-groups | |
875 | (string "") | |
876 | "Grant access to these supplementary groups for mail processes. | |
877 | Typically these are used to set up access to shared mailboxes. Note | |
878 | that it may be dangerous to set these if users can create | |
879 | symlinks (e.g. if \"mail\" group is set here, ln -s /var/mail ~/mail/var | |
880 | could allow a user to delete others' mailboxes, or ln -s | |
881 | /secret/shared/box ~/mail/mybox would allow reading it).") | |
882 | ||
883 | (mail-full-filesystem-access? | |
884 | (boolean #f) | |
8f65585b | 885 | "Allow full file system access to clients. There's no access checks |
d8c18af8 AW |
886 | other than what the operating system does for the active UID/GID. It |
887 | works with both maildir and mboxes, allowing you to prefix mailboxes | |
888 | names with e.g. /path/ or ~user/.") | |
889 | ||
890 | ;;; Mail processes | |
891 | ||
892 | (mmap-disable? | |
893 | (boolean #f) | |
894 | "Don't use mmap() at all. This is required if you store indexes to | |
8f65585b | 895 | shared file systems (NFS or clustered file system).") |
d8c18af8 AW |
896 | |
897 | (dotlock-use-excl? | |
898 | (boolean #t) | |
899 | "Rely on @samp{O_EXCL} to work when creating dotlock files. NFS | |
900 | supports @samp{O_EXCL} since version 3, so this should be safe to use | |
901 | nowadays by default.") | |
902 | ||
903 | (mail-fsync | |
904 | (string "optimized") | |
905 | "When to use fsync() or fdatasync() calls: | |
906 | @table @code | |
907 | @item optimized | |
908 | Whenever necessary to avoid losing important data | |
909 | @item always | |
910 | Useful with e.g. NFS when write()s are delayed | |
911 | @item never | |
912 | Never use it (best performance, but crashes can lose data). | |
913 | @end table") | |
914 | ||
915 | (mail-nfs-storage? | |
916 | (boolean #f) | |
917 | "Mail storage exists in NFS. Set this to yes to make Dovecot flush | |
918 | NFS caches whenever needed. If you're using only a single mail server | |
919 | this isn't needed.") | |
920 | ||
921 | (mail-nfs-index? | |
922 | (boolean #f) | |
923 | "Mail index files also exist in NFS. Setting this to yes requires | |
924 | @samp{mmap-disable? #t} and @samp{fsync-disable? #f}.") | |
925 | ||
926 | (lock-method | |
927 | (string "fcntl") | |
928 | "Locking method for index files. Alternatives are fcntl, flock and | |
929 | dotlock. Dotlocking uses some tricks which may create more disk I/O | |
930 | than other locking methods. NFS users: flock doesn't work, remember to | |
931 | change @samp{mmap-disable}.") | |
932 | ||
933 | (mail-temp-dir | |
934 | (file-name "/tmp") | |
935 | "Directory in which LDA/LMTP temporarily stores incoming mails >128 | |
936 | kB.") | |
937 | ||
938 | (first-valid-uid | |
939 | (non-negative-integer 500) | |
940 | "Valid UID range for users. This is mostly to make sure that users can't | |
941 | log in as daemons or other system users. Note that denying root logins is | |
942 | hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid} | |
943 | is set to 0.") | |
944 | ||
945 | (last-valid-uid | |
946 | (non-negative-integer 0) | |
947 | "") | |
948 | ||
949 | (first-valid-gid | |
950 | (non-negative-integer 1) | |
951 | "Valid GID range for users. Users having non-valid GID as primary group ID | |
952 | aren't allowed to log in. If user belongs to supplementary groups with | |
953 | non-valid GIDs, those groups are not set.") | |
954 | ||
955 | (last-valid-gid | |
956 | (non-negative-integer 0) | |
957 | "") | |
958 | ||
959 | (mail-max-keyword-length | |
960 | (non-negative-integer 50) | |
961 | "Maximum allowed length for mail keyword name. It's only forced when | |
962 | trying to create new keywords.") | |
963 | ||
964 | (valid-chroot-dirs | |
965 | (colon-separated-file-name-list '()) | |
966 | "List of directories under which chrooting is allowed for mail | |
967 | processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar | |
968 | too). This setting doesn't affect @samp{login-chroot} | |
969 | @samp{mail-chroot} or auth chroot settings. If this setting is empty, | |
970 | \"/./\" in home dirs are ignored. WARNING: Never add directories here | |
971 | which local users can modify, that may lead to root exploit. Usually | |
972 | this should be done only if you don't allow shell access for users. | |
973 | <doc/wiki/Chrooting.txt>.") | |
974 | ||
975 | (mail-chroot | |
976 | (string "") | |
977 | "Default chroot directory for mail processes. This can be overridden | |
978 | for specific users in user database by giving /./ in user's home | |
979 | directory (e.g. /home/./user chroots into /home). Note that usually | |
980 | there is no real need to do chrooting, Dovecot doesn't allow users to | |
981 | access files outside their mail directory anyway. If your home | |
982 | directories are prefixed with the chroot directory, append \"/.\" to | |
983 | @samp{mail-chroot}. <doc/wiki/Chrooting.txt>.") | |
984 | ||
985 | (auth-socket-path | |
986 | (file-name "/var/run/dovecot/auth-userdb") | |
987 | "UNIX socket path to master authentication server to find users. | |
988 | This is used by imap (for shared users) and lda.") | |
989 | ||
990 | (mail-plugin-dir | |
bcfe0f0c AA |
991 | (file-name "/etc/dovecot/modules") |
992 | "Directory where to look up mail plugins. | |
993 | Defaults to @samp{\"/etc/dovecot/modules\"}, a union of all enabled mail | |
994 | plugins.") | |
d8c18af8 AW |
995 | |
996 | (mail-plugins | |
997 | (space-separated-string-list '()) | |
998 | "List of plugins to load for all services. Plugins specific to IMAP, | |
999 | LDA, etc. are added to this list in their own .conf files.") | |
1000 | ||
1001 | ||
1002 | (mail-cache-min-mail-count | |
1003 | (non-negative-integer 0) | |
1004 | "The minimum number of mails in a mailbox before updates are done to | |
1005 | cache file. This allows optimizing Dovecot's behavior to do less disk | |
1006 | writes at the cost of more disk reads.") | |
1007 | ||
1008 | (mailbox-idle-check-interval | |
1009 | (string "30 secs") | |
1010 | "When IDLE command is running, mailbox is checked once in a while to | |
1011 | see if there are any new mails or other changes. This setting defines | |
1012 | the minimum time to wait between those checks. Dovecot can also use | |
1013 | dnotify, inotify and kqueue to find out immediately when changes | |
1014 | occur.") | |
1015 | ||
1016 | (mail-save-crlf? | |
1017 | (boolean #f) | |
1018 | "Save mails with CR+LF instead of plain LF. This makes sending those | |
1019 | mails take less CPU, especially with sendfile() syscall with Linux and | |
1020 | FreeBSD. But it also creates a bit more disk I/O which may just make it | |
1021 | slower. Also note that if other software reads the mboxes/maildirs, | |
1022 | they may handle the extra CRs wrong and cause problems.") | |
1023 | ||
1024 | (maildir-stat-dirs? | |
1025 | (boolean #f) | |
1026 | "By default LIST command returns all entries in maildir beginning | |
1027 | with a dot. Enabling this option makes Dovecot return only entries | |
1028 | which are directories. This is done by stat()ing each entry, so it | |
1029 | causes more disk I/O. | |
1030 | (For systems setting struct @samp{dirent->d_type} this check is free | |
1031 | and it's done always regardless of this setting).") | |
1032 | ||
1033 | (maildir-copy-with-hardlinks? | |
1034 | (boolean #t) | |
1035 | "When copying a message, do it with hard links whenever possible. | |
1036 | This makes the performance much better, and it's unlikely to have any | |
1037 | side effects.") | |
1038 | ||
1039 | (maildir-very-dirty-syncs? | |
1040 | (boolean #f) | |
1041 | "Assume Dovecot is the only MUA accessing Maildir: Scan cur/ | |
1042 | directory only when its mtime changes unexpectedly or when we can't find | |
1043 | the mail otherwise.") | |
1044 | ||
1045 | (mbox-read-locks | |
1046 | (space-separated-string-list '("fcntl")) | |
1047 | "Which locking methods to use for locking mbox. There are four | |
1048 | available: | |
1049 | ||
1050 | @table @code | |
1051 | @item dotlock | |
1052 | Create <mailbox>.lock file. This is the oldest and most NFS-safe | |
1053 | solution. If you want to use /var/mail/ like directory, the users will | |
1054 | need write access to that directory. | |
1055 | @item dotlock-try | |
1056 | Same as dotlock, but if it fails because of permissions or because there | |
1057 | isn't enough disk space, just skip it. | |
1058 | @item fcntl | |
1059 | Use this if possible. Works with NFS too if lockd is used. | |
1060 | @item flock | |
1061 | May not exist in all systems. Doesn't work with NFS. | |
1062 | @item lockf | |
1063 | May not exist in all systems. Doesn't work with NFS. | |
1064 | @end table | |
1065 | ||
1066 | You can use multiple locking methods; if you do the order they're declared | |
1067 | in is important to avoid deadlocks if other MTAs/MUAs are using multiple | |
1068 | locking methods as well. Some operating systems don't allow using some of | |
1069 | them simultaneously.") | |
1070 | ||
1071 | (mbox-write-locks | |
1072 | (space-separated-string-list '("dotlock" "fcntl")) | |
1073 | "") | |
1074 | ||
1075 | (mbox-lock-timeout | |
1076 | (string "5 mins") | |
1077 | "Maximum time to wait for lock (all of them) before aborting.") | |
1078 | ||
1079 | (mbox-dotlock-change-timeout | |
1080 | (string "2 mins") | |
1081 | "If dotlock exists but the mailbox isn't modified in any way, | |
1082 | override the lock file after this much time.") | |
1083 | ||
1084 | (mbox-dirty-syncs? | |
1085 | (boolean #t) | |
1086 | "When mbox changes unexpectedly we have to fully read it to find out | |
1087 | what changed. If the mbox is large this can take a long time. Since | |
1088 | the change is usually just a newly appended mail, it'd be faster to | |
1089 | simply read the new mails. If this setting is enabled, Dovecot does | |
1090 | this but still safely fallbacks to re-reading the whole mbox file | |
1091 | whenever something in mbox isn't how it's expected to be. The only real | |
1092 | downside to this setting is that if some other MUA changes message | |
1093 | flags, Dovecot doesn't notice it immediately. Note that a full sync is | |
1094 | done with SELECT, EXAMINE, EXPUNGE and CHECK commands.") | |
1095 | ||
1096 | (mbox-very-dirty-syncs? | |
1097 | (boolean #f) | |
1098 | "Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT, | |
1099 | EXAMINE, EXPUNGE or CHECK commands. If this is set, | |
1100 | @samp{mbox-dirty-syncs} is ignored.") | |
1101 | ||
1102 | (mbox-lazy-writes? | |
1103 | (boolean #t) | |
1104 | "Delay writing mbox headers until doing a full write sync (EXPUNGE | |
1105 | and CHECK commands and when closing the mailbox). This is especially | |
1106 | useful for POP3 where clients often delete all mails. The downside is | |
1107 | that our changes aren't immediately visible to other MUAs.") | |
1108 | ||
1109 | (mbox-min-index-size | |
1110 | (non-negative-integer 0) | |
1111 | "If mbox size is smaller than this (e.g. 100k), don't write index | |
1112 | files. If an index file already exists it's still read, just not | |
1113 | updated.") | |
1114 | ||
1115 | (mdbox-rotate-size | |
28c03b45 | 1116 | (non-negative-integer #e10e6) |
d8c18af8 AW |
1117 | "Maximum dbox file size until it's rotated.") |
1118 | ||
1119 | (mdbox-rotate-interval | |
1120 | (string "1d") | |
1121 | "Maximum dbox file age until it's rotated. Typically in days. Day | |
1122 | begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check | |
1123 | disabled.") | |
1124 | ||
1125 | (mdbox-preallocate-space? | |
1126 | (boolean #f) | |
1127 | "When creating new mdbox files, immediately preallocate their size to | |
1128 | @samp{mdbox-rotate-size}. This setting currently works only in Linux | |
8f65585b | 1129 | with some file systems (ext4, xfs).") |
d8c18af8 AW |
1130 | |
1131 | (mail-attachment-dir | |
1132 | (string "") | |
1133 | "sdbox and mdbox support saving mail attachments to external files, | |
1134 | which also allows single instance storage for them. Other backends | |
1135 | don't support this for now. | |
1136 | ||
1137 | WARNING: This feature hasn't been tested much yet. Use at your own risk. | |
1138 | ||
1139 | Directory root where to store mail attachments. Disabled, if empty.") | |
1140 | ||
1141 | (mail-attachment-min-size | |
1142 | (non-negative-integer #e128e3) | |
1143 | "Attachments smaller than this aren't saved externally. It's also | |
1144 | possible to write a plugin to disable saving specific attachments | |
1145 | externally.") | |
1146 | ||
1147 | (mail-attachment-fs | |
1148 | (string "sis posix") | |
8f65585b | 1149 | "File system backend to use for saving attachments: |
d8c18af8 AW |
1150 | @table @code |
1151 | @item posix | |
1152 | No SiS done by Dovecot (but this might help FS's own deduplication) | |
1153 | @item sis posix | |
1154 | SiS with immediate byte-by-byte comparison during saving | |
1155 | @item sis-queue posix | |
1156 | SiS with delayed comparison and deduplication. | |
1157 | @end table") | |
1158 | ||
1159 | (mail-attachment-hash | |
1160 | (string "%{sha1}") | |
1161 | "Hash format to use in attachment filenames. You can add any text and | |
1162 | variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}}, | |
1163 | @code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be | |
1164 | truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.") | |
1165 | ||
1166 | (default-process-limit | |
1167 | (non-negative-integer 100) | |
1168 | "") | |
1169 | ||
1170 | (default-client-limit | |
1171 | (non-negative-integer 1000) | |
1172 | "") | |
1173 | ||
1174 | (default-vsz-limit | |
1175 | (non-negative-integer #e256e6) | |
1176 | "Default VSZ (virtual memory size) limit for service processes. | |
1177 | This is mainly intended to catch and kill processes that leak memory | |
1178 | before they eat up everything.") | |
1179 | ||
1180 | (default-login-user | |
1181 | (string "dovenull") | |
1182 | "Login user is internally used by login processes. This is the most | |
1183 | untrusted user in Dovecot system. It shouldn't have access to anything | |
1184 | at all.") | |
1185 | ||
1186 | (default-internal-user | |
1187 | (string "dovecot") | |
1188 | "Internal user is used by unprivileged processes. It should be | |
1189 | separate from login user, so that login processes can't disturb other | |
1190 | processes.") | |
1191 | ||
1192 | (ssl? | |
1193 | (string "required") | |
1194 | "SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.") | |
1195 | ||
1196 | (ssl-cert | |
1197 | (string "</etc/dovecot/default.pem") | |
1198 | "PEM encoded X.509 SSL/TLS certificate (public key).") | |
1199 | ||
1200 | (ssl-key | |
1201 | (string "</etc/dovecot/private/default.pem") | |
1202 | "PEM encoded SSL/TLS private key. The key is opened before | |
1203 | dropping root privileges, so keep the key file unreadable by anyone but | |
1204 | root.") | |
1205 | ||
1206 | (ssl-key-password | |
1207 | (string "") | |
1208 | "If key file is password protected, give the password here. | |
1209 | Alternatively give it when starting dovecot with -p parameter. Since | |
1210 | this file is often world-readable, you may want to place this setting | |
1211 | instead to a different.") | |
1212 | ||
1213 | (ssl-ca | |
1214 | (string "") | |
1215 | "PEM encoded trusted certificate authority. Set this only if you | |
1216 | intend to use @samp{ssl-verify-client-cert? #t}. The file should | |
1217 | contain the CA certificate(s) followed by the matching | |
1218 | CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).") | |
1219 | (ssl-require-crl? | |
1220 | (boolean #t) | |
1221 | "Require that CRL check succeeds for client certificates.") | |
1222 | (ssl-verify-client-cert? | |
1223 | (boolean #f) | |
1224 | "Request client to send a certificate. If you also want to require | |
1225 | it, set @samp{auth-ssl-require-client-cert? #t} in auth section.") | |
1226 | ||
1227 | (ssl-cert-username-field | |
1228 | (string "commonName") | |
1229 | "Which field from certificate to use for username. commonName and | |
1230 | x500UniqueIdentifier are the usual choices. You'll also need to set | |
1231 | @samp{auth-ssl-username-from-cert? #t}.") | |
1232 | ||
28c03b45 TGR |
1233 | (ssl-min-protocol |
1234 | (string "TLSv1") | |
1235 | "Minimum SSL protocol version to accept.") | |
d8c18af8 AW |
1236 | |
1237 | (ssl-cipher-list | |
28c03b45 | 1238 | (string "ALL:!kRSA:!SRP:!kDHd:!DSS:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK:!RC4:!ADH:!LOW@STRENGTH") |
d8c18af8 AW |
1239 | "SSL ciphers to use.") |
1240 | ||
1241 | (ssl-crypto-device | |
1242 | (string "") | |
1243 | "SSL crypto device to use, for valid values run \"openssl engine\".") | |
1244 | ||
1245 | (postmaster-address | |
66329c23 | 1246 | (string "postmaster@%d") |
d8c18af8 AW |
1247 | "Address to use when sending rejection mails. |
1248 | Default is postmaster@@<your domain>. %d expands to recipient domain.") | |
1249 | ||
1250 | (hostname | |
1251 | (string "") | |
1252 | "Hostname to use in various parts of sent mails (e.g. in Message-Id) | |
1253 | and in LMTP replies. Default is the system's real hostname@@domain.") | |
1254 | ||
1255 | (quota-full-tempfail? | |
1256 | (boolean #f) | |
1257 | "If user is over quota, return with temporary failure instead of | |
1258 | bouncing the mail.") | |
1259 | ||
1260 | (sendmail-path | |
1261 | (file-name "/usr/sbin/sendmail") | |
1262 | "Binary to use for sending mails.") | |
1263 | ||
1264 | (submission-host | |
1265 | (string "") | |
1266 | "If non-empty, send mails via this SMTP host[:port] instead of | |
1267 | sendmail.") | |
1268 | ||
1269 | (rejection-subject | |
1270 | (string "Rejected: %s") | |
1271 | "Subject: header to use for rejection mails. You can use the same | |
1272 | variables as for @samp{rejection-reason} below.") | |
1273 | ||
1274 | (rejection-reason | |
1275 | (string "Your message to <%t> was automatically rejected:%n%r") | |
1276 | "Human readable error message for rejection mails. You can use | |
1277 | variables: | |
1278 | ||
1279 | @table @code | |
1280 | @item %n | |
1281 | CRLF | |
1282 | @item %r | |
1283 | reason | |
1284 | @item %s | |
1285 | original subject | |
1286 | @item %t | |
1287 | recipient | |
1288 | @end table") | |
1289 | ||
1290 | (recipient-delimiter | |
1291 | (string "+") | |
1292 | "Delimiter character between local-part and detail in email | |
1293 | address.") | |
1294 | ||
1295 | (lda-original-recipient-header | |
1296 | (string "") | |
1297 | "Header where the original recipient address (SMTP's RCPT TO: | |
1298 | address) is taken from if not available elsewhere. With dovecot-lda -a | |
1299 | parameter overrides this. A commonly used header for this is | |
1300 | X-Original-To.") | |
1301 | ||
1302 | (lda-mailbox-autocreate? | |
1303 | (boolean #f) | |
1304 | "Should saving a mail to a nonexistent mailbox automatically create | |
1305 | it?.") | |
1306 | ||
1307 | (lda-mailbox-autosubscribe? | |
1308 | (boolean #f) | |
1309 | "Should automatically created mailboxes be also automatically | |
1310 | subscribed?.") | |
1311 | ||
1312 | ||
1313 | (imap-max-line-length | |
1314 | (non-negative-integer #e64e3) | |
1315 | "Maximum IMAP command line length. Some clients generate very long | |
1316 | command lines with huge mailboxes, so you may need to raise this if you | |
1317 | get \"Too long argument\" or \"IMAP command line too large\" errors | |
1318 | often.") | |
1319 | ||
1320 | (imap-logout-format | |
28c03b45 | 1321 | (string "in=%i out=%o deleted=%{deleted} expunged=%{expunged} trashed=%{trashed} hdr_count=%{fetch_hdr_count} hdr_bytes=%{fetch_hdr_bytes} body_count=%{fetch_body_count} body_bytes=%{fetch_body_bytes}") |
d8c18af8 AW |
1322 | "IMAP logout format string: |
1323 | @table @code | |
1324 | @item %i | |
1325 | total number of bytes read from client | |
1326 | @item %o | |
1327 | total number of bytes sent to client. | |
28c03b45 TGR |
1328 | @end table |
1329 | See @file{doc/wiki/Variables.txt} for a list of all the variables you can use.") | |
d8c18af8 AW |
1330 | |
1331 | (imap-capability | |
1332 | (string "") | |
1333 | "Override the IMAP CAPABILITY response. If the value begins with '+', | |
1334 | add the given capabilities on top of the defaults (e.g. +XFOO XBAR).") | |
1335 | ||
1336 | (imap-idle-notify-interval | |
1337 | (string "2 mins") | |
1338 | "How long to wait between \"OK Still here\" notifications when client | |
1339 | is IDLEing.") | |
1340 | ||
1341 | (imap-id-send | |
1342 | (string "") | |
1343 | "ID field names and values to send to clients. Using * as the value | |
1344 | makes Dovecot use the default value. The following fields have default | |
1345 | values currently: name, version, os, os-version, support-url, | |
1346 | support-email.") | |
1347 | ||
1348 | (imap-id-log | |
1349 | (string "") | |
1350 | "ID fields sent by client to log. * means everything.") | |
1351 | ||
1352 | (imap-client-workarounds | |
1353 | (space-separated-string-list '()) | |
1354 | "Workarounds for various client bugs: | |
1355 | ||
1356 | @table @code | |
1357 | @item delay-newmail | |
1358 | Send EXISTS/RECENT new mail notifications only when replying to NOOP and | |
1359 | CHECK commands. Some clients ignore them otherwise, for example OSX | |
1360 | Mail (<v2.1). Outlook Express breaks more badly though, without this it | |
1361 | may show user \"Message no longer in server\" errors. Note that OE6 | |
1362 | still breaks even with this workaround if synchronization is set to | |
1363 | \"Headers Only\". | |
1364 | ||
1365 | @item tb-extra-mailbox-sep | |
1366 | Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and | |
1367 | adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to | |
1368 | ignore the extra @samp{/} instead of treating it as invalid mailbox name. | |
1369 | ||
1370 | @item tb-lsub-flags | |
1371 | Show \\Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox). | |
1372 | This makes Thunderbird realize they aren't selectable and show them | |
1373 | greyed out, instead of only later giving \"not selectable\" popup error. | |
1374 | @end table | |
1375 | ") | |
1376 | ||
1377 | (imap-urlauth-host | |
1378 | (string "") | |
22470c88 AA |
1379 | "Host allowed in URLAUTH URLs sent by client. \"*\" allows all.") |
1380 | ||
1381 | (protocols | |
1382 | (protocol-configuration-list | |
1383 | (list (protocol-configuration | |
1384 | (name "imap")))) | |
1385 | "List of protocols we want to serve. Available protocols include | |
1386 | @samp{imap}, @samp{pop3}, and @samp{lmtp}.") | |
1387 | ||
1388 | (services | |
1389 | (service-configuration-list | |
1390 | (list | |
1391 | (service-configuration | |
1392 | (kind "imap-login") | |
1393 | (client-limit 0) | |
1394 | (process-limit 0) | |
1395 | (listeners | |
1396 | (list | |
1397 | (inet-listener-configuration (protocol "imap") (port 143) (ssl? #f)) | |
1398 | (inet-listener-configuration (protocol "imaps") (port 993) (ssl? #t))))) | |
1399 | (service-configuration | |
1400 | (kind "pop3-login") | |
1401 | (listeners | |
1402 | (list | |
1403 | (inet-listener-configuration (protocol "pop3") (port 110) (ssl? #f)) | |
1404 | (inet-listener-configuration (protocol "pop3s") (port 995) (ssl? #t))))) | |
1405 | (service-configuration | |
1406 | (kind "lmtp") | |
1407 | (client-limit 1) | |
1408 | (process-limit 0) | |
1409 | (listeners | |
1410 | (list (unix-listener-configuration (path "lmtp") (mode "0666"))))) | |
1411 | (service-configuration | |
1412 | (kind "imap") | |
1413 | (client-limit 1) | |
1414 | (process-limit 1024)) | |
1415 | (service-configuration | |
1416 | (kind "pop3") | |
1417 | (client-limit 1) | |
1418 | (process-limit 1024)) | |
1419 | (service-configuration | |
1420 | (kind "auth") | |
1421 | (service-count 0) | |
1422 | (client-limit 0) | |
1423 | (process-limit 1) | |
1424 | (listeners | |
1425 | (list (unix-listener-configuration (path "auth-userdb"))))) | |
1426 | (service-configuration | |
1427 | (kind "auth-worker") | |
1428 | (client-limit 1) | |
1429 | (process-limit 0)) | |
1430 | (service-configuration | |
1431 | (kind "dict") | |
1432 | (client-limit 1) | |
1433 | (process-limit 0) | |
1434 | (listeners (list (unix-listener-configuration (path "dict"))))))) | |
1435 | "List of services to enable. Available services include @samp{imap}, | |
1436 | @samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and | |
1437 | @samp{lmtp}.")) | |
d8c18af8 AW |
1438 | |
1439 | (define-configuration opaque-dovecot-configuration | |
1440 | (dovecot | |
1441 | (package dovecot) | |
1442 | "The dovecot package.") | |
1443 | ||
1444 | (string | |
5305ed20 JL |
1445 | (string (configuration-missing-field 'opaque-dovecot-configuration |
1446 | 'string)) | |
d8c18af8 AW |
1447 | "The contents of the @code{dovecot.conf} to use.")) |
1448 | ||
1449 | (define %dovecot-accounts | |
1450 | ;; Account and group for the Dovecot daemon. | |
1451 | (list (user-group (name "dovecot") (system? #t)) | |
1452 | (user-account | |
1453 | (name "dovecot") | |
1454 | (group "dovecot") | |
1455 | (system? #t) | |
1456 | (comment "Dovecot daemon user") | |
1457 | (home-directory "/var/empty") | |
9e41130b | 1458 | (shell (file-append shadow "/sbin/nologin"))) |
d8c18af8 AW |
1459 | |
1460 | (user-group (name "dovenull") (system? #t)) | |
1461 | (user-account | |
1462 | (name "dovenull") | |
1463 | (group "dovenull") | |
1464 | (system? #t) | |
1465 | (comment "Dovecot daemon login user") | |
1466 | (home-directory "/var/empty") | |
9e41130b | 1467 | (shell (file-append shadow "/sbin/nologin"))))) |
d8c18af8 | 1468 | |
6310dff1 | 1469 | (define (%dovecot-activation config) |
d8c18af8 | 1470 | ;; Activation gexp. |
6310dff1 OP |
1471 | (let ((config-str |
1472 | (cond | |
1473 | ((opaque-dovecot-configuration? config) | |
1474 | (opaque-dovecot-configuration-string config)) | |
1475 | (else | |
1476 | (with-output-to-string | |
1477 | (lambda () | |
1478 | (serialize-configuration config | |
1479 | dovecot-configuration-fields))))))) | |
1480 | #~(begin | |
1481 | (use-modules (guix build utils)) | |
1482 | (define (mkdir-p/perms directory owner perms) | |
1483 | (mkdir-p directory) | |
1484 | (chown "/var/run/dovecot" (passwd:uid owner) (passwd:gid owner)) | |
1485 | (chmod directory perms)) | |
1486 | (define (build-subject parameters) | |
1487 | (string-concatenate | |
1488 | (map (lambda (pair) | |
1489 | (let ((k (car pair)) (v (cdr pair))) | |
1490 | (define (escape-char str chr) | |
1491 | (string-join (string-split str chr) (string #\\ chr))) | |
1492 | (string-append "/" k "=" | |
1493 | (escape-char (escape-char v #\=) #\/)))) | |
1494 | (filter (lambda (pair) (cdr pair)) parameters)))) | |
1495 | (define* (create-self-signed-certificate-if-absent | |
1496 | #:key private-key public-key (owner (getpwnam "root")) | |
1497 | (common-name (gethostname)) | |
59e80445 | 1498 | (organization-name "Guix") |
6310dff1 OP |
1499 | (organization-unit-name "Default Self-Signed Certificate") |
1500 | (subject-parameters `(("CN" . ,common-name) | |
1501 | ("O" . ,organization-name) | |
1502 | ("OU" . ,organization-unit-name))) | |
1503 | (subject (build-subject subject-parameters))) | |
1504 | ;; Note that by default, OpenSSL outputs keys in PEM format. This | |
1505 | ;; is what we want. | |
1506 | (unless (file-exists? private-key) | |
1507 | (cond | |
1508 | ((zero? (system* (string-append #$openssl "/bin/openssl") | |
1509 | "genrsa" "-out" private-key "2048")) | |
1510 | (chown private-key (passwd:uid owner) (passwd:gid owner)) | |
1511 | (chmod private-key #o400)) | |
1512 | (else | |
1513 | (format (current-error-port) | |
1514 | "Failed to create private key at ~a.\n" private-key)))) | |
1515 | (unless (file-exists? public-key) | |
1516 | (cond | |
1517 | ((zero? (system* (string-append #$openssl "/bin/openssl") | |
1518 | "req" "-new" "-x509" "-key" private-key | |
1519 | "-out" public-key "-days" "3650" | |
1520 | "-batch" "-subj" subject)) | |
1521 | (chown public-key (passwd:uid owner) (passwd:gid owner)) | |
1522 | (chmod public-key #o444)) | |
1523 | (else | |
1524 | (format (current-error-port) | |
1525 | "Failed to create public key at ~a.\n" public-key))))) | |
bcfe0f0c AA |
1526 | (let ((user (getpwnam "dovecot")) |
1527 | ;; This is Dovecot's term for the base directory for | |
1528 | ;; dynamically loadable modules. It supports only one. | |
1529 | (moduledir "/etc/dovecot/modules")) | |
6310dff1 OP |
1530 | (mkdir-p/perms "/var/run/dovecot" user #o755) |
1531 | (mkdir-p/perms "/var/lib/dovecot" user #o755) | |
1532 | (mkdir-p/perms "/etc/dovecot" user #o755) | |
1533 | (copy-file #$(plain-file "dovecot.conf" config-str) | |
1534 | "/etc/dovecot/dovecot.conf") | |
1535 | (mkdir-p/perms "/etc/dovecot/private" user #o700) | |
bcfe0f0c AA |
1536 | (unless (file-exists? moduledir) |
1537 | (symlink "/run/current-system/profile/lib/dovecot" moduledir)) | |
6310dff1 OP |
1538 | (create-self-signed-certificate-if-absent |
1539 | #:private-key "/etc/dovecot/private/default.pem" | |
1540 | #:public-key "/etc/dovecot/default.pem" | |
1541 | #:owner (getpwnam "root") | |
1542 | #:common-name (format #f "Dovecot service on ~a" (gethostname))))))) | |
d8c18af8 | 1543 | |
d4053c71 AK |
1544 | (define (dovecot-shepherd-service config) |
1545 | "Return a list of <shepherd-service> for CONFIG." | |
6310dff1 OP |
1546 | (let ((dovecot (if (opaque-dovecot-configuration? config) |
1547 | (opaque-dovecot-configuration-dovecot config) | |
1548 | (dovecot-configuration-dovecot config)))) | |
d4053c71 | 1549 | (list (shepherd-service |
d8c18af8 AW |
1550 | (documentation "Run the Dovecot POP3/IMAP mail server.") |
1551 | (provision '(dovecot)) | |
1552 | (requirement '(networking)) | |
1553 | (start #~(make-forkexec-constructor | |
1554 | (list (string-append #$dovecot "/sbin/dovecot") | |
6310dff1 | 1555 | "-F"))) |
b25ecfa2 LC |
1556 | (stop #~(lambda _ |
1557 | (invoke #$(file-append dovecot "/sbin/dovecot") | |
1558 | "stop") | |
1559 | #f)))))) | |
d8c18af8 AW |
1560 | |
1561 | (define %dovecot-pam-services | |
1562 | (list (unix-pam-service "dovecot"))) | |
1563 | ||
1564 | (define dovecot-service-type | |
1565 | (service-type (name 'dovecot) | |
1566 | (extensions | |
d4053c71 AK |
1567 | (list (service-extension shepherd-root-service-type |
1568 | dovecot-shepherd-service) | |
d8c18af8 AW |
1569 | (service-extension account-service-type |
1570 | (const %dovecot-accounts)) | |
1571 | (service-extension pam-root-service-type | |
1572 | (const %dovecot-pam-services)) | |
1573 | (service-extension activation-service-type | |
6310dff1 | 1574 | %dovecot-activation))))) |
d8c18af8 AW |
1575 | |
1576 | (define* (dovecot-service #:key (config (dovecot-configuration))) | |
1577 | "Return a service that runs @command{dovecot}, a mail server that can run | |
1578 | POP3, IMAP, and LMTP. @var{config} should be a configuration object created | |
1579 | by @code{dovecot-configuration}. @var{config} may also be created by | |
1580 | @code{opaque-dovecot-configuration}, which allows specification of the | |
1581 | @code{dovecot.conf} as a string." | |
1582 | (validate-configuration config | |
1583 | (if (opaque-dovecot-configuration? config) | |
1584 | opaque-dovecot-configuration-fields | |
1585 | dovecot-configuration-fields)) | |
1586 | (service dovecot-service-type config)) | |
1587 | ||
1588 | ;; A little helper to make it easier to document all those fields. | |
5305ed20 JL |
1589 | (define (generate-dovecot-documentation) |
1590 | (generate-documentation | |
d8c18af8 AW |
1591 | `((dovecot-configuration |
1592 | ,dovecot-configuration-fields | |
1593 | (dict dict-configuration) | |
1594 | (namespaces namespace-configuration) | |
1595 | (plugin plugin-configuration) | |
1596 | (passdbs passdb-configuration) | |
1597 | (userdbs userdb-configuration) | |
1598 | (services service-configuration) | |
1599 | (protocols protocol-configuration)) | |
1600 | (dict-configuration ,dict-configuration-fields) | |
1601 | (plugin-configuration ,plugin-configuration-fields) | |
1602 | (passdb-configuration ,passdb-configuration-fields) | |
1603 | (userdb-configuration ,userdb-configuration-fields) | |
1604 | (unix-listener-configuration ,unix-listener-configuration-fields) | |
1605 | (fifo-listener-configuration ,fifo-listener-configuration-fields) | |
1606 | (inet-listener-configuration ,inet-listener-configuration-fields) | |
1607 | (namespace-configuration | |
1608 | ,namespace-configuration-fields | |
1609 | (mailboxes mailbox-configuration)) | |
1610 | (mailbox-configuration ,mailbox-configuration-fields) | |
1611 | (service-configuration | |
1612 | ,service-configuration-fields | |
1613 | (listeners unix-listener-configuration fifo-listener-configuration | |
1614 | inet-listener-configuration)) | |
5305ed20 JL |
1615 | (protocol-configuration ,protocol-configuration-fields)) |
1616 | 'dovecot-configuration)) | |
f88371e8 SB |
1617 | |
1618 | \f | |
1619 | ;;; | |
1620 | ;;; OpenSMTPD. | |
1621 | ;;; | |
1622 | ||
1623 | (define-record-type* <opensmtpd-configuration> | |
1624 | opensmtpd-configuration make-opensmtpd-configuration | |
1625 | opensmtpd-configuration? | |
1626 | (package opensmtpd-configuration-package | |
1627 | (default opensmtpd)) | |
1628 | (config-file opensmtpd-configuration-config-file | |
1629 | (default %default-opensmtpd-config-file))) | |
1630 | ||
1631 | (define %default-opensmtpd-config-file | |
1632 | (plain-file "smtpd.conf" " | |
1633 | listen on lo | |
c3f146e7 TGR |
1634 | |
1635 | action inbound mbox | |
1636 | match for local action inbound | |
1637 | ||
1638 | action outbound relay | |
1639 | match from local for any action outbound | |
f88371e8 SB |
1640 | ")) |
1641 | ||
1642 | (define opensmtpd-shepherd-service | |
1643 | (match-lambda | |
1644 | (($ <opensmtpd-configuration> package config-file) | |
1645 | (list (shepherd-service | |
1646 | (provision '(smtpd)) | |
1647 | (requirement '(loopback)) | |
1648 | (documentation "Run the OpenSMTPD daemon.") | |
1649 | (start (let ((smtpd (file-append package "/sbin/smtpd"))) | |
1650 | #~(make-forkexec-constructor | |
1651 | (list #$smtpd "-f" #$config-file) | |
1652 | #:pid-file "/var/run/smtpd.pid"))) | |
1653 | (stop #~(make-kill-destructor))))))) | |
1654 | ||
1655 | (define %opensmtpd-accounts | |
1656 | (list (user-group | |
1657 | (name "smtpq") | |
1658 | (system? #t)) | |
1659 | (user-account | |
1660 | (name "smtpd") | |
1661 | (group "nogroup") | |
1662 | (system? #t) | |
1663 | (comment "SMTP Daemon") | |
1664 | (home-directory "/var/empty") | |
1665 | (shell (file-append shadow "/sbin/nologin"))) | |
1666 | (user-account | |
1667 | (name "smtpq") | |
1668 | (group "smtpq") | |
1669 | (system? #t) | |
1670 | (comment "SMTPD Queue") | |
1671 | (home-directory "/var/empty") | |
1672 | (shell (file-append shadow "/sbin/nologin"))))) | |
1673 | ||
1674 | (define opensmtpd-activation | |
1675 | (match-lambda | |
1676 | (($ <opensmtpd-configuration> package config-file) | |
1677 | (let ((smtpd (file-append package "/sbin/smtpd"))) | |
1678 | #~(begin | |
e57bd0be | 1679 | (use-modules (guix build utils)) |
f88371e8 SB |
1680 | ;; Create mbox and spool directories. |
1681 | (mkdir-p "/var/mail") | |
1682 | (mkdir-p "/var/spool/smtpd") | |
a37e03d6 LC |
1683 | (chmod "/var/spool/smtpd" #o711) |
1684 | (mkdir-p "/var/spool/mail") | |
1685 | (chmod "/var/spool/mail" #o711)))))) | |
f88371e8 | 1686 | |
ace8e269 KB |
1687 | (define %opensmtpd-pam-services |
1688 | (list (unix-pam-service "smtpd"))) | |
1689 | ||
f88371e8 SB |
1690 | (define opensmtpd-service-type |
1691 | (service-type | |
1692 | (name 'opensmtpd) | |
1693 | (extensions | |
1694 | (list (service-extension account-service-type | |
1695 | (const %opensmtpd-accounts)) | |
1696 | (service-extension activation-service-type | |
1697 | opensmtpd-activation) | |
ace8e269 KB |
1698 | (service-extension pam-root-service-type |
1699 | (const %opensmtpd-pam-services)) | |
f88371e8 SB |
1700 | (service-extension profile-service-type |
1701 | (compose list opensmtpd-configuration-package)) | |
1702 | (service-extension shepherd-root-service-type | |
1703 | opensmtpd-shepherd-service))))) | |
82ccc499 CZ |
1704 | |
1705 | \f | |
8d17cf1c CZ |
1706 | ;;; |
1707 | ;;; mail aliases. | |
1708 | ;;; | |
1709 | ||
1710 | (define (mail-aliases-etc aliases) | |
1711 | `(("aliases" ,(plain-file "aliases" | |
1712 | ;; Ideally we'd use a format string like | |
1713 | ;; "~:{~a: ~{~a~^,~}\n~}", but it gives a | |
1714 | ;; warning that I can't figure out how to fix, | |
1715 | ;; so we'll just use string-join below instead. | |
1716 | (format #f "~:{~a: ~a\n~}" | |
1717 | (map (match-lambda | |
1718 | ((alias addresses ...) | |
1719 | (list alias (string-join addresses ",")))) | |
1720 | aliases)))))) | |
1721 | ||
1722 | (define mail-aliases-service-type | |
1723 | (service-type | |
1724 | (name 'mail-aliases) | |
1725 | (extensions | |
1726 | (list (service-extension etc-service-type mail-aliases-etc))) | |
1727 | (compose concatenate) | |
1728 | (extend append))) | |
1729 | ||
1730 | \f | |
82ccc499 CZ |
1731 | ;;; |
1732 | ;;; Exim. | |
1733 | ;;; | |
1734 | ||
1735 | (define-record-type* <exim-configuration> exim-configuration | |
1736 | make-exim-configuration | |
1737 | exim-configuration? | |
1738 | (package exim-configuration-package ;<package> | |
1739 | (default exim)) | |
1740 | (config-file exim-configuration-config-file ;file-like | |
b065f78e | 1741 | (default #f))) |
82ccc499 CZ |
1742 | |
1743 | (define %exim-accounts | |
1744 | (list (user-group | |
1745 | (name "exim") | |
1746 | (system? #t)) | |
1747 | (user-account | |
1748 | (name "exim") | |
1749 | (group "exim") | |
1750 | (system? #t) | |
1751 | (comment "Exim Daemon") | |
1752 | (home-directory "/var/empty") | |
1753 | (shell (file-append shadow "/sbin/nologin"))))) | |
1754 | ||
1755 | (define (exim-computed-config-file package config-file) | |
1756 | (computed-file "exim.conf" | |
1757 | #~(call-with-output-file #$output | |
1758 | (lambda (port) | |
1759 | (format port " | |
1760 | exim_user = exim | |
1761 | exim_group = exim | |
1762 | .include ~a" | |
1763 | #$(or config-file | |
1764 | (file-append package "/etc/exim.conf"))))))) | |
1765 | ||
1766 | (define exim-shepherd-service | |
1767 | (match-lambda | |
b065f78e | 1768 | (($ <exim-configuration> package config-file) |
82ccc499 CZ |
1769 | (list (shepherd-service |
1770 | (provision '(exim mta)) | |
1771 | (documentation "Run the exim daemon.") | |
1772 | (requirement '(networking)) | |
1773 | (start #~(make-forkexec-constructor | |
1774 | '(#$(file-append package "/bin/exim") | |
1775 | "-bd" "-v" "-C" | |
1776 | #$(exim-computed-config-file package config-file)))) | |
1777 | (stop #~(make-kill-destructor))))))) | |
1778 | ||
1779 | (define exim-activation | |
1780 | (match-lambda | |
b065f78e | 1781 | (($ <exim-configuration> package config-file) |
82ccc499 CZ |
1782 | (with-imported-modules '((guix build utils)) |
1783 | #~(begin | |
1784 | (use-modules (guix build utils)) | |
1785 | ||
1786 | (let ((uid (passwd:uid (getpw "exim"))) | |
1787 | (gid (group:gid (getgr "exim")))) | |
1788 | (mkdir-p "/var/spool/exim") | |
1789 | (chown "/var/spool/exim" uid gid)) | |
1790 | ||
1791 | (zero? (system* #$(file-append package "/bin/exim") | |
1792 | "-bV" "-C" #$(exim-computed-config-file package config-file)))))))) | |
1793 | ||
82ccc499 CZ |
1794 | (define exim-profile |
1795 | (compose list exim-configuration-package)) | |
1796 | ||
1797 | (define exim-service-type | |
1798 | (service-type | |
1799 | (name 'exim) | |
1800 | (extensions | |
1801 | (list (service-extension shepherd-root-service-type exim-shepherd-service) | |
1802 | (service-extension account-service-type (const %exim-accounts)) | |
1803 | (service-extension activation-service-type exim-activation) | |
1804 | (service-extension profile-service-type exim-profile) | |
b065f78e | 1805 | (service-extension mail-aliases-service-type (const '())))))) |
412e6396 SB |
1806 | |
1807 | \f | |
1808 | ;;; | |
1809 | ;;; GNU Mailutils IMAP4 Daemon. | |
1810 | ;;; | |
1811 | ||
1812 | (define %default-imap4d-config-file | |
1813 | (plain-file "imap4d.conf" "server localhost {};\n")) | |
1814 | ||
1815 | (define-record-type* <imap4d-configuration> | |
1816 | imap4d-configuration make-imap4d-configuration imap4d-configuration? | |
1817 | (package imap4d-configuration-package | |
1818 | (default mailutils)) | |
1819 | (config-file imap4d-configuration-config-file | |
1820 | (default %default-imap4d-config-file))) | |
1821 | ||
1822 | (define imap4d-shepherd-service | |
1823 | (match-lambda | |
1824 | (($ <imap4d-configuration> package config-file) | |
1825 | (list (shepherd-service | |
1826 | (provision '(imap4d)) | |
1827 | (requirement '(networking syslogd)) | |
1828 | (documentation "Run the imap4d daemon.") | |
1829 | (start (let ((imap4d (file-append package "/sbin/imap4d"))) | |
1830 | #~(make-forkexec-constructor | |
1831 | (list #$imap4d "--daemon" "--foreground" | |
1832 | "--config-file" #$config-file)))) | |
1833 | (stop #~(make-kill-destructor))))))) | |
1834 | ||
1835 | (define imap4d-service-type | |
1836 | (service-type | |
1837 | (name 'imap4d) | |
1838 | (description | |
1839 | "Run the GNU @command{imap4d} to serve e-mail messages through IMAP.") | |
1840 | (extensions | |
1841 | (list (service-extension | |
1842 | shepherd-root-service-type imap4d-shepherd-service))) | |
1843 | (default-value (imap4d-configuration)))) |