* [PATCH] services: Add opensmtpd service.
@ 2016-11-24 13:55 宋文武
2016-11-25 22:58 ` Ludovic Courtès
0 siblings, 1 reply; 2+ messages in thread
From: 宋文武 @ 2016-11-24 13:55 UTC (permalink / raw)
To: guix-devel
* gnu/services/mail.scm (<opensmtpd-configuration>): New record type.
(%default-opensmtpd-config-file, %opensmtpd-accounts): New variables.
(opensmtpd-shepherd-service, opensmtpd-activation): New procedures.
(opensmtpd-service-type): New variable.
* doc/guix.texi (Mail Services): Document it.
---
doc/guix.texi | 42 ++++++++++++++++++++------
gnu/services/mail.scm | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 114 insertions(+), 10 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index 0055d09..fced4a4 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -10025,16 +10025,11 @@ For MariaDB, the root password is empty.
@cindex mail
@cindex email
The @code{(gnu services mail)} module provides Guix service definitions
-for mail services. Currently the only implemented service is Dovecot,
-an IMAP, POP3, and LMTP server.
+for email services: IMAP, POP3, and LMTP servers, as well as mail
+transport agents (MTAs). Lots of acronyms! These services are detailed
+in the subsections below.
-Guix does not yet have a mail transfer agent (MTA), although for some
-lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
-is needed to properly integrate a full MTA, such as Postfix. Patches
-welcome!
-
-To add an IMAP/POP3 server to a GuixSD system, add a
-@code{dovecot-service} to the operating system definition:
+@subsubheading Dovecot Service
@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
@@ -11390,6 +11385,35 @@ could instantiate a dovecot service like this:
(string "")))
@end example
+@subsubheading OpenSMTPD Service
+
+@deffn {Scheme Variable} opensmtpd-service-type
+This is the type of the @uref{https://www.opensmtpd.org, OpenSMTPD}
+service, whose value should be an @code{opensmtpd-configuration} object
+as in this example:
+
+@example
+(service opensmtpd-service-type
+ (opensmtpd-configuration
+ (config-file "/etc/smtpd.conf")))
+@end example
+@end deffn
+
+@deftp {Data Type} opensmtpd-configuraiton
+Data type regresenting the configuraiton of opensmtpd.
+
+@table @asis
+@item @code{package} (default: @var{opensmtpd})
+Package object of the OpenSMTPD SMTP server.
+
+@item @code{config-file} (default: @var{%default-opensmtpd-file})
+File-like object of the OpenSMTPD configuration file to use. By default
+it listens on the loopback network interface, and allows for mail from
+users and daemons on the local machine, as well as permitting email to
+remote servers. Run @command{man smtpd.conf} for more information.
+
+@end table
+@end deftp
@node Kerberos Services
@subsubsection Kerberos Services
diff --git a/gnu/services/mail.scm b/gnu/services/mail.scm
index cb0f119..f7ab951 100644
--- a/gnu/services/mail.scm
+++ b/gnu/services/mail.scm
@@ -51,7 +51,12 @@
protocol-configuration
plugin-configuration
mailbox-configuration
- namespace-configuration))
+ namespace-configuration
+
+ opensmtpd-configuration
+ opensmtpd-configuration?
+ opensmtpd-service-type
+ %default-opensmtpd-config-file))
;;; Commentary:
;;;
@@ -1691,3 +1696,78 @@ by @code{dovecot-configuration}. @var{config} may also be created by
(format #t "@end deftypevr\n\n")))
fields))))
(generate 'dovecot-configuration))
+
+\f
+;;;
+;;; OpenSMTPD.
+;;;
+
+(define-record-type* <opensmtpd-configuration>
+ opensmtpd-configuration make-opensmtpd-configuration
+ opensmtpd-configuration?
+ (package opensmtpd-configuration-package
+ (default opensmtpd))
+ (config-file opensmtpd-configuration-config-file
+ (default %default-opensmtpd-config-file)))
+
+(define %default-opensmtpd-config-file
+ (plain-file "smtpd.conf" "
+listen on lo
+accept from any for local deliver to mbox
+accept from local for any relay
+"))
+
+(define opensmtpd-shepherd-service
+ (match-lambda
+ (($ <opensmtpd-configuration> package config-file)
+ (list (shepherd-service
+ (provision '(smtpd))
+ (requirement '(loopback))
+ (documentation "Run the OpenSMTPD daemon.")
+ (start (let ((smtpd (file-append package "/sbin/smtpd")))
+ #~(make-forkexec-constructor
+ (list #$smtpd "-f" #$config-file)
+ #:pid-file "/var/run/smtpd.pid")))
+ (stop #~(make-kill-destructor)))))))
+
+(define %opensmtpd-accounts
+ (list (user-group
+ (name "smtpq")
+ (system? #t))
+ (user-account
+ (name "smtpd")
+ (group "nogroup")
+ (system? #t)
+ (comment "SMTP Daemon")
+ (home-directory "/var/empty")
+ (shell (file-append shadow "/sbin/nologin")))
+ (user-account
+ (name "smtpq")
+ (group "smtpq")
+ (system? #t)
+ (comment "SMTPD Queue")
+ (home-directory "/var/empty")
+ (shell (file-append shadow "/sbin/nologin")))))
+
+(define opensmtpd-activation
+ (match-lambda
+ (($ <opensmtpd-configuration> package config-file)
+ (let ((smtpd (file-append package "/sbin/smtpd")))
+ #~(begin
+ ;; Create mbox and spool directories.
+ (mkdir-p "/var/mail")
+ (mkdir-p "/var/spool/smtpd")
+ (chmod "/var/spool/smtpd" #o711))))))
+
+(define opensmtpd-service-type
+ (service-type
+ (name 'opensmtpd)
+ (extensions
+ (list (service-extension account-service-type
+ (const %opensmtpd-accounts))
+ (service-extension activation-service-type
+ opensmtpd-activation)
+ (service-extension profile-service-type
+ (compose list opensmtpd-configuration-package))
+ (service-extension shepherd-root-service-type
+ opensmtpd-shepherd-service)))))
--
2.10.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] services: Add opensmtpd service.
2016-11-24 13:55 [PATCH] services: Add opensmtpd service 宋文武
@ 2016-11-25 22:58 ` Ludovic Courtès
0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2016-11-25 22:58 UTC (permalink / raw)
To: 宋文武; +Cc: guix-devel
宋文武 <iyzsong@member.fsf.org> skribis:
> * gnu/services/mail.scm (<opensmtpd-configuration>): New record type.
> (%default-opensmtpd-config-file, %opensmtpd-accounts): New variables.
> (opensmtpd-shepherd-service, opensmtpd-activation): New procedures.
> (opensmtpd-service-type): New variable.
> * doc/guix.texi (Mail Services): Document it.
[...]
> +@example
> +(service opensmtpd-service-type
> + (opensmtpd-configuration
> + (config-file "/etc/smtpd.conf")))
Better suggest:
(config-file (local-file "./my-smtpd.conf"))
The above example would work but would not be referentially transparent
(which would prevent rollback, etc.)
> +@deftp {Data Type} opensmtpd-configuraiton
> +Data type regresenting the configuraiton of opensmtpd.
^^
“configuration of OpenSMTPD”.
OK with these changes, thank you!
Ludo’.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-11-25 22:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-24 13:55 [PATCH] services: Add opensmtpd service 宋文武
2016-11-25 22:58 ` Ludovic Courtès
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).