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