Compare commits

...

2 Commits

Author SHA1 Message Date
TakeV ce5f3477cd
Remove unneeded fields from gts service 2023-07-23 02:01:07 -07:00
TakeV 326bc8dbce
Modernize the config 2023-07-22 23:47:18 -07:00
2 changed files with 72 additions and 55 deletions

View File

@ -1,6 +1,5 @@
(define-module (kulupu packages gotosocial) (define-module (kulupu packages gotosocial)
#:use-module ((guix licenses) #:use-module ((guix licenses) #:prefix license:)
#:prefix license:)
#:use-module (gnu packages) #:use-module (gnu packages)
#:use-module (gnu packages golang) #:use-module (gnu packages golang)
#:use-module (gnu packages shells) #:use-module (gnu packages shells)

View File

@ -2,77 +2,95 @@
#:use-module (guix gexp) #:use-module (guix gexp)
#:use-module (guix records) #:use-module (guix records)
#:use-module (gnu services) #:use-module (gnu services)
#:use-module (gnu services certbot)
#:use-module (gnu services configuration)
#:use-module (gnu services databases)
#:use-module (gnu services base) #:use-module (gnu services base)
#:use-module (gnu services shepherd) #:use-module (gnu services shepherd)
#:use-module (gnu services web)
#:use-module (gnu system shadow) #:use-module (gnu system shadow)
#:use-module (gnu packages admin) #:use-module (gnu packages admin)
#:use-module (kulupu packages gotosocial) #:use-module (kulupu packages gotosocial)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:export (gotosocial-shepherd-service #:export (gotosocial-service-type
gotosocial-service-type gotosocial-configuration))
gts-config
gts-config?))
(define-record-type* <gts-config> gts-config (define-maybe string)
make-gts-config
gts-config?
(pkg gotosocial-configuration-package (default gotosocial))
(front-end gotosocial-configuration-frontend-package (default gotosocial-frontend))
(config-file gotosocial-configuration-config (default #f)) ; file-like
(port gotosocial-port (default #f))
(cert-dir gotosocial-letsencrypt-cert-dir (default #f))
(storage-dir gotosocial-storage-local-base-path (default #f))
(web-asset-dir gotosocial-web-asset-dir (default #f))
(web-template-dir gotosocial-template-asset-dir (default #f))
(host gotosocial-host (default #f))
(db-type gotosocial-db-type (default #f))
(db-address gotosocial-db-address (default #f)))
(define gotosocial-shepherd-service (define-configuration gotosocial-configuration
(match-lambda (($ <gts-config> pkg front-end config-file port cert-dir storage-dir web-asset-dir web-template-dir host db-type db-address) (host
(let* ((gts (file-append pkg "/bin/gotosocial")) (string "localhost")
(gts-frontend-assets (file-append front-end "/gotosocial/web/assets")) "Name to use as gotosocial host")
(gts-frontend-templates (file-append front-end "/gotosocial/web/template")) (gotosocial
(package gotosocial)
"The gotosocial package to use")
(front-end
(package gotosocial-frontend)
"The gotosocial web asset package to use")
(config-file
(maybe-string)
"Path to configuration file, defaults to no configuration file")
(port
(integer 8080)
"Port to listen on, default 8080")
(work-dir
(string "/var/lib/gotosocial")
"GTS work directory")
(run-dir
(string "/var/run/gotosocial")
"GTS runtime directory")
(database-type
(string "sqlite")
"Database type to use, default to sqlite")
(database-address
(string "/var/run/gotosocial/gts.db")
"Address of the database, default /var/run/gotosocial/gts.db"))
(define (gotosocial-shepherd-service config)
(match-record config <gotosocial-configuration>
(gotosocial gotosocial-frontend config-file port work-dir run-dir host database-type database-address)
(let* ((gts (file-append gotosocial "/bin/gotosocial"))
(gts-frontend-assets (file-append gotosocial-frontend "/gotosocial/web/assets"))
(gts-frontend-templates (file-append gotosocial-frontend "/gotosocial/web/template"))
(command `(,gts (command `(,gts
"server" "start" "--syslog-enabled" "server" "start" "--syslog-enabled"
,@(if port `(,(string-append "--port=" (number->string port))) '()) ,(string-append "--port=" (number->string port))
,@(if db-type `(,(string-append "--db-type=" db-type)) '()) ,(string-append "--db-type=" database-type)
,@(if db-address `(,(string-append "--db-address=" db-address)) '()) ,(string-append "--db-address=" database-address)
,@(if cert-dir `(,(string-append "--letsencrypt-cert-dir=" cert-dir)) '()) ,(string-append "--letsencrypt-cert-dir=" work-dir "/storage/certs")
,@(if storage-dir `(,(string-append "--storage-local-base-path=" storage-dir)) '()) ,(string-append "--storage-local-base-path=" work-dir "/storage")
,@(if web-asset-dir `(,(string-append "--web-asset-base-dir=" web-asset-dir)) '(,(string-append "--web-asset-base-dir=" gts-frontend-assets))) ,(string-append "--web-asset-base-dir=" gts-frontend-assets)
,@(if web-template-dir `(,(string-append "--web-template-base-dir=" web-template-dir)) '(,(string-append "--web-template-base-dir=" gts-frontend-templates))) ,(string-append "--web-template-base-dir=" gts-frontend-templates)
,@(if config-file `(,(string-append "--config-path=" config-file)) '()) ,(string-append "--host=" host))))
,@(if host `(,(string-append "--host=" host)) '())
)))
(list (shepherd-service (list (shepherd-service
(documentation "Run GoToSocial") (documentation "Run GoToSocial")
;(requirement '(networking)) (provision '(gotosocial))
(provision '(gotosocial-server))
(start #~(make-forkexec-constructor '#$command (start #~(make-forkexec-constructor '#$command
#:user "gotosocial" #:user "gotosocial"
#:group "gotosocial")) #:group "gotosocial"
(stop #~(make-kill-destructor)))))))) #:directory #$work-dir))
(stop #~(make-kill-destructor)))))))
(define %gotosocial-server-account
(list (user-group (define (gotosocial-accounts config)
(name "gotosocial") (match-record config <gotosocial-configuration>
(system? #t)) (work-dir)
(user-account (list (user-group
(name "gotosocial") (name "gotosocial")
(system? #t) (system? #t))
(group "gotosocial") (user-account
(comment "GoToSocial server user") (name "gotosocial")
(home-directory "/var/empty/") (system? #t)
(shell (file-append shadow "/sbin/nologin"))))) (group "gotosocial")
(comment "GoToSocial server user")
(home-directory work-dir)
(shell (file-append bash-minimal "/bin/bash"))))))
(define gotosocial-service-type (define gotosocial-service-type
(service-type (service-type
(name 'gotosocial) (name 'gotosocial)
(extensions (extensions
(list (service-extension shepherd-root-service-type (list (service-extension shepherd-root-service-type gotosocial-shepherd-service)
gotosocial-shepherd-service) (service-extension account-service-type gotosocial-accounts)))
(service-extension account-service-type
(const %gotosocial-server-account))))
(description "Runs GoToSocial") (description "Runs GoToSocial")
(default-value (gts-config)))) (default-value (gotosocial-configuration))))