aboutsummaryrefslogtreecommitdiff
path: root/gn/services/mailman-container.scm
diff options
context:
space:
mode:
authorEfraim Flashner2020-04-28 05:44:02 -0500
committerEfraim Flashner2020-04-28 05:44:02 -0500
commit55ed6aaaac53876c0c398a13aa45b1e8a0530bbd (patch)
tree48ba6306d8be955e07def87a28e00a861fb11f3c /gn/services/mailman-container.scm
parent3b5182bdd5d9a24cbc15c47df6acbfdbc1c80d3a (diff)
downloadguix-bioinformatics-55ed6aaaac53876c0c398a13aa45b1e8a0530bbd.tar.gz
WIP mailman servicewip-mailman
Diffstat (limited to 'gn/services/mailman-container.scm')
-rw-r--r--gn/services/mailman-container.scm94
1 files changed, 94 insertions, 0 deletions
diff --git a/gn/services/mailman-container.scm b/gn/services/mailman-container.scm
new file mode 100644
index 0000000..1afa08a
--- /dev/null
+++ b/gn/services/mailman-container.scm
@@ -0,0 +1,94 @@
+(define-module (gn services mailman-container))
+
+(use-modules (gnu)
+ (gn packages mailman)
+ (guix records)
+ (ice-9 match))
+(use-service-modules base mcron networking shepherd)
+
+(define-record-type* <mailman-configuration>
+ mailman-configuration
+ make-mailman-configuration
+ mailman-configuration?
+ (package mailman-configuration-package ; package
+ (default mailman))
+ )
+
+(define mailman-cronjobs
+ (match-lambda
+ (($ <mailman-configuration> package)
+ (list
+ #~(job '(next-hour '(0))
+ (string-append #$package "/bin/mailman digests --periodic"))
+ #~(job '(next-hour '(8))
+ (string-append #$package "/bin/mailman notify"))))))
+
+(define mailman-activation
+ (match-lambda
+ (($ <mailman-configuration> package)
+ #~(begin
+ (use-modules (guix build utils))
+ (let ((%user (getpwnam "mailman")))
+ ;; Prepare the environment for mailman:
+ ;; https://docs.mailman.io/en-us/install-from-binary/
+ (unless (directory-exists? #$work-dir)
+ (mkdir-p #$work-dir)
+ ;; These two are supposed to be recursive.
+ (chown #$work-dir (passwd:uid %user) (passwd:gid %user))
+ (chmod #$work-dir #o750)))))))
+
+(define mailman-config-file
+ (plain-file "mailman.cfg"
+ "[mailman]
+layout: local
+\n"))
+
+(define mailman-shepherd-service
+ (match-lambda
+ (($ <mailman-configuration> package)
+ (list (shepherd-service
+ (documentation "Run the Mailman server.")
+ (requirement '(networking))
+ (provision '(mailman))
+ (start #~(make-forkexec-constructor
+ (list
+ #$(file-append package "/bin/mailman")
+ "start")
+ #:environment-variables
+ (list (string-append "MAILMAN_CONFIG_FILE" mailman-config-file)
+ )
+ ))
+ (stop #~(make-kill-destructor
+ (list
+ #$(file-append package "/bin/mailman")
+ "stop"))))))))
+
+(define mailman-service-type
+ (service-type
+ (name 'mailman)
+ (extensions
+ (list (service-extension shepherd-root-service-type
+ mailman-shepherd-service)
+ (service-extension activation-service-type
+ mailman-activation)
+ (service-extension mcron-service-type
+ mailman-cronjobs)))
+ (description
+ "Run a Mailman server.")
+ (default-value (mailman-configuration))))
+
+
+(operating-system
+ (host-name "mailman")
+ (timezone "Etc/UTC")
+ (locale "en_US.utf8")
+
+ (bootloader (bootloader-configuration
+ (bootloader grub-bootloader)
+ (target "does-not-matter")))
+ (file-systems %base-file-systems)
+ ;; No firmware for VMs or containers.
+ (firmware '())
+
+ (services (list (service dhcp-client-service-type)
+ (service mailman-service-type))))