[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/02: services: Add opensmtpd service.

From: ???
Subject: 01/02: services: Add opensmtpd service.
Date: Sat, 26 Nov 2016 04:50:52 +0000 (UTC)

iyzsong pushed a commit to branch master
in repository guix.

commit f88371e86602a9b3d86f2030709f719778613552
Author: 宋文武 <address@hidden>
Date:   Mon Nov 21 20:41:17 2016 +0800

    services: Add opensmtpd service.
    * 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 b8e3705..137fec8 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -10075,16 +10075,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
-To add an IMAP/POP3 server to a GuixSD system, add a
address@hidden to the operating system definition:
address@hidden Dovecot Service
 @deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
 Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
@@ -11440,6 +11435,35 @@ could instantiate a dovecot service like this:
                   (string "")))
 @end example
address@hidden OpenSMTPD Service
address@hidden {Scheme Variable} opensmtpd-service-type
+This is the type of the @uref{, OpenSMTPD}
+service, whose value should be an @code{opensmtpd-configuration} object
+as in this example:
+(service opensmtpd-service-type
+         (opensmtpd-configuration
+           (config-file (local-file "./my-smtpd.conf"))))
address@hidden example
address@hidden deffn
address@hidden {Data Type} opensmtpd-configuration
+Data type regresenting the configuration of opensmtpd.
address@hidden @asis
address@hidden @code{package} (default: @var{opensmtpd})
+Package object of the OpenSMTPD SMTP server.
address@hidden @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.
address@hidden table
address@hidden 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 @@
-            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")))
   (generate 'dovecot-configuration))
+;;; 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/")))
+            (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)))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]