summaryrefslogtreecommitdiff
path: root/rodion/services/agate.scm
blob: c8dff62c0f98adf83b79057b108f08d6719a6dcb (about) (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
(define-module (rodion services agate)
  #:use-module (guix records)
  #:use-module (guix gexp)
  #:use-module (ice-9 match)
  #:use-module (gnu services shepherd)
  #:use-module (gnu services admin)
  #:use-module (gnu system pam)
  #:use-module (gnu system shadow)
  #:use-module (gnu services)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages rust-apps)
  #:export (agate-configuration
            agate-configuration?
            agate-configuration-package
            agate-configuration-content
            agate-configuration-cert
            agate-configuration-key
            agate-configuration-addr
            agate-configuration-hostname
            agate-configuration-lang
            agate-configuration-silent
            agate-configuration-serve-secret
            agate-configuration-log-ip
            agate-configuration-user
            agate-configuration-group
            agate-configuration-log-file

            agate-service-type))

(define-record-type* <agate-configuration>
  agate-configuration make-agate-configuration
  agate-configuration?
  (package  agate-configuration-package
            (default agate))
  (content  agate-configuration-content
            (default "/srv/gemini"))
  (cert     agate-configuration-cert
            (default #f))
  (key      agate-configuration-key
            (default #f))
  (addr     agate-configuration-addr
            (default '("0.0.0.0:1965" "[::]:1965")))
  (hostname agate-configuration-hostname
            (default #f))
  (lang     agate-configuration-lang
            (default #f))
  (silent?  agate-configuration-silent
            (default #f))
  (serve-secret? agate-configuration-serve-secret
                 (default #f))
  (log-ip?  agate-configuration-log-ip
            (default #t))
  (user     agate-configuration-user
            (default "agate"))
  (group    agate-configuration-group
            (default "agate"))
  (log-file agate-configuration-log
            (default "/var/log/agate.log")))

(define agate-shepherd-service
  (match-lambda
    (($ <agate-configuration> package content cert key addr
                              hostname lang silent? serve-secret?
                              log-ip? user group log-file)
     (list (shepherd-service
            (provision '(agate))
            (requirement '(networking))
            (documentation "Run the agate Gemini server.")
            (start (let ((agate (file-append package "/bin/agate")))
                     #~(make-forkexec-constructor
                        (list #$agate
                              "--content" #$content
                              "--addr" #$@addr
			      "--certs" #$cert
                              #$@(if lang
                                     (list "--lang" lang)
                                     '())
                              #$@(if hostname
                                     (list "--hostname" hostname)
                                     '())
                              #$@(if silent? '("--silent") '())
                              #$@(if serve-secret? '("--serve-secret") '())
                              #$@(if log-ip? '("--log-ip") '()))
                        #:user #$user #:group #$group
                        #:log-file #$log-file)))
            (stop #~(make-kill-destructor)))))))

(define agate-accounts
  (lambda (config)
    (let ((group (agate-configuration-group config))
          (user (agate-configuration-user config)))
      `(,@(if (equal? group "agate")
              '()
              (list (user-group (name "agate") (system? #t))))
        ,(user-group
          (name group)
          (system? #t))
        ,(user-account
          (name user)
          (group group)
          (supplementary-groups '("agate"))
          (system? #t)
          (comment "agate server user")
          (home-directory "/var/empty")
          (shell (file-append shadow "/sbin/nologin")))))))

(define agate-service-type
  (service-type
   (name 'agate)
   (extensions
    (list (service-extension account-service-type
                             agate-accounts)
          (service-extension shepherd-root-service-type
                             agate-shepherd-service)))
   (default-value (agate-configuration))
   (description "Run Agate, a simple Gemini protocol server written in
Rust.")))