1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Andy Wingo <wingo@igalia.com>
3 ;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org>
4 ;;; Copyright © 2017 Carlo Zancanaro <carlo@zancanaro.id.au>
5 ;;; Copyright © 2017, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
6 ;;; Copyright © 2019 Kristofer Buffington <kristoferbuffington@gmail.com>
8 ;;; This file is part of GNU Guix.
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.
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.
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/>.
23 ;;; Some of the help text was taken from the default dovecot.conf files.
25 (define-module (gnu services mail)
26 #:use-module (gnu services)
27 #:use-module (gnu services base)
28 #:use-module (gnu services configuration)
29 #:use-module (gnu services shepherd)
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)
38 #:use-module (ice-9 match)
39 #:use-module (ice-9 format)
40 #:use-module (srfi srfi-1)
41 #:export (dovecot-service
44 opaque-dovecot-configuration
49 unix-listener-configuration
50 fifo-listener-configuration
51 inet-listener-configuration
53 protocol-configuration
56 namespace-configuration
58 opensmtpd-configuration
59 opensmtpd-configuration?
60 opensmtpd-service-type
61 %default-opensmtpd-config-file
63 mail-aliases-service-type
68 %default-exim-config-file
73 %default-imap4d-config-file))
77 ;;; This module provides service definitions for the Dovecot POP3 and IMAP
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)))
90 (define (serialize-field field-name val)
91 (format #t "~a=~a\n" (uglify-field-name field-name) val))
93 (define (serialize-string field-name val)
94 (serialize-field field-name val))
96 (define (space-separated-string-list? val)
99 (and (string? x) (not (string-index x #\space))))
101 (define (serialize-space-separated-string-list field-name val)
104 (_ (serialize-field field-name (string-join val " ")))))
106 (define (comma-separated-string-list? val)
109 (and (string? x) (not (string-index x #\,))))
111 (define (serialize-comma-separated-string-list field-name val)
112 (serialize-field field-name (string-join val ",")))
114 (define (file-name? val)
116 (string-prefix? "/" val)))
117 (define (serialize-file-name field-name val)
118 (serialize-string field-name val))
120 (define (colon-separated-file-name-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 ":")))
127 (define (serialize-boolean field-name val)
128 (serialize-string field-name (if val "yes" "no")))
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))
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)))
139 (define (free-form-fields? val)
142 ((((? symbol?) . (? string?)) . val) (free-form-fields? val))
144 (define (serialize-free-form-fields field-name val)
145 (for-each (match-lambda ((k . v) (serialize-field k v))) val))
147 (define (free-form-args? val)
150 ((((? symbol?) . (? string?)) . val) (free-form-args? val))
152 (define (serialize-free-form-args field-name val)
153 (serialize-field field-name
155 (map (match-lambda ((k . v) (format #t "~a=~a" k v))) val)
158 (define-configuration dict-configuration
160 (free-form-fields '())
161 "A list of key-value pairs that this dict should hold."))
163 (define (serialize-dict-configuration field-name val)
164 (format #t "dict {\n")
165 (serialize-configuration val dict-configuration-fields)
168 (define-configuration passdb-configuration
171 "The driver that the passdb should use. Valid values include
172 @samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
175 (space-separated-string-list '())
176 "Space separated list of arguments to the passdb driver."))
178 (define (serialize-passdb-configuration field-name val)
179 (format #t "passdb {\n")
180 (serialize-configuration val passdb-configuration-fields)
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))
187 (define-configuration userdb-configuration
190 "The driver that the userdb should use. Valid values include
191 @samp{passwd} and @samp{static}.")
193 (space-separated-string-list '())
194 "Space separated list of arguments to the userdb driver.")
197 "Override fields from passwd."))
199 (define (serialize-userdb-configuration field-name val)
200 (format #t "userdb {\n")
201 (serialize-configuration val userdb-configuration-fields)
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))
208 (define-configuration unix-listener-configuration
210 (string (configuration-missing-field 'unix-listener 'path))
211 "Path to the file, relative to @code{base-dir} field. This is also used as
215 "The access mode for the socket.")
218 "The user to own the the socket.")
221 "The group to own the socket."))
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))
228 (define-configuration fifo-listener-configuration
230 (string (configuration-missing-field 'fifo-listener 'path))
231 "Path to the file, relative to @code{base-dir} field. This is also used as
235 "The access mode for the socket.")
238 "The user to own the the socket.")
241 "The group to own the socket."))
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))
248 (define-configuration inet-listener-configuration
250 (string (configuration-missing-field 'inet-listener 'protocol))
251 "The protocol to listen for.")
254 "The address on which to listen, or empty for all addresses.")
256 (non-negative-integer
257 (configuration-missing-field 'inet-listener 'port))
258 "The port on which to listen.")
261 "Whether to use SSL for this service; @samp{yes}, @samp{no}, or
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))
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)
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))
281 (else (configuration-field-error field-name val))))
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))
289 (define-configuration service-configuration
291 (string (configuration-missing-field 'service 'kind))
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.")
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}.")
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
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>.")
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.")
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.
322 (non-negative-integer #e256e6)
323 "If you set @samp{service-count 0}, you probably need to grow
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))
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))
337 (define-configuration protocol-configuration
339 (string (configuration-missing-field 'protocol 'name))
340 "The name of the protocol.")
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.")
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."))
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))
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))
366 (define-configuration plugin-configuration
368 (free-form-fields '())
369 "A list of key-value pairs that this dict should hold."))
371 (define (serialize-plugin-configuration field-name val)
372 (format #t "plugin {\n")
373 (serialize-configuration val plugin-configuration-fields)
376 (define-configuration mailbox-configuration
378 (string (error "mailbox name is required"))
379 "Name for this mailbox.")
383 "@samp{create} will automatically create this mailbox.
384 @samp{subscribe} will both create and subscribe to the mailbox.")
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}."))
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))
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))
403 (define-configuration namespace-configuration
405 (string (error "namespace name is required"))
406 "Name for this namespace.")
410 "Namespace type: @samp{private}, @samp{shared} or @samp{public}.")
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
421 "Prefix required to access this namespace. This needs to be
422 different for all namespaces. For example @samp{Public/}.")
426 "Physical location of the mailbox. This is in same format as
427 mail_location, which is also the default for it.")
431 "There can be only one INBOX, and this setting defines which
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/}
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.")
452 "Namespace handles its own subscriptions. If set to @code{#f}, the
453 parent namespace handles them. The empty prefix should always have this
457 (mailbox-configuration-list '())
458 "List of predefined mailboxes in this namespace."))
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))
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))
471 (define-configuration dovecot-configuration
474 "The dovecot package.")
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.")
485 (dict-configuration (dict-configuration))
486 "Dict configuration, as created by the @code{dict-configuration}
490 (passdb-configuration-list (list (passdb-configuration (driver "pam"))))
491 "List of passdb configurations, each one created by the
492 @code{passdb-configuration} constructor.")
495 (userdb-configuration-list (list (userdb-configuration (driver "passwd"))))
496 "List of userdb configurations, each one created by the
497 @code{userdb-configuration} constructor.")
499 (plugin-configuration
500 (plugin-configuration (plugin-configuration))
501 "Plug-in configuration, created by the @code{plugin-configuration}
505 (list-of-namespace-configuration
507 (namespace-configuration
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.")
523 (file-name "/var/run/dovecot/")
524 "Base directory where to store runtime data.")
527 (string "Dovecot ready.")
528 "Greeting message for clients.")
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
538 (login-access-sockets
539 (space-separated-string-list '())
540 "List of login access check sockets (e.g. tcpwrap).")
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
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).")
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.")
562 (string "doveadm-server")
563 "UNIX socket or host:port used for connecting to doveadm server.")
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.")
571 ;;; Authentication processes
573 (disable-plaintext-auth?
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.")
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.")
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
596 (auth-cache-negative-ttl
598 "TTL for negative hits (user not found, password mismatch).
599 0 disables caching them completely.")
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
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
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.")
623 (auth-username-translation
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{@@}.")
630 (auth-username-format
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.")
638 (auth-master-user-separator
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
647 (auth-anonymous-username
649 "Username to use for users logging in with ANONYMOUS SASL
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.")
658 (auth-gssapi-hostname
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.")
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
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>.")
677 (auth-winbind-helper-path
678 (file-name "/usr/bin/ntlm_auth")
679 "Path for Samba's @samp{ntlm-auth} helper binary.")
683 "Time to delay before replying to failed authentications.")
685 (auth-ssl-require-client-cert?
687 "Require a valid SSL client certificate or the authentication
690 (auth-ssl-username-from-cert?
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
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.")
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.")
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.")
715 (director-user-expire
717 "How long to redirect users to a specific server after it no longer
718 has any connections.")
720 (director-username-hash
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.")
730 "Log file to use for error messages. @samp{syslog} logs to syslog,
731 @samp{/dev/stderr} logs to stderr.")
735 "Log file to use for informational messages. Defaults to
740 "Log file to use for debug messages. Defaults to
741 @samp{info-log-path}.")
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.")
751 "Log unsuccessful authentication attempts and the reasons why they
754 (auth-verbose-passwords
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).")
764 "Even more verbose logging for debugging purposes. Shows for example
767 (auth-debug-passwords?
769 "In case of password mismatches, log the passwords and used scheme so
770 the problem can be debugged. Enabling this also enables
775 "Enable mail process debugging. This can help you figure out why
776 Dovecot isn't finding your mails.")
780 "Show protocol level SSL errors.")
783 (string "\"%b %d %H:%M:%S \"")
784 "Prefix for each line written to log file. % codes are in
785 strftime(3) format.")
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
796 "Login log format. %s contains @samp{login-log-format-elements}
797 string, %$ contains the data we want to log.")
800 (string "\"%s(%u)<%{pid}><%{session}>: \"")
801 "Log prefix for mail processes. See doc/wiki/Variables.txt for list
802 of possible variables you can use.")
805 (string "msgid=%m: %$")
806 "Format to use for logging mail deliveries. You can use variables:
809 Delivery status message (e.g. @samp{saved to INBOX})
822 ;;; Mailbox locations and namespaces
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.
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.
837 There are a few special variables you can use, eg.:
843 user part in user@@domain, same as %u if there's no domain
845 domain part in user@@domain, empty if there's no domain
850 See doc/wiki/Variables.txt for full list. Some examples:
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/%
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>.")
867 (mail-privileged-group
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
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).")
883 (mail-full-filesystem-access?
885 "Allow full file system access to clients. There's no access checks
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/.")
894 "Don't use mmap() at all. This is required if you store indexes to
895 shared file systems (NFS or clustered file system).")
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.")
905 "When to use fsync() or fdatasync() calls:
908 Whenever necessary to avoid losing important data
910 Useful with e.g. NFS when write()s are delayed
912 Never use it (best performance, but crashes can lose data).
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
923 "Mail index files also exist in NFS. Setting this to yes requires
924 @samp{mmap-disable? #t} and @samp{fsync-disable? #f}.")
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}.")
935 "Directory in which LDA/LMTP temporarily stores incoming mails >128
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}
946 (non-negative-integer 0)
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.")
956 (non-negative-integer 0)
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.")
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>.")
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>.")
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.")
991 (file-name "/usr/lib/dovecot")
992 "Directory where to look up mail plugins.")
995 (space-separated-string-list '())
996 "List of plugins to load for all services. Plugins specific to IMAP,
997 LDA, etc. are added to this list in their own .conf files.")
1000 (mail-cache-min-mail-count
1001 (non-negative-integer 0)
1002 "The minimum number of mails in a mailbox before updates are done to
1003 cache file. This allows optimizing Dovecot's behavior to do less disk
1004 writes at the cost of more disk reads.")
1006 (mailbox-idle-check-interval
1008 "When IDLE command is running, mailbox is checked once in a while to
1009 see if there are any new mails or other changes. This setting defines
1010 the minimum time to wait between those checks. Dovecot can also use
1011 dnotify, inotify and kqueue to find out immediately when changes
1016 "Save mails with CR+LF instead of plain LF. This makes sending those
1017 mails take less CPU, especially with sendfile() syscall with Linux and
1018 FreeBSD. But it also creates a bit more disk I/O which may just make it
1019 slower. Also note that if other software reads the mboxes/maildirs,
1020 they may handle the extra CRs wrong and cause problems.")
1024 "By default LIST command returns all entries in maildir beginning
1025 with a dot. Enabling this option makes Dovecot return only entries
1026 which are directories. This is done by stat()ing each entry, so it
1027 causes more disk I/O.
1028 (For systems setting struct @samp{dirent->d_type} this check is free
1029 and it's done always regardless of this setting).")
1031 (maildir-copy-with-hardlinks?
1033 "When copying a message, do it with hard links whenever possible.
1034 This makes the performance much better, and it's unlikely to have any
1037 (maildir-very-dirty-syncs?
1039 "Assume Dovecot is the only MUA accessing Maildir: Scan cur/
1040 directory only when its mtime changes unexpectedly or when we can't find
1041 the mail otherwise.")
1044 (space-separated-string-list '("fcntl"))
1045 "Which locking methods to use for locking mbox. There are four
1050 Create <mailbox>.lock file. This is the oldest and most NFS-safe
1051 solution. If you want to use /var/mail/ like directory, the users will
1052 need write access to that directory.
1054 Same as dotlock, but if it fails because of permissions or because there
1055 isn't enough disk space, just skip it.
1057 Use this if possible. Works with NFS too if lockd is used.
1059 May not exist in all systems. Doesn't work with NFS.
1061 May not exist in all systems. Doesn't work with NFS.
1064 You can use multiple locking methods; if you do the order they're declared
1065 in is important to avoid deadlocks if other MTAs/MUAs are using multiple
1066 locking methods as well. Some operating systems don't allow using some of
1067 them simultaneously.")
1070 (space-separated-string-list '("dotlock" "fcntl"))
1075 "Maximum time to wait for lock (all of them) before aborting.")
1077 (mbox-dotlock-change-timeout
1079 "If dotlock exists but the mailbox isn't modified in any way,
1080 override the lock file after this much time.")
1084 "When mbox changes unexpectedly we have to fully read it to find out
1085 what changed. If the mbox is large this can take a long time. Since
1086 the change is usually just a newly appended mail, it'd be faster to
1087 simply read the new mails. If this setting is enabled, Dovecot does
1088 this but still safely fallbacks to re-reading the whole mbox file
1089 whenever something in mbox isn't how it's expected to be. The only real
1090 downside to this setting is that if some other MUA changes message
1091 flags, Dovecot doesn't notice it immediately. Note that a full sync is
1092 done with SELECT, EXAMINE, EXPUNGE and CHECK commands.")
1094 (mbox-very-dirty-syncs?
1096 "Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
1097 EXAMINE, EXPUNGE or CHECK commands. If this is set,
1098 @samp{mbox-dirty-syncs} is ignored.")
1102 "Delay writing mbox headers until doing a full write sync (EXPUNGE
1103 and CHECK commands and when closing the mailbox). This is especially
1104 useful for POP3 where clients often delete all mails. The downside is
1105 that our changes aren't immediately visible to other MUAs.")
1107 (mbox-min-index-size
1108 (non-negative-integer 0)
1109 "If mbox size is smaller than this (e.g. 100k), don't write index
1110 files. If an index file already exists it's still read, just not
1114 (non-negative-integer #e10e6)
1115 "Maximum dbox file size until it's rotated.")
1117 (mdbox-rotate-interval
1119 "Maximum dbox file age until it's rotated. Typically in days. Day
1120 begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
1123 (mdbox-preallocate-space?
1125 "When creating new mdbox files, immediately preallocate their size to
1126 @samp{mdbox-rotate-size}. This setting currently works only in Linux
1127 with some file systems (ext4, xfs).")
1129 (mail-attachment-dir
1131 "sdbox and mdbox support saving mail attachments to external files,
1132 which also allows single instance storage for them. Other backends
1133 don't support this for now.
1135 WARNING: This feature hasn't been tested much yet. Use at your own risk.
1137 Directory root where to store mail attachments. Disabled, if empty.")
1139 (mail-attachment-min-size
1140 (non-negative-integer #e128e3)
1141 "Attachments smaller than this aren't saved externally. It's also
1142 possible to write a plugin to disable saving specific attachments
1146 (string "sis posix")
1147 "File system backend to use for saving attachments:
1150 No SiS done by Dovecot (but this might help FS's own deduplication)
1152 SiS with immediate byte-by-byte comparison during saving
1153 @item sis-queue posix
1154 SiS with delayed comparison and deduplication.
1157 (mail-attachment-hash
1159 "Hash format to use in attachment filenames. You can add any text and
1160 variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
1161 @code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
1162 truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.")
1164 (default-process-limit
1165 (non-negative-integer 100)
1168 (default-client-limit
1169 (non-negative-integer 1000)
1173 (non-negative-integer #e256e6)
1174 "Default VSZ (virtual memory size) limit for service processes.
1175 This is mainly intended to catch and kill processes that leak memory
1176 before they eat up everything.")
1180 "Login user is internally used by login processes. This is the most
1181 untrusted user in Dovecot system. It shouldn't have access to anything
1184 (default-internal-user
1186 "Internal user is used by unprivileged processes. It should be
1187 separate from login user, so that login processes can't disturb other
1192 "SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.")
1195 (string "</etc/dovecot/default.pem")
1196 "PEM encoded X.509 SSL/TLS certificate (public key).")
1199 (string "</etc/dovecot/private/default.pem")
1200 "PEM encoded SSL/TLS private key. The key is opened before
1201 dropping root privileges, so keep the key file unreadable by anyone but
1206 "If key file is password protected, give the password here.
1207 Alternatively give it when starting dovecot with -p parameter. Since
1208 this file is often world-readable, you may want to place this setting
1209 instead to a different.")
1213 "PEM encoded trusted certificate authority. Set this only if you
1214 intend to use @samp{ssl-verify-client-cert? #t}. The file should
1215 contain the CA certificate(s) followed by the matching
1216 CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).")
1219 "Require that CRL check succeeds for client certificates.")
1220 (ssl-verify-client-cert?
1222 "Request client to send a certificate. If you also want to require
1223 it, set @samp{auth-ssl-require-client-cert? #t} in auth section.")
1225 (ssl-cert-username-field
1226 (string "commonName")
1227 "Which field from certificate to use for username. commonName and
1228 x500UniqueIdentifier are the usual choices. You'll also need to set
1229 @samp{auth-ssl-username-from-cert? #t}.")
1233 "Minimum SSL protocol version to accept.")
1236 (string "ALL:!kRSA:!SRP:!kDHd:!DSS:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK:!RC4:!ADH:!LOW@STRENGTH")
1237 "SSL ciphers to use.")
1241 "SSL crypto device to use, for valid values run \"openssl engine\".")
1244 (string "postmaster@%d")
1245 "Address to use when sending rejection mails.
1246 Default is postmaster@@<your domain>. %d expands to recipient domain.")
1250 "Hostname to use in various parts of sent mails (e.g. in Message-Id)
1251 and in LMTP replies. Default is the system's real hostname@@domain.")
1253 (quota-full-tempfail?
1255 "If user is over quota, return with temporary failure instead of
1256 bouncing the mail.")
1259 (file-name "/usr/sbin/sendmail")
1260 "Binary to use for sending mails.")
1264 "If non-empty, send mails via this SMTP host[:port] instead of
1268 (string "Rejected: %s")
1269 "Subject: header to use for rejection mails. You can use the same
1270 variables as for @samp{rejection-reason} below.")
1273 (string "Your message to <%t> was automatically rejected:%n%r")
1274 "Human readable error message for rejection mails. You can use
1288 (recipient-delimiter
1290 "Delimiter character between local-part and detail in email
1293 (lda-original-recipient-header
1295 "Header where the original recipient address (SMTP's RCPT TO:
1296 address) is taken from if not available elsewhere. With dovecot-lda -a
1297 parameter overrides this. A commonly used header for this is
1300 (lda-mailbox-autocreate?
1302 "Should saving a mail to a nonexistent mailbox automatically create
1305 (lda-mailbox-autosubscribe?
1307 "Should automatically created mailboxes be also automatically
1311 (imap-max-line-length
1312 (non-negative-integer #e64e3)
1313 "Maximum IMAP command line length. Some clients generate very long
1314 command lines with huge mailboxes, so you may need to raise this if you
1315 get \"Too long argument\" or \"IMAP command line too large\" errors
1319 (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}")
1320 "IMAP logout format string:
1323 total number of bytes read from client
1325 total number of bytes sent to client.
1327 See @file{doc/wiki/Variables.txt} for a list of all the variables you can use.")
1331 "Override the IMAP CAPABILITY response. If the value begins with '+',
1332 add the given capabilities on top of the defaults (e.g. +XFOO XBAR).")
1334 (imap-idle-notify-interval
1336 "How long to wait between \"OK Still here\" notifications when client
1341 "ID field names and values to send to clients. Using * as the value
1342 makes Dovecot use the default value. The following fields have default
1343 values currently: name, version, os, os-version, support-url,
1348 "ID fields sent by client to log. * means everything.")
1350 (imap-client-workarounds
1351 (space-separated-string-list '())
1352 "Workarounds for various client bugs:
1356 Send EXISTS/RECENT new mail notifications only when replying to NOOP and
1357 CHECK commands. Some clients ignore them otherwise, for example OSX
1358 Mail (<v2.1). Outlook Express breaks more badly though, without this it
1359 may show user \"Message no longer in server\" errors. Note that OE6
1360 still breaks even with this workaround if synchronization is set to
1363 @item tb-extra-mailbox-sep
1364 Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
1365 adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
1366 ignore the extra @samp{/} instead of treating it as invalid mailbox name.
1369 Show \\Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
1370 This makes Thunderbird realize they aren't selectable and show them
1371 greyed out, instead of only later giving \"not selectable\" popup error.
1377 "Host allowed in URLAUTH URLs sent by client. \"*\" allows all.")
1380 (protocol-configuration-list
1381 (list (protocol-configuration
1383 "List of protocols we want to serve. Available protocols include
1384 @samp{imap}, @samp{pop3}, and @samp{lmtp}.")
1387 (service-configuration-list
1389 (service-configuration
1395 (inet-listener-configuration (protocol "imap") (port 143) (ssl? #f))
1396 (inet-listener-configuration (protocol "imaps") (port 993) (ssl? #t)))))
1397 (service-configuration
1401 (inet-listener-configuration (protocol "pop3") (port 110) (ssl? #f))
1402 (inet-listener-configuration (protocol "pop3s") (port 995) (ssl? #t)))))
1403 (service-configuration
1408 (list (unix-listener-configuration (path "lmtp") (mode "0666")))))
1409 (service-configuration
1412 (process-limit 1024))
1413 (service-configuration
1416 (process-limit 1024))
1417 (service-configuration
1423 (list (unix-listener-configuration (path "auth-userdb")))))
1424 (service-configuration
1425 (kind "auth-worker")
1428 (service-configuration
1432 (listeners (list (unix-listener-configuration (path "dict")))))))
1433 "List of services to enable. Available services include @samp{imap},
1434 @samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
1437 (define-configuration opaque-dovecot-configuration
1440 "The dovecot package.")
1443 (string (configuration-missing-field 'opaque-dovecot-configuration
1445 "The contents of the @code{dovecot.conf} to use."))
1447 (define %dovecot-accounts
1448 ;; Account and group for the Dovecot daemon.
1449 (list (user-group (name "dovecot") (system? #t))
1454 (comment "Dovecot daemon user")
1455 (home-directory "/var/empty")
1456 (shell (file-append shadow "/sbin/nologin")))
1458 (user-group (name "dovenull") (system? #t))
1463 (comment "Dovecot daemon login user")
1464 (home-directory "/var/empty")
1465 (shell (file-append shadow "/sbin/nologin")))))
1467 (define (%dovecot-activation config)
1471 ((opaque-dovecot-configuration? config)
1472 (opaque-dovecot-configuration-string config))
1474 (with-output-to-string
1476 (serialize-configuration config
1477 dovecot-configuration-fields)))))))
1479 (use-modules (guix build utils))
1480 (define (mkdir-p/perms directory owner perms)
1482 (chown "/var/run/dovecot" (passwd:uid owner) (passwd:gid owner))
1483 (chmod directory perms))
1484 (define (build-subject parameters)
1487 (let ((k (car pair)) (v (cdr pair)))
1488 (define (escape-char str chr)
1489 (string-join (string-split str chr) (string #\\ chr)))
1490 (string-append "/" k "="
1491 (escape-char (escape-char v #\=) #\/))))
1492 (filter (lambda (pair) (cdr pair)) parameters))))
1493 (define* (create-self-signed-certificate-if-absent
1494 #:key private-key public-key (owner (getpwnam "root"))
1495 (common-name (gethostname))
1496 (organization-name "Guix")
1497 (organization-unit-name "Default Self-Signed Certificate")
1498 (subject-parameters `(("CN" . ,common-name)
1499 ("O" . ,organization-name)
1500 ("OU" . ,organization-unit-name)))
1501 (subject (build-subject subject-parameters)))
1502 ;; Note that by default, OpenSSL outputs keys in PEM format. This
1504 (unless (file-exists? private-key)
1506 ((zero? (system* (string-append #$openssl "/bin/openssl")
1507 "genrsa" "-out" private-key "2048"))
1508 (chown private-key (passwd:uid owner) (passwd:gid owner))
1509 (chmod private-key #o400))
1511 (format (current-error-port)
1512 "Failed to create private key at ~a.\n" private-key))))
1513 (unless (file-exists? public-key)
1515 ((zero? (system* (string-append #$openssl "/bin/openssl")
1516 "req" "-new" "-x509" "-key" private-key
1517 "-out" public-key "-days" "3650"
1518 "-batch" "-subj" subject))
1519 (chown public-key (passwd:uid owner) (passwd:gid owner))
1520 (chmod public-key #o444))
1522 (format (current-error-port)
1523 "Failed to create public key at ~a.\n" public-key)))))
1524 (let ((user (getpwnam "dovecot")))
1525 (mkdir-p/perms "/var/run/dovecot" user #o755)
1526 (mkdir-p/perms "/var/lib/dovecot" user #o755)
1527 (mkdir-p/perms "/etc/dovecot" user #o755)
1528 (copy-file #$(plain-file "dovecot.conf" config-str)
1529 "/etc/dovecot/dovecot.conf")
1530 (mkdir-p/perms "/etc/dovecot/private" user #o700)
1531 (create-self-signed-certificate-if-absent
1532 #:private-key "/etc/dovecot/private/default.pem"
1533 #:public-key "/etc/dovecot/default.pem"
1534 #:owner (getpwnam "root")
1535 #:common-name (format #f "Dovecot service on ~a" (gethostname)))))))
1537 (define (dovecot-shepherd-service config)
1538 "Return a list of <shepherd-service> for CONFIG."
1539 (let ((dovecot (if (opaque-dovecot-configuration? config)
1540 (opaque-dovecot-configuration-dovecot config)
1541 (dovecot-configuration-dovecot config))))
1542 (list (shepherd-service
1543 (documentation "Run the Dovecot POP3/IMAP mail server.")
1544 (provision '(dovecot))
1545 (requirement '(networking))
1546 (start #~(make-forkexec-constructor
1547 (list (string-append #$dovecot "/sbin/dovecot")
1550 (invoke #$(file-append dovecot "/sbin/dovecot")
1554 (define %dovecot-pam-services
1555 (list (unix-pam-service "dovecot")))
1557 (define dovecot-service-type
1558 (service-type (name 'dovecot)
1560 (list (service-extension shepherd-root-service-type
1561 dovecot-shepherd-service)
1562 (service-extension account-service-type
1563 (const %dovecot-accounts))
1564 (service-extension pam-root-service-type
1565 (const %dovecot-pam-services))
1566 (service-extension activation-service-type
1567 %dovecot-activation)))))
1569 (define* (dovecot-service #:key (config (dovecot-configuration)))
1570 "Return a service that runs @command{dovecot}, a mail server that can run
1571 POP3, IMAP, and LMTP. @var{config} should be a configuration object created
1572 by @code{dovecot-configuration}. @var{config} may also be created by
1573 @code{opaque-dovecot-configuration}, which allows specification of the
1574 @code{dovecot.conf} as a string."
1575 (validate-configuration config
1576 (if (opaque-dovecot-configuration? config)
1577 opaque-dovecot-configuration-fields
1578 dovecot-configuration-fields))
1579 (service dovecot-service-type config))
1581 ;; A little helper to make it easier to document all those fields.
1582 (define (generate-dovecot-documentation)
1583 (generate-documentation
1584 `((dovecot-configuration
1585 ,dovecot-configuration-fields
1586 (dict dict-configuration)
1587 (namespaces namespace-configuration)
1588 (plugin plugin-configuration)
1589 (passdbs passdb-configuration)
1590 (userdbs userdb-configuration)
1591 (services service-configuration)
1592 (protocols protocol-configuration))
1593 (dict-configuration ,dict-configuration-fields)
1594 (plugin-configuration ,plugin-configuration-fields)
1595 (passdb-configuration ,passdb-configuration-fields)
1596 (userdb-configuration ,userdb-configuration-fields)
1597 (unix-listener-configuration ,unix-listener-configuration-fields)
1598 (fifo-listener-configuration ,fifo-listener-configuration-fields)
1599 (inet-listener-configuration ,inet-listener-configuration-fields)
1600 (namespace-configuration
1601 ,namespace-configuration-fields
1602 (mailboxes mailbox-configuration))
1603 (mailbox-configuration ,mailbox-configuration-fields)
1604 (service-configuration
1605 ,service-configuration-fields
1606 (listeners unix-listener-configuration fifo-listener-configuration
1607 inet-listener-configuration))
1608 (protocol-configuration ,protocol-configuration-fields))
1609 'dovecot-configuration))
1616 (define-record-type* <opensmtpd-configuration>
1617 opensmtpd-configuration make-opensmtpd-configuration
1618 opensmtpd-configuration?
1619 (package opensmtpd-configuration-package
1620 (default opensmtpd))
1621 (config-file opensmtpd-configuration-config-file
1622 (default %default-opensmtpd-config-file)))
1624 (define %default-opensmtpd-config-file
1625 (plain-file "smtpd.conf" "
1629 match for local action inbound
1631 action outbound relay
1632 match from local for any action outbound
1635 (define opensmtpd-shepherd-service
1637 (($ <opensmtpd-configuration> package config-file)
1638 (list (shepherd-service
1639 (provision '(smtpd))
1640 (requirement '(loopback))
1641 (documentation "Run the OpenSMTPD daemon.")
1642 (start (let ((smtpd (file-append package "/sbin/smtpd")))
1643 #~(make-forkexec-constructor
1644 (list #$smtpd "-f" #$config-file)
1645 #:pid-file "/var/run/smtpd.pid")))
1646 (stop #~(make-kill-destructor)))))))
1648 (define %opensmtpd-accounts
1656 (comment "SMTP Daemon")
1657 (home-directory "/var/empty")
1658 (shell (file-append shadow "/sbin/nologin")))
1663 (comment "SMTPD Queue")
1664 (home-directory "/var/empty")
1665 (shell (file-append shadow "/sbin/nologin")))))
1667 (define opensmtpd-activation
1669 (($ <opensmtpd-configuration> package config-file)
1670 (let ((smtpd (file-append package "/sbin/smtpd")))
1672 (use-modules (guix build utils))
1673 ;; Create mbox and spool directories.
1674 (mkdir-p "/var/mail")
1675 (mkdir-p "/var/spool/smtpd")
1676 (chmod "/var/spool/smtpd" #o711)
1677 (mkdir-p "/var/spool/mail")
1678 (chmod "/var/spool/mail" #o711))))))
1680 (define %opensmtpd-pam-services
1681 (list (unix-pam-service "smtpd")))
1683 (define opensmtpd-service-type
1687 (list (service-extension account-service-type
1688 (const %opensmtpd-accounts))
1689 (service-extension activation-service-type
1690 opensmtpd-activation)
1691 (service-extension pam-root-service-type
1692 (const %opensmtpd-pam-services))
1693 (service-extension profile-service-type
1694 (compose list opensmtpd-configuration-package))
1695 (service-extension shepherd-root-service-type
1696 opensmtpd-shepherd-service)))))
1703 (define (mail-aliases-etc aliases)
1704 `(("aliases" ,(plain-file "aliases"
1705 ;; Ideally we'd use a format string like
1706 ;; "~:{~a: ~{~a~^,~}\n~}", but it gives a
1707 ;; warning that I can't figure out how to fix,
1708 ;; so we'll just use string-join below instead.
1709 (format #f "~:{~a: ~a\n~}"
1711 ((alias addresses ...)
1712 (list alias (string-join addresses ","))))
1715 (define mail-aliases-service-type
1717 (name 'mail-aliases)
1719 (list (service-extension etc-service-type mail-aliases-etc)))
1720 (compose concatenate)
1728 (define-record-type* <exim-configuration> exim-configuration
1729 make-exim-configuration
1731 (package exim-configuration-package ;<package>
1733 (config-file exim-configuration-config-file ;file-like
1736 (define %exim-accounts
1744 (comment "Exim Daemon")
1745 (home-directory "/var/empty")
1746 (shell (file-append shadow "/sbin/nologin")))))
1748 (define (exim-computed-config-file package config-file)
1749 (computed-file "exim.conf"
1750 #~(call-with-output-file #$output
1757 (file-append package "/etc/exim.conf")))))))
1759 (define exim-shepherd-service
1761 (($ <exim-configuration> package config-file)
1762 (list (shepherd-service
1763 (provision '(exim mta))
1764 (documentation "Run the exim daemon.")
1765 (requirement '(networking))
1766 (start #~(make-forkexec-constructor
1767 '(#$(file-append package "/bin/exim")
1769 #$(exim-computed-config-file package config-file))))
1770 (stop #~(make-kill-destructor)))))))
1772 (define exim-activation
1774 (($ <exim-configuration> package config-file)
1775 (with-imported-modules '((guix build utils))
1777 (use-modules (guix build utils))
1779 (let ((uid (passwd:uid (getpw "exim")))
1780 (gid (group:gid (getgr "exim"))))
1781 (mkdir-p "/var/spool/exim")
1782 (chown "/var/spool/exim" uid gid))
1784 (zero? (system* #$(file-append package "/bin/exim")
1785 "-bV" "-C" #$(exim-computed-config-file package config-file))))))))
1787 (define exim-profile
1788 (compose list exim-configuration-package))
1790 (define exim-service-type
1794 (list (service-extension shepherd-root-service-type exim-shepherd-service)
1795 (service-extension account-service-type (const %exim-accounts))
1796 (service-extension activation-service-type exim-activation)
1797 (service-extension profile-service-type exim-profile)
1798 (service-extension mail-aliases-service-type (const '()))))))
1802 ;;; GNU Mailutils IMAP4 Daemon.
1805 (define %default-imap4d-config-file
1806 (plain-file "imap4d.conf" "server localhost {};\n"))
1808 (define-record-type* <imap4d-configuration>
1809 imap4d-configuration make-imap4d-configuration imap4d-configuration?
1810 (package imap4d-configuration-package
1811 (default mailutils))
1812 (config-file imap4d-configuration-config-file
1813 (default %default-imap4d-config-file)))
1815 (define imap4d-shepherd-service
1817 (($ <imap4d-configuration> package config-file)
1818 (list (shepherd-service
1819 (provision '(imap4d))
1820 (requirement '(networking syslogd))
1821 (documentation "Run the imap4d daemon.")
1822 (start (let ((imap4d (file-append package "/sbin/imap4d")))
1823 #~(make-forkexec-constructor
1824 (list #$imap4d "--daemon" "--foreground"
1825 "--config-file" #$config-file))))
1826 (stop #~(make-kill-destructor)))))))
1828 (define imap4d-service-type
1832 "Run the GNU @command{imap4d} to serve e-mail messages through IMAP.")
1834 (list (service-extension
1835 shepherd-root-service-type imap4d-shepherd-service)))
1836 (default-value (imap4d-configuration))))