summaryrefslogtreecommitdiff
path: root/rodion
diff options
context:
space:
mode:
authorRodion Goritskov <rodion.goritskov@gmail.com>2024-06-07 01:36:37 +0400
committerRodion Goritskov <rodion.goritskov@gmail.com>2024-06-07 01:36:37 +0400
commitbffc0534d22a831f95a6c46ed7dcfd2c38a4d0a5 (patch)
tree2f5183b03dfc56635ca259f9667c8411ff4c108d /rodion
parent0130f144e8d7690a5b08118f402aa7a6be613902 (diff)
gnu: Add Agate service.
* rodion/services/agate.scm (Agate service): New variable.
Diffstat (limited to 'rodion')
-rw-r--r--rodion/services/agate.scm117
1 files changed, 117 insertions, 0 deletions
diff --git a/rodion/services/agate.scm b/rodion/services/agate.scm
new file mode 100644
index 0000000..c8dff62
--- /dev/null
+++ b/rodion/services/agate.scm
@@ -0,0 +1,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.")))