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 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)
102 (serialize-field field-name (string-join val " ")))
104 (define (comma-separated-string-list? val)
107 (and (string? x) (not (string-index x #\,))))
109 (define (serialize-comma-separated-string-list field-name val)
110 (serialize-field field-name (string-join val ",")))
112 (define (file-name? val)
114 (string-prefix? "/" val)))
115 (define (serialize-file-name field-name val)
116 (serialize-string field-name val))
118 (define (colon-separated-file-name-list? val)
120 ;; Trailing slashes not needed and not
121 (and-map file-name? val)))
122 (define (serialize-colon-separated-file-name-list field-name val)
123 (serialize-field field-name (string-join val ":")))
125 (define (serialize-boolean field-name val)
126 (serialize-string field-name (if val "yes" "no")))
128 (define (non-negative-integer? val)
129 (and (exact-integer? val) (not (negative? val))))
130 (define (serialize-non-negative-integer field-name val)
131 (serialize-field field-name val))
133 (define (hours? val) (non-negative-integer? val))
134 (define (serialize-hours field-name val)
135 (serialize-field field-name (format #f "~a hours" val)))
137 (define (free-form-fields? val)
140 ((((? symbol?) . (? string)) . val) (free-form-fields? val))
142 (define (serialize-free-form-fields field-name val)
143 (for-each (match-lambda ((k . v) (serialize-field k v))) val))
145 (define (free-form-args? val)
148 ((((? symbol?) . (? string)) . val) (free-form-args? val))
150 (define (serialize-free-form-args field-name val)
151 (serialize-field field-name
153 (map (match-lambda ((k . v) (format #t "~a=~a" k v))) val)
156 (define-configuration dict-configuration
158 (free-form-fields '())
159 "A list of key-value pairs that this dict should hold."))
161 (define (serialize-dict-configuration field-name val)
162 (format #t "dict {\n")
163 (serialize-configuration val dict-configuration-fields)
166 (define-configuration passdb-configuration
169 "The driver that the passdb should use. Valid values include
170 @samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
173 (space-separated-string-list '())
174 "Space separated list of arguments to the passdb driver."))
176 (define (serialize-passdb-configuration field-name val)
177 (format #t "passdb {\n")
178 (serialize-configuration val passdb-configuration-fields)
180 (define (passdb-configuration-list? val)
181 (and (list? val) (and-map passdb-configuration? val)))
182 (define (serialize-passdb-configuration-list field-name val)
183 (for-each (lambda (val) (serialize-passdb-configuration field-name val)) val))
185 (define-configuration userdb-configuration
188 "The driver that the userdb should use. Valid values include
189 @samp{passwd} and @samp{static}.")
191 (space-separated-string-list '())
192 "Space separated list of arguments to the userdb driver.")
195 "Override fields from passwd."))
197 (define (serialize-userdb-configuration field-name val)
198 (format #t "userdb {\n")
199 (serialize-configuration val userdb-configuration-fields)
201 (define (userdb-configuration-list? val)
202 (and (list? val) (and-map userdb-configuration? val)))
203 (define (serialize-userdb-configuration-list field-name val)
204 (for-each (lambda (val) (serialize-userdb-configuration field-name val)) val))
206 (define-configuration unix-listener-configuration
208 (string (configuration-missing-field 'unix-listener 'path))
209 "Path to the file, relative to @code{base-dir} field. This is also used as
213 "The access mode for the socket.")
216 "The user to own the the socket.")
219 "The group to own the socket."))
221 (define (serialize-unix-listener-configuration field-name val)
222 (format #t "unix_listener ~a {\n" (unix-listener-configuration-path val))
223 (serialize-configuration val (cdr unix-listener-configuration-fields))
226 (define-configuration fifo-listener-configuration
228 (string (configuration-missing-field 'fifo-listener 'path))
229 "Path to the file, relative to @code{base-dir} field. This is also used as
233 "The access mode for the socket.")
236 "The user to own the the socket.")
239 "The group to own the socket."))
241 (define (serialize-fifo-listener-configuration field-name val)
242 (format #t "fifo_listener ~a {\n" (fifo-listener-configuration-path val))
243 (serialize-configuration val (cdr fifo-listener-configuration-fields))
246 (define-configuration inet-listener-configuration
248 (string (configuration-missing-field 'inet-listener 'protocol))
249 "The protocol to listen for.")
252 "The address on which to listen, or empty for all addresses.")
254 (non-negative-integer
255 (configuration-missing-field 'inet-listener 'port))
256 "The port on which to listen.")
259 "Whether to use SSL for this service; @samp{yes}, @samp{no}, or
262 (define (serialize-inet-listener-configuration field-name val)
263 (format #t "inet_listener ~a {\n" (inet-listener-configuration-protocol val))
264 (serialize-configuration val (cdr inet-listener-configuration-fields))
267 (define (listener-configuration? val)
268 (or (unix-listener-configuration? val)
269 (fifo-listener-configuration? val)
270 (inet-listener-configuration? val)))
271 (define (serialize-listener-configuration field-name val)
273 ((unix-listener-configuration? val)
274 (serialize-unix-listener-configuration field-name val))
275 ((fifo-listener-configuration? val)
276 (serialize-fifo-listener-configuration field-name val))
277 ((inet-listener-configuration? val)
278 (serialize-inet-listener-configuration field-name val))
279 (else (configuration-field-error field-name val))))
280 (define (listener-configuration-list? val)
281 (and (list? val) (and-map listener-configuration? val)))
282 (define (serialize-listener-configuration-list field-name val)
283 (for-each (lambda (val)
284 (serialize-listener-configuration field-name val))
287 (define-configuration service-configuration
289 (string (configuration-missing-field 'service 'kind))
290 "The service kind. Valid values include @code{director},
291 @code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
292 @code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
293 @code{tcpwrap}, @code{quota-warning}, or anything else.")
295 (listener-configuration-list '())
296 "Listeners for the service. A listener is either an
297 @code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
298 an @code{inet-listener-configuration}.")
300 (non-negative-integer 0)
301 "Maximum number of simultaneous client connections per process. Once this
302 number of connections is received, the next incoming connection will prompt
303 Dovecot to spawn another process. If set to 0, @code{default-client-limit} is
306 (non-negative-integer 1)
307 "Number of connections to handle before starting a new process.
308 Typically the only useful values are 0 (unlimited) or 1. 1 is more
309 secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.")
311 (non-negative-integer 0)
312 "Maximum number of processes that can exist for this service. If set to 0,
313 @code{default-process-limit} is used instead.")
315 (non-negative-integer 0)
316 "Number of processes to always keep waiting for more connections.")
317 ;; FIXME: Need to be able to take the default for this value from other
318 ;; parts of the config.
320 (non-negative-integer #e256e6)
321 "If you set @samp{service-count 0}, you probably need to grow
324 (define (serialize-service-configuration field-name val)
325 (format #t "service ~a {\n" (service-configuration-kind val))
326 (serialize-configuration val (cdr service-configuration-fields))
328 (define (service-configuration-list? val)
329 (and (list? val) (and-map service-configuration? val)))
330 (define (serialize-service-configuration-list field-name val)
331 (for-each (lambda (val)
332 (serialize-service-configuration field-name val))
335 (define-configuration protocol-configuration
337 (string (configuration-missing-field 'protocol 'name))
338 "The name of the protocol.")
340 (string "/var/run/dovecot/auth-userdb")
341 "UNIX socket path to master authentication server to find users.
342 This is used by imap (for shared users) and lda.")
344 (space-separated-string-list '("$mail_plugins"))
345 "Space separated list of plugins to load.")
346 (mail-max-userip-connections
347 (non-negative-integer 10)
348 "Maximum number of IMAP connections allowed for a user from each IP
349 address. NOTE: The username is compared case-sensitively."))
351 (define (serialize-protocol-configuration field-name val)
352 (format #t "protocol ~a {\n" (protocol-configuration-name val))
353 (serialize-configuration val (cdr protocol-configuration-fields))
355 (define (protocol-configuration-list? val)
356 (and (list? val) (and-map protocol-configuration? val)))
357 (define (serialize-protocol-configuration-list field-name val)
358 (serialize-field 'protocols
359 (string-join (map protocol-configuration-name val) " "))
360 (for-each (lambda (val)
361 (serialize-protocol-configuration field-name val))
364 (define-configuration plugin-configuration
366 (free-form-fields '())
367 "A list of key-value pairs that this dict should hold."))
369 (define (serialize-plugin-configuration field-name val)
370 (format #t "plugin {\n")
371 (serialize-configuration val plugin-configuration-fields)
374 (define-configuration mailbox-configuration
376 (string (error "mailbox name is required"))
377 "Name for this mailbox.")
381 "@samp{create} will automatically create this mailbox.
382 @samp{subscribe} will both create and subscribe to the mailbox.")
385 (space-separated-string-list '())
386 "List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
387 Valid values are @code{\\All}, @code{\\Archive}, @code{\\Drafts},
388 @code{\\Flagged}, @code{\\Junk}, @code{\\Sent}, and @code{\\Trash}."))
390 (define (serialize-mailbox-configuration field-name val)
391 (format #t "mailbox \"~a\" {\n" (mailbox-configuration-name val))
392 (serialize-configuration val (cdr mailbox-configuration-fields))
394 (define (mailbox-configuration-list? val)
395 (and (list? val) (and-map mailbox-configuration? val)))
396 (define (serialize-mailbox-configuration-list field-name val)
397 (for-each (lambda (val)
398 (serialize-mailbox-configuration field-name val))
401 (define-configuration namespace-configuration
403 (string (error "namespace name is required"))
404 "Name for this namespace.")
408 "Namespace type: @samp{private}, @samp{shared} or @samp{public}.")
412 "Hierarchy separator to use. You should use the same separator for
413 all namespaces or some clients get confused. @samp{/} is usually a good
414 one. The default however depends on the underlying mail storage
419 "Prefix required to access this namespace. This needs to be
420 different for all namespaces. For example @samp{Public/}.")
424 "Physical location of the mailbox. This is in same format as
425 mail_location, which is also the default for it.")
429 "There can be only one INBOX, and this setting defines which
434 "If namespace is hidden, it's not advertised to clients via NAMESPACE
435 extension. You'll most likely also want to set @samp{list? #f}. This is mostly
436 useful when converting from another server with different namespaces
437 which you want to deprecate but still keep working. For example you can
438 create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
443 "Show the mailboxes under this namespace with LIST command. This
444 makes the namespace visible for clients that don't support NAMESPACE
445 extension. The special @code{children} value lists child mailboxes, but
446 hides the namespace prefix.")
450 "Namespace handles its own subscriptions. If set to @code{#f}, the
451 parent namespace handles them. The empty prefix should always have this
455 (mailbox-configuration-list '())
456 "List of predefined mailboxes in this namespace."))
458 (define (serialize-namespace-configuration field-name val)
459 (format #t "namespace ~a {\n" (namespace-configuration-name val))
460 (serialize-configuration val (cdr namespace-configuration-fields))
462 (define (list-of-namespace-configuration? val)
463 (and (list? val) (and-map namespace-configuration? val)))
464 (define (serialize-list-of-namespace-configuration field-name val)
465 (for-each (lambda (val)
466 (serialize-namespace-configuration field-name val))
469 (define-configuration dovecot-configuration
472 "The dovecot package.")
475 (comma-separated-string-list '("*" "::"))
476 "A list of IPs or hosts where to listen in for connections. @samp{*}
477 listens in all IPv4 interfaces, @samp{::} listens in all IPv6
478 interfaces. If you want to specify non-default ports or anything more
479 complex, customize the address and port fields of the
480 @samp{inet-listener} of the specific services you are interested in.")
483 (protocol-configuration-list
484 (list (protocol-configuration
486 "List of protocols we want to serve. Available protocols include
487 @samp{imap}, @samp{pop3}, and @samp{lmtp}.")
490 (service-configuration-list
492 (service-configuration
498 (inet-listener-configuration (protocol "imap") (port 143) (ssl? #f))
499 (inet-listener-configuration (protocol "imaps") (port 993) (ssl? #t)))))
500 (service-configuration
504 (inet-listener-configuration (protocol "pop3") (port 110) (ssl? #f))
505 (inet-listener-configuration (protocol "pop3s") (port 995) (ssl? #t)))))
506 (service-configuration
511 (list (unix-listener-configuration (path "lmtp") (mode "0666")))))
512 (service-configuration
515 (process-limit 1024))
516 (service-configuration
519 (process-limit 1024))
520 (service-configuration
526 (list (unix-listener-configuration (path "auth-userdb")))))
527 (service-configuration
531 (service-configuration
535 (listeners (list (unix-listener-configuration (path "dict")))))))
536 "List of services to enable. Available services include @samp{imap},
537 @samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
541 (dict-configuration (dict-configuration))
542 "Dict configuration, as created by the @code{dict-configuration}
546 (passdb-configuration-list (list (passdb-configuration (driver "pam"))))
547 "List of passdb configurations, each one created by the
548 @code{passdb-configuration} constructor.")
551 (userdb-configuration-list (list (userdb-configuration (driver "passwd"))))
552 "List of userdb configurations, each one created by the
553 @code{userdb-configuration} constructor.")
555 (plugin-configuration
556 (plugin-configuration (plugin-configuration))
557 "Plug-in configuration, created by the @code{plugin-configuration}
561 (list-of-namespace-configuration
563 (namespace-configuration
569 (mailbox-configuration (name "Drafts") (special-use '("\\Drafts")))
570 (mailbox-configuration (name "Junk") (special-use '("\\Junk")))
571 (mailbox-configuration (name "Trash") (special-use '("\\Trash")))
572 (mailbox-configuration (name "Sent") (special-use '("\\Sent")))
573 (mailbox-configuration (name "Sent Messages") (special-use '("\\Sent")))
574 (mailbox-configuration (name "Drafts") (special-use '("\\Drafts"))))))))
575 "List of namespaces. Each item in the list is created by the
576 @code{namespace-configuration} constructor.")
579 (file-name "/var/run/dovecot/")
580 "Base directory where to store runtime data.")
583 (string "Dovecot ready.")
584 "Greeting message for clients.")
586 (login-trusted-networks
587 (space-separated-string-list '())
588 "List of trusted network ranges. Connections from these IPs are
589 allowed to override their IP addresses and ports (for logging and for
590 authentication checks). @samp{disable-plaintext-auth} is also ignored
591 for these networks. Typically you'd specify your IMAP proxy servers
594 (login-access-sockets
595 (space-separated-string-list '())
596 "List of login access check sockets (e.g. tcpwrap).")
600 "Show more verbose process titles (in ps). Currently shows user name
601 and IP address. Useful for seeing who are actually using the IMAP
602 processes (e.g. shared mailboxes or if same uid is used for multiple
607 "Should all processes be killed when Dovecot master process shuts down.
608 Setting this to @code{#f} means that Dovecot can be upgraded without
609 forcing existing client connections to close (although that could also
610 be a problem if the upgrade is e.g. because of a security fix).")
612 (doveadm-worker-count
613 (non-negative-integer 0)
614 "If non-zero, run mail commands via this many connections to doveadm
615 server, instead of running them directly in the same process.")
618 (string "doveadm-server")
619 "UNIX socket or host:port used for connecting to doveadm server.")
622 (space-separated-string-list '("TZ"))
623 "List of environment variables that are preserved on Dovecot startup
624 and passed down to all of its child processes. You can also give
625 key=value pairs to always set specific settings.")
627 ;;; Authentication processes
629 (disable-plaintext-auth?
631 "Disable LOGIN command and all other plaintext authentications unless
632 SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
633 matches the local IP (i.e. you're connecting from the same computer),
634 the connection is considered secure and plaintext authentication is
635 allowed. See also ssl=required setting.")
638 (non-negative-integer 0)
639 "Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
640 Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
641 for caching to be used.")
645 "Time to live for cached data. After TTL expires the cached record
646 is no longer used, *except* if the main database lookup returns internal
647 failure. We also try to handle password changes automatically: If
648 user's previous authentication was successful, but this one wasn't, the
649 cache isn't used. For now this works only with plaintext
652 (auth-cache-negative-ttl
654 "TTL for negative hits (user not found, password mismatch).
655 0 disables caching them completely.")
658 (space-separated-string-list '())
659 "List of realms for SASL authentication mechanisms that need them.
660 You can leave it empty if you don't want to support multiple realms.
661 Many clients simply use the first one listed here, so keep the default
666 "Default realm/domain to use if none was specified. This is used for
667 both SASL realms and appending @@domain to username in plaintext
672 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@")
673 "List of allowed characters in username. If the user-given username
674 contains a character not listed in here, the login automatically fails.
675 This is just an extra check to make sure user can't exploit any
676 potential quote escaping vulnerabilities with SQL/LDAP databases. If
677 you want to allow all characters, set this value to empty.")
679 (auth-username-translation
681 "Username character translations before it's looked up from
682 databases. The value contains series of from -> to characters. For
683 example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
684 translated to @samp{@@}.")
686 (auth-username-format
688 "Username formatting before it's looked up from databases. You can
689 use the standard variables here, e.g. %Lu would lowercase the username,
690 %n would drop away the domain if it was given, or @samp{%n-AT-%d} would
691 change the @samp{@@} into @samp{-AT-}. This translation is done after
692 @samp{auth-username-translation} changes.")
694 (auth-master-user-separator
696 "If you want to allow master users to log in by specifying the master
697 username within the normal username string (i.e. not using SASL
698 mechanism's support for it), you can specify the separator character
699 here. The format is then <username><separator><master username>.
700 UW-IMAP uses @samp{*} as the separator, so that could be a good
703 (auth-anonymous-username
705 "Username to use for users logging in with ANONYMOUS SASL
708 (auth-worker-max-count
709 (non-negative-integer 30)
710 "Maximum number of dovecot-auth worker processes. They're used to
711 execute blocking passdb and userdb queries (e.g. MySQL and PAM).
712 They're automatically created and destroyed as needed.")
714 (auth-gssapi-hostname
716 "Host name to use in GSSAPI principal names. The default is to use
717 the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
718 allow all keytab entries.")
722 "Kerberos keytab to use for the GSSAPI mechanism. Will use the
723 system default (usually /etc/krb5.keytab) if not specified. You may
724 need to change the auth service to run as root to be able to read this
729 "Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
730 and @samp{ntlm-auth} helper.
731 <doc/wiki/Authentication/Mechanisms/Winbind.txt>.")
733 (auth-winbind-helper-path
734 (file-name "/usr/bin/ntlm_auth")
735 "Path for Samba's @samp{ntlm-auth} helper binary.")
739 "Time to delay before replying to failed authentications.")
741 (auth-ssl-require-client-cert?
743 "Require a valid SSL client certificate or the authentication
746 (auth-ssl-username-from-cert?
748 "Take the username from client's SSL certificate, using
749 @code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
753 (space-separated-string-list '("plain"))
754 "List of wanted authentication mechanisms. Supported mechanisms are:
755 @samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
756 @samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
757 @samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
758 @samp{disable-plaintext-auth} setting.")
761 (space-separated-string-list '())
762 "List of IPs or hostnames to all director servers, including ourself.
763 Ports can be specified as ip:port. The default port is the same as what
764 director service's @samp{inet-listener} is using.")
766 (director-mail-servers
767 (space-separated-string-list '())
768 "List of IPs or hostnames to all backend mail servers. Ranges are
769 allowed too, like 10.0.0.10-10.0.0.30.")
771 (director-user-expire
773 "How long to redirect users to a specific server after it no longer
774 has any connections.")
776 (director-username-hash
778 "How the username is translated before being hashed. Useful values
779 include %Ln if user can log in with or without @@domain, %Ld if mailboxes
780 are shared within domain.")
786 "Log file to use for error messages. @samp{syslog} logs to syslog,
787 @samp{/dev/stderr} logs to stderr.")
791 "Log file to use for informational messages. Defaults to
796 "Log file to use for debug messages. Defaults to
797 @samp{info-log-path}.")
801 "Syslog facility to use if you're logging to syslog. Usually if you
802 don't want to use @samp{mail}, you'll use local0..local7. Also other
803 standard facilities are supported.")
807 "Log unsuccessful authentication attempts and the reasons why they
810 (auth-verbose-passwords
812 "In case of password mismatches, log the attempted password. Valid
813 values are no, plain and sha1. sha1 can be useful for detecting brute
814 force password attempts vs. user simply trying the same password over
815 and over again. You can also truncate the value to n chars by appending
816 \":n\" (e.g. sha1:6).")
820 "Even more verbose logging for debugging purposes. Shows for example
823 (auth-debug-passwords?
825 "In case of password mismatches, log the passwords and used scheme so
826 the problem can be debugged. Enabling this also enables
831 "Enable mail process debugging. This can help you figure out why
832 Dovecot isn't finding your mails.")
836 "Show protocol level SSL errors.")
839 (string "\"%b %d %H:%M:%S \"")
840 "Prefix for each line written to log file. % codes are in
841 strftime(3) format.")
843 (login-log-format-elements
844 (space-separated-string-list
845 '("user=<%u>" "method=%m" "rip=%r" "lip=%l" "mpid=%e" "%c"))
846 "List of elements we want to log. The elements which have a
847 non-empty variable value are joined together to form a comma-separated
852 "Login log format. %s contains @samp{login-log-format-elements}
853 string, %$ contains the data we want to log.")
856 (string "\"%s(%u)<%{pid}><%{session}>: \"")
857 "Log prefix for mail processes. See doc/wiki/Variables.txt for list
858 of possible variables you can use.")
861 (string "msgid=%m: %$")
862 "Format to use for logging mail deliveries. You can use variables:
865 Delivery status message (e.g. @samp{saved to INBOX})
878 ;;; Mailbox locations and namespaces
882 "Location for users' mailboxes. The default is empty, which means
883 that Dovecot tries to find the mailboxes automatically. This won't work
884 if the user doesn't yet have any mail, so you should explicitly tell
885 Dovecot the full location.
887 If you're using mbox, giving a path to the INBOX
888 file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
889 where the other mailboxes are kept. This is called the \"root mail
890 directory\", and it must be the first path given in the
891 @samp{mail-location} setting.
893 There are a few special variables you can use, eg.:
899 user part in user@@domain, same as %u if there's no domain
901 domain part in user@@domain, empty if there's no domain
906 See doc/wiki/Variables.txt for full list. Some examples:
908 @item maildir:~/Maildir
909 @item mbox:~/mail:INBOX=/var/mail/%u
910 @item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
915 "System user and group used to access mails. If you use multiple,
916 userdb can override these by returning uid or gid fields. You can use
917 either numbers or names. <doc/wiki/UserIds.txt>.")
923 (mail-privileged-group
925 "Group to enable temporarily for privileged operations. Currently
926 this is used only with INBOX when either its initial creation or
927 dotlocking fails. Typically this is set to \"mail\" to give access to
932 "Grant access to these supplementary groups for mail processes.
933 Typically these are used to set up access to shared mailboxes. Note
934 that it may be dangerous to set these if users can create
935 symlinks (e.g. if \"mail\" group is set here, ln -s /var/mail ~/mail/var
936 could allow a user to delete others' mailboxes, or ln -s
937 /secret/shared/box ~/mail/mybox would allow reading it).")
939 (mail-full-filesystem-access?
941 "Allow full file system access to clients. There's no access checks
942 other than what the operating system does for the active UID/GID. It
943 works with both maildir and mboxes, allowing you to prefix mailboxes
944 names with e.g. /path/ or ~user/.")
950 "Don't use mmap() at all. This is required if you store indexes to
951 shared file systems (NFS or clustered file system).")
955 "Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
956 supports @samp{O_EXCL} since version 3, so this should be safe to use
957 nowadays by default.")
961 "When to use fsync() or fdatasync() calls:
964 Whenever necessary to avoid losing important data
966 Useful with e.g. NFS when write()s are delayed
968 Never use it (best performance, but crashes can lose data).
973 "Mail storage exists in NFS. Set this to yes to make Dovecot flush
974 NFS caches whenever needed. If you're using only a single mail server
979 "Mail index files also exist in NFS. Setting this to yes requires
980 @samp{mmap-disable? #t} and @samp{fsync-disable? #f}.")
984 "Locking method for index files. Alternatives are fcntl, flock and
985 dotlock. Dotlocking uses some tricks which may create more disk I/O
986 than other locking methods. NFS users: flock doesn't work, remember to
987 change @samp{mmap-disable}.")
991 "Directory in which LDA/LMTP temporarily stores incoming mails >128
995 (non-negative-integer 500)
996 "Valid UID range for users. This is mostly to make sure that users can't
997 log in as daemons or other system users. Note that denying root logins is
998 hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
1002 (non-negative-integer 0)
1006 (non-negative-integer 1)
1007 "Valid GID range for users. Users having non-valid GID as primary group ID
1008 aren't allowed to log in. If user belongs to supplementary groups with
1009 non-valid GIDs, those groups are not set.")
1012 (non-negative-integer 0)
1015 (mail-max-keyword-length
1016 (non-negative-integer 50)
1017 "Maximum allowed length for mail keyword name. It's only forced when
1018 trying to create new keywords.")
1021 (colon-separated-file-name-list '())
1022 "List of directories under which chrooting is allowed for mail
1023 processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
1024 too). This setting doesn't affect @samp{login-chroot}
1025 @samp{mail-chroot} or auth chroot settings. If this setting is empty,
1026 \"/./\" in home dirs are ignored. WARNING: Never add directories here
1027 which local users can modify, that may lead to root exploit. Usually
1028 this should be done only if you don't allow shell access for users.
1029 <doc/wiki/Chrooting.txt>.")
1033 "Default chroot directory for mail processes. This can be overridden
1034 for specific users in user database by giving /./ in user's home
1035 directory (e.g. /home/./user chroots into /home). Note that usually
1036 there is no real need to do chrooting, Dovecot doesn't allow users to
1037 access files outside their mail directory anyway. If your home
1038 directories are prefixed with the chroot directory, append \"/.\" to
1039 @samp{mail-chroot}. <doc/wiki/Chrooting.txt>.")
1042 (file-name "/var/run/dovecot/auth-userdb")
1043 "UNIX socket path to master authentication server to find users.
1044 This is used by imap (for shared users) and lda.")
1047 (file-name "/usr/lib/dovecot")
1048 "Directory where to look up mail plugins.")
1051 (space-separated-string-list '())
1052 "List of plugins to load for all services. Plugins specific to IMAP,
1053 LDA, etc. are added to this list in their own .conf files.")
1056 (mail-cache-min-mail-count
1057 (non-negative-integer 0)
1058 "The minimum number of mails in a mailbox before updates are done to
1059 cache file. This allows optimizing Dovecot's behavior to do less disk
1060 writes at the cost of more disk reads.")
1062 (mailbox-idle-check-interval
1064 "When IDLE command is running, mailbox is checked once in a while to
1065 see if there are any new mails or other changes. This setting defines
1066 the minimum time to wait between those checks. Dovecot can also use
1067 dnotify, inotify and kqueue to find out immediately when changes
1072 "Save mails with CR+LF instead of plain LF. This makes sending those
1073 mails take less CPU, especially with sendfile() syscall with Linux and
1074 FreeBSD. But it also creates a bit more disk I/O which may just make it
1075 slower. Also note that if other software reads the mboxes/maildirs,
1076 they may handle the extra CRs wrong and cause problems.")
1080 "By default LIST command returns all entries in maildir beginning
1081 with a dot. Enabling this option makes Dovecot return only entries
1082 which are directories. This is done by stat()ing each entry, so it
1083 causes more disk I/O.
1084 (For systems setting struct @samp{dirent->d_type} this check is free
1085 and it's done always regardless of this setting).")
1087 (maildir-copy-with-hardlinks?
1089 "When copying a message, do it with hard links whenever possible.
1090 This makes the performance much better, and it's unlikely to have any
1093 (maildir-very-dirty-syncs?
1095 "Assume Dovecot is the only MUA accessing Maildir: Scan cur/
1096 directory only when its mtime changes unexpectedly or when we can't find
1097 the mail otherwise.")
1100 (space-separated-string-list '("fcntl"))
1101 "Which locking methods to use for locking mbox. There are four
1106 Create <mailbox>.lock file. This is the oldest and most NFS-safe
1107 solution. If you want to use /var/mail/ like directory, the users will
1108 need write access to that directory.
1110 Same as dotlock, but if it fails because of permissions or because there
1111 isn't enough disk space, just skip it.
1113 Use this if possible. Works with NFS too if lockd is used.
1115 May not exist in all systems. Doesn't work with NFS.
1117 May not exist in all systems. Doesn't work with NFS.
1120 You can use multiple locking methods; if you do the order they're declared
1121 in is important to avoid deadlocks if other MTAs/MUAs are using multiple
1122 locking methods as well. Some operating systems don't allow using some of
1123 them simultaneously.")
1126 (space-separated-string-list '("dotlock" "fcntl"))
1131 "Maximum time to wait for lock (all of them) before aborting.")
1133 (mbox-dotlock-change-timeout
1135 "If dotlock exists but the mailbox isn't modified in any way,
1136 override the lock file after this much time.")
1140 "When mbox changes unexpectedly we have to fully read it to find out
1141 what changed. If the mbox is large this can take a long time. Since
1142 the change is usually just a newly appended mail, it'd be faster to
1143 simply read the new mails. If this setting is enabled, Dovecot does
1144 this but still safely fallbacks to re-reading the whole mbox file
1145 whenever something in mbox isn't how it's expected to be. The only real
1146 downside to this setting is that if some other MUA changes message
1147 flags, Dovecot doesn't notice it immediately. Note that a full sync is
1148 done with SELECT, EXAMINE, EXPUNGE and CHECK commands.")
1150 (mbox-very-dirty-syncs?
1152 "Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
1153 EXAMINE, EXPUNGE or CHECK commands. If this is set,
1154 @samp{mbox-dirty-syncs} is ignored.")
1158 "Delay writing mbox headers until doing a full write sync (EXPUNGE
1159 and CHECK commands and when closing the mailbox). This is especially
1160 useful for POP3 where clients often delete all mails. The downside is
1161 that our changes aren't immediately visible to other MUAs.")
1163 (mbox-min-index-size
1164 (non-negative-integer 0)
1165 "If mbox size is smaller than this (e.g. 100k), don't write index
1166 files. If an index file already exists it's still read, just not
1170 (non-negative-integer #e10e6)
1171 "Maximum dbox file size until it's rotated.")
1173 (mdbox-rotate-interval
1175 "Maximum dbox file age until it's rotated. Typically in days. Day
1176 begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
1179 (mdbox-preallocate-space?
1181 "When creating new mdbox files, immediately preallocate their size to
1182 @samp{mdbox-rotate-size}. This setting currently works only in Linux
1183 with some file systems (ext4, xfs).")
1185 (mail-attachment-dir
1187 "sdbox and mdbox support saving mail attachments to external files,
1188 which also allows single instance storage for them. Other backends
1189 don't support this for now.
1191 WARNING: This feature hasn't been tested much yet. Use at your own risk.
1193 Directory root where to store mail attachments. Disabled, if empty.")
1195 (mail-attachment-min-size
1196 (non-negative-integer #e128e3)
1197 "Attachments smaller than this aren't saved externally. It's also
1198 possible to write a plugin to disable saving specific attachments
1202 (string "sis posix")
1203 "File system backend to use for saving attachments:
1206 No SiS done by Dovecot (but this might help FS's own deduplication)
1208 SiS with immediate byte-by-byte comparison during saving
1209 @item sis-queue posix
1210 SiS with delayed comparison and deduplication.
1213 (mail-attachment-hash
1215 "Hash format to use in attachment filenames. You can add any text and
1216 variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
1217 @code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
1218 truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.")
1220 (default-process-limit
1221 (non-negative-integer 100)
1224 (default-client-limit
1225 (non-negative-integer 1000)
1229 (non-negative-integer #e256e6)
1230 "Default VSZ (virtual memory size) limit for service processes.
1231 This is mainly intended to catch and kill processes that leak memory
1232 before they eat up everything.")
1236 "Login user is internally used by login processes. This is the most
1237 untrusted user in Dovecot system. It shouldn't have access to anything
1240 (default-internal-user
1242 "Internal user is used by unprivileged processes. It should be
1243 separate from login user, so that login processes can't disturb other
1248 "SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.")
1251 (string "</etc/dovecot/default.pem")
1252 "PEM encoded X.509 SSL/TLS certificate (public key).")
1255 (string "</etc/dovecot/private/default.pem")
1256 "PEM encoded SSL/TLS private key. The key is opened before
1257 dropping root privileges, so keep the key file unreadable by anyone but
1262 "If key file is password protected, give the password here.
1263 Alternatively give it when starting dovecot with -p parameter. Since
1264 this file is often world-readable, you may want to place this setting
1265 instead to a different.")
1269 "PEM encoded trusted certificate authority. Set this only if you
1270 intend to use @samp{ssl-verify-client-cert? #t}. The file should
1271 contain the CA certificate(s) followed by the matching
1272 CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).")
1275 "Require that CRL check succeeds for client certificates.")
1276 (ssl-verify-client-cert?
1278 "Request client to send a certificate. If you also want to require
1279 it, set @samp{auth-ssl-require-client-cert? #t} in auth section.")
1281 (ssl-cert-username-field
1282 (string "commonName")
1283 "Which field from certificate to use for username. commonName and
1284 x500UniqueIdentifier are the usual choices. You'll also need to set
1285 @samp{auth-ssl-username-from-cert? #t}.")
1289 "Minimum SSL protocol version to accept.")
1292 (string "ALL:!kRSA:!SRP:!kDHd:!DSS:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK:!RC4:!ADH:!LOW@STRENGTH")
1293 "SSL ciphers to use.")
1297 "SSL crypto device to use, for valid values run \"openssl engine\".")
1300 (string "postmaster@%d")
1301 "Address to use when sending rejection mails.
1302 Default is postmaster@@<your domain>. %d expands to recipient domain.")
1306 "Hostname to use in various parts of sent mails (e.g. in Message-Id)
1307 and in LMTP replies. Default is the system's real hostname@@domain.")
1309 (quota-full-tempfail?
1311 "If user is over quota, return with temporary failure instead of
1312 bouncing the mail.")
1315 (file-name "/usr/sbin/sendmail")
1316 "Binary to use for sending mails.")
1320 "If non-empty, send mails via this SMTP host[:port] instead of
1324 (string "Rejected: %s")
1325 "Subject: header to use for rejection mails. You can use the same
1326 variables as for @samp{rejection-reason} below.")
1329 (string "Your message to <%t> was automatically rejected:%n%r")
1330 "Human readable error message for rejection mails. You can use
1344 (recipient-delimiter
1346 "Delimiter character between local-part and detail in email
1349 (lda-original-recipient-header
1351 "Header where the original recipient address (SMTP's RCPT TO:
1352 address) is taken from if not available elsewhere. With dovecot-lda -a
1353 parameter overrides this. A commonly used header for this is
1356 (lda-mailbox-autocreate?
1358 "Should saving a mail to a nonexistent mailbox automatically create
1361 (lda-mailbox-autosubscribe?
1363 "Should automatically created mailboxes be also automatically
1367 (imap-max-line-length
1368 (non-negative-integer #e64e3)
1369 "Maximum IMAP command line length. Some clients generate very long
1370 command lines with huge mailboxes, so you may need to raise this if you
1371 get \"Too long argument\" or \"IMAP command line too large\" errors
1375 (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}")
1376 "IMAP logout format string:
1379 total number of bytes read from client
1381 total number of bytes sent to client.
1383 See @file{doc/wiki/Variables.txt} for a list of all the variables you can use.")
1387 "Override the IMAP CAPABILITY response. If the value begins with '+',
1388 add the given capabilities on top of the defaults (e.g. +XFOO XBAR).")
1390 (imap-idle-notify-interval
1392 "How long to wait between \"OK Still here\" notifications when client
1397 "ID field names and values to send to clients. Using * as the value
1398 makes Dovecot use the default value. The following fields have default
1399 values currently: name, version, os, os-version, support-url,
1404 "ID fields sent by client to log. * means everything.")
1406 (imap-client-workarounds
1407 (space-separated-string-list '())
1408 "Workarounds for various client bugs:
1412 Send EXISTS/RECENT new mail notifications only when replying to NOOP and
1413 CHECK commands. Some clients ignore them otherwise, for example OSX
1414 Mail (<v2.1). Outlook Express breaks more badly though, without this it
1415 may show user \"Message no longer in server\" errors. Note that OE6
1416 still breaks even with this workaround if synchronization is set to
1419 @item tb-extra-mailbox-sep
1420 Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
1421 adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
1422 ignore the extra @samp{/} instead of treating it as invalid mailbox name.
1425 Show \\Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
1426 This makes Thunderbird realize they aren't selectable and show them
1427 greyed out, instead of only later giving \"not selectable\" popup error.
1433 "Host allowed in URLAUTH URLs sent by client. \"*\" allows all.") )
1435 (define-configuration opaque-dovecot-configuration
1438 "The dovecot package.")
1441 (string (configuration-missing-field 'opaque-dovecot-configuration
1443 "The contents of the @code{dovecot.conf} to use."))
1445 (define %dovecot-accounts
1446 ;; Account and group for the Dovecot daemon.
1447 (list (user-group (name "dovecot") (system? #t))
1452 (comment "Dovecot daemon user")
1453 (home-directory "/var/empty")
1454 (shell (file-append shadow "/sbin/nologin")))
1456 (user-group (name "dovenull") (system? #t))
1461 (comment "Dovecot daemon login user")
1462 (home-directory "/var/empty")
1463 (shell (file-append shadow "/sbin/nologin")))))
1465 (define (%dovecot-activation config)
1469 ((opaque-dovecot-configuration? config)
1470 (opaque-dovecot-configuration-string config))
1472 (with-output-to-string
1474 (serialize-configuration config
1475 dovecot-configuration-fields)))))))
1477 (use-modules (guix build utils))
1478 (define (mkdir-p/perms directory owner perms)
1480 (chown "/var/run/dovecot" (passwd:uid owner) (passwd:gid owner))
1481 (chmod directory perms))
1482 (define (build-subject parameters)
1485 (let ((k (car pair)) (v (cdr pair)))
1486 (define (escape-char str chr)
1487 (string-join (string-split str chr) (string #\\ chr)))
1488 (string-append "/" k "="
1489 (escape-char (escape-char v #\=) #\/))))
1490 (filter (lambda (pair) (cdr pair)) parameters))))
1491 (define* (create-self-signed-certificate-if-absent
1492 #:key private-key public-key (owner (getpwnam "root"))
1493 (common-name (gethostname))
1494 (organization-name "Guix")
1495 (organization-unit-name "Default Self-Signed Certificate")
1496 (subject-parameters `(("CN" . ,common-name)
1497 ("O" . ,organization-name)
1498 ("OU" . ,organization-unit-name)))
1499 (subject (build-subject subject-parameters)))
1500 ;; Note that by default, OpenSSL outputs keys in PEM format. This
1502 (unless (file-exists? private-key)
1504 ((zero? (system* (string-append #$openssl "/bin/openssl")
1505 "genrsa" "-out" private-key "2048"))
1506 (chown private-key (passwd:uid owner) (passwd:gid owner))
1507 (chmod private-key #o400))
1509 (format (current-error-port)
1510 "Failed to create private key at ~a.\n" private-key))))
1511 (unless (file-exists? public-key)
1513 ((zero? (system* (string-append #$openssl "/bin/openssl")
1514 "req" "-new" "-x509" "-key" private-key
1515 "-out" public-key "-days" "3650"
1516 "-batch" "-subj" subject))
1517 (chown public-key (passwd:uid owner) (passwd:gid owner))
1518 (chmod public-key #o444))
1520 (format (current-error-port)
1521 "Failed to create public key at ~a.\n" public-key)))))
1522 (let ((user (getpwnam "dovecot")))
1523 (mkdir-p/perms "/var/run/dovecot" user #o755)
1524 (mkdir-p/perms "/var/lib/dovecot" user #o755)
1525 (mkdir-p/perms "/etc/dovecot" user #o755)
1526 (copy-file #$(plain-file "dovecot.conf" config-str)
1527 "/etc/dovecot/dovecot.conf")
1528 (mkdir-p/perms "/etc/dovecot/private" user #o700)
1529 (create-self-signed-certificate-if-absent
1530 #:private-key "/etc/dovecot/private/default.pem"
1531 #:public-key "/etc/dovecot/default.pem"
1532 #:owner (getpwnam "root")
1533 #:common-name (format #f "Dovecot service on ~a" (gethostname)))))))
1535 (define (dovecot-shepherd-service config)
1536 "Return a list of <shepherd-service> for CONFIG."
1537 (let ((dovecot (if (opaque-dovecot-configuration? config)
1538 (opaque-dovecot-configuration-dovecot config)
1539 (dovecot-configuration-dovecot config))))
1540 (list (shepherd-service
1541 (documentation "Run the Dovecot POP3/IMAP mail server.")
1542 (provision '(dovecot))
1543 (requirement '(networking))
1544 (start #~(make-forkexec-constructor
1545 (list (string-append #$dovecot "/sbin/dovecot")
1547 (stop #~(make-forkexec-constructor
1548 (list (string-append #$dovecot "/sbin/dovecot")
1551 (define %dovecot-pam-services
1552 (list (unix-pam-service "dovecot")))
1554 (define dovecot-service-type
1555 (service-type (name 'dovecot)
1557 (list (service-extension shepherd-root-service-type
1558 dovecot-shepherd-service)
1559 (service-extension account-service-type
1560 (const %dovecot-accounts))
1561 (service-extension pam-root-service-type
1562 (const %dovecot-pam-services))
1563 (service-extension activation-service-type
1564 %dovecot-activation)))))
1566 (define* (dovecot-service #:key (config (dovecot-configuration)))
1567 "Return a service that runs @command{dovecot}, a mail server that can run
1568 POP3, IMAP, and LMTP. @var{config} should be a configuration object created
1569 by @code{dovecot-configuration}. @var{config} may also be created by
1570 @code{opaque-dovecot-configuration}, which allows specification of the
1571 @code{dovecot.conf} as a string."
1572 (validate-configuration config
1573 (if (opaque-dovecot-configuration? config)
1574 opaque-dovecot-configuration-fields
1575 dovecot-configuration-fields))
1576 (service dovecot-service-type config))
1578 ;; A little helper to make it easier to document all those fields.
1579 (define (generate-dovecot-documentation)
1580 (generate-documentation
1581 `((dovecot-configuration
1582 ,dovecot-configuration-fields
1583 (dict dict-configuration)
1584 (namespaces namespace-configuration)
1585 (plugin plugin-configuration)
1586 (passdbs passdb-configuration)
1587 (userdbs userdb-configuration)
1588 (services service-configuration)
1589 (protocols protocol-configuration))
1590 (dict-configuration ,dict-configuration-fields)
1591 (plugin-configuration ,plugin-configuration-fields)
1592 (passdb-configuration ,passdb-configuration-fields)
1593 (userdb-configuration ,userdb-configuration-fields)
1594 (unix-listener-configuration ,unix-listener-configuration-fields)
1595 (fifo-listener-configuration ,fifo-listener-configuration-fields)
1596 (inet-listener-configuration ,inet-listener-configuration-fields)
1597 (namespace-configuration
1598 ,namespace-configuration-fields
1599 (mailboxes mailbox-configuration))
1600 (mailbox-configuration ,mailbox-configuration-fields)
1601 (service-configuration
1602 ,service-configuration-fields
1603 (listeners unix-listener-configuration fifo-listener-configuration
1604 inet-listener-configuration))
1605 (protocol-configuration ,protocol-configuration-fields))
1606 'dovecot-configuration))
1613 (define-record-type* <opensmtpd-configuration>
1614 opensmtpd-configuration make-opensmtpd-configuration
1615 opensmtpd-configuration?
1616 (package opensmtpd-configuration-package
1617 (default opensmtpd))
1618 (config-file opensmtpd-configuration-config-file
1619 (default %default-opensmtpd-config-file)))
1621 (define %default-opensmtpd-config-file
1622 (plain-file "smtpd.conf" "
1624 accept from any for local deliver to mbox
1625 accept from local for any relay
1628 (define opensmtpd-shepherd-service
1630 (($ <opensmtpd-configuration> package config-file)
1631 (list (shepherd-service
1632 (provision '(smtpd))
1633 (requirement '(loopback))
1634 (documentation "Run the OpenSMTPD daemon.")
1635 (start (let ((smtpd (file-append package "/sbin/smtpd")))
1636 #~(make-forkexec-constructor
1637 (list #$smtpd "-f" #$config-file)
1638 #:pid-file "/var/run/smtpd.pid")))
1639 (stop #~(make-kill-destructor)))))))
1641 (define %opensmtpd-accounts
1649 (comment "SMTP Daemon")
1650 (home-directory "/var/empty")
1651 (shell (file-append shadow "/sbin/nologin")))
1656 (comment "SMTPD Queue")
1657 (home-directory "/var/empty")
1658 (shell (file-append shadow "/sbin/nologin")))))
1660 (define opensmtpd-activation
1662 (($ <opensmtpd-configuration> package config-file)
1663 (let ((smtpd (file-append package "/sbin/smtpd")))
1665 (use-modules (guix build utils))
1666 ;; Create mbox and spool directories.
1667 (mkdir-p "/var/mail")
1668 (mkdir-p "/var/spool/smtpd")
1669 (chmod "/var/spool/smtpd" #o711))))))
1671 (define %opensmtpd-pam-services
1672 (list (unix-pam-service "smtpd")))
1674 (define opensmtpd-service-type
1678 (list (service-extension account-service-type
1679 (const %opensmtpd-accounts))
1680 (service-extension activation-service-type
1681 opensmtpd-activation)
1682 (service-extension pam-root-service-type
1683 (const %opensmtpd-pam-services))
1684 (service-extension profile-service-type
1685 (compose list opensmtpd-configuration-package))
1686 (service-extension shepherd-root-service-type
1687 opensmtpd-shepherd-service)))))
1694 (define (mail-aliases-etc aliases)
1695 `(("aliases" ,(plain-file "aliases"
1696 ;; Ideally we'd use a format string like
1697 ;; "~:{~a: ~{~a~^,~}\n~}", but it gives a
1698 ;; warning that I can't figure out how to fix,
1699 ;; so we'll just use string-join below instead.
1700 (format #f "~:{~a: ~a\n~}"
1702 ((alias addresses ...)
1703 (list alias (string-join addresses ","))))
1706 (define mail-aliases-service-type
1708 (name 'mail-aliases)
1710 (list (service-extension etc-service-type mail-aliases-etc)))
1711 (compose concatenate)
1719 (define-record-type* <exim-configuration> exim-configuration
1720 make-exim-configuration
1722 (package exim-configuration-package ;<package>
1724 (config-file exim-configuration-config-file ;file-like
1727 (define %exim-accounts
1735 (comment "Exim Daemon")
1736 (home-directory "/var/empty")
1737 (shell (file-append shadow "/sbin/nologin")))))
1739 (define (exim-computed-config-file package config-file)
1740 (computed-file "exim.conf"
1741 #~(call-with-output-file #$output
1748 (file-append package "/etc/exim.conf")))))))
1750 (define exim-shepherd-service
1752 (($ <exim-configuration> package config-file)
1753 (list (shepherd-service
1754 (provision '(exim mta))
1755 (documentation "Run the exim daemon.")
1756 (requirement '(networking))
1757 (start #~(make-forkexec-constructor
1758 '(#$(file-append package "/bin/exim")
1760 #$(exim-computed-config-file package config-file))))
1761 (stop #~(make-kill-destructor)))))))
1763 (define exim-activation
1765 (($ <exim-configuration> package config-file)
1766 (with-imported-modules '((guix build utils))
1768 (use-modules (guix build utils))
1770 (let ((uid (passwd:uid (getpw "exim")))
1771 (gid (group:gid (getgr "exim"))))
1772 (mkdir-p "/var/spool/exim")
1773 (chown "/var/spool/exim" uid gid))
1775 (zero? (system* #$(file-append package "/bin/exim")
1776 "-bV" "-C" #$(exim-computed-config-file package config-file))))))))
1778 (define exim-profile
1779 (compose list exim-configuration-package))
1781 (define exim-service-type
1785 (list (service-extension shepherd-root-service-type exim-shepherd-service)
1786 (service-extension account-service-type (const %exim-accounts))
1787 (service-extension activation-service-type exim-activation)
1788 (service-extension profile-service-type exim-profile)
1789 (service-extension mail-aliases-service-type (const '()))))))
1793 ;;; GNU Mailutils IMAP4 Daemon.
1796 (define %default-imap4d-config-file
1797 (plain-file "imap4d.conf" "server localhost {};\n"))
1799 (define-record-type* <imap4d-configuration>
1800 imap4d-configuration make-imap4d-configuration imap4d-configuration?
1801 (package imap4d-configuration-package
1802 (default mailutils))
1803 (config-file imap4d-configuration-config-file
1804 (default %default-imap4d-config-file)))
1806 (define imap4d-shepherd-service
1808 (($ <imap4d-configuration> package config-file)
1809 (list (shepherd-service
1810 (provision '(imap4d))
1811 (requirement '(networking syslogd))
1812 (documentation "Run the imap4d daemon.")
1813 (start (let ((imap4d (file-append package "/sbin/imap4d")))
1814 #~(make-forkexec-constructor
1815 (list #$imap4d "--daemon" "--foreground"
1816 "--config-file" #$config-file))))
1817 (stop #~(make-kill-destructor)))))))
1819 (define imap4d-service-type
1823 "Run the GNU @command{imap4d} to serve e-mail messages through IMAP.")
1825 (list (service-extension
1826 shepherd-root-service-type imap4d-shepherd-service)))
1827 (default-value (imap4d-configuration))))