aboutsummaryrefslogtreecommitdiff
path: root/gn/services/mailman-container.scm
blob: 1afa08ae2f351eba864bfab4127ee11f729a9ec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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))))