Compare commits

...

25 Commits

Author SHA1 Message Date
TakeV 511f0b7bd5
Fix frontend download link 2023-07-30 22:43:19 -07:00
TakeV b28b78bd92
Allow system container to use the network 2023-07-24 17:22:59 -07:00
TakeV f6880701e5
Helper script to run gts container 2023-07-24 17:20:17 -07:00
TakeV 282ad929ca
Update gotosocial 2023-07-24 00:55:01 -07:00
TakeV 8d6355d252
Add nginx to test container 2023-07-24 00:24:12 -07:00
TakeV ec9185f503
Add postgres requirement for gotosocial service 2023-07-24 00:06:28 -07:00
TakeV bd32605d84
Add gotosocial activation service 2023-07-23 23:53:59 -07:00
TakeV adcc79730a
Add nginx/certbot service extensions 2023-07-23 23:51:06 -07:00
TakeV c7acbbcf90
Add tests 2023-07-23 22:46:40 -07:00
TakeV 8fc7e960f2
Format GTS service 2023-07-23 22:46:16 -07:00
TakeV 52a832327b
Add dir-locals 2023-07-23 22:45:56 -07:00
TakeV 0ba79f37af
Add tests 2023-07-23 17:23:46 -07:00
TakeV e6ae17fe1d
Move gts service arguments into the forkexec gexp 2023-07-23 03:27:20 -07:00
TakeV e9ed901c92
Fix typo 2023-07-23 02:33:45 -07:00
TakeV 675e6d4130
Fix stray package 2023-07-23 02:31:06 -07:00
TakeV 8f540ddb55
Fix errors when building gotosocial 2023-07-23 02:27:04 -07:00
TakeV ea472eeb8a
Fix authorizations 2023-07-23 02:08:48 -07:00
TakeV 8c34be5660
Remove unneeded fields from gts service 2023-07-23 02:04:19 -07:00
TakeV 0c01e7cf52
Modernize the config 2023-07-23 02:04:19 -07:00
TakeV 758c175d9c
Pass frontend to service 2023-07-23 02:04:19 -07:00
TakeV 5b0bb26a92
Add gotosocial frontend 2023-07-23 02:04:19 -07:00
TakeV 2798041c31
Remove test file 2023-07-23 02:04:19 -07:00
TakeV 53b46de9e3
Buildable container 2023-07-23 02:04:19 -07:00
TakeV 9a6caabc73
Add GTS service (currently broke'd) 2023-07-23 02:04:18 -07:00
TakeV 080821eb8a
Add backend package for GoToSocial.
At present, this does not include the frontend assets.
2023-07-23 02:01:57 -07:00
7 changed files with 363 additions and 5 deletions

100
.dir-locals.el Normal file
View File

@ -0,0 +1,100 @@
;;; SPDX-License-Identifier: GPL-3.0-or-later
;; Per-directory local variables for GNU Emacs 23 and later.
((nil
. ((fill-column . 78)
(tab-width . 8)
(sentence-end-double-space . t)
;; For use with 'bug-reference-prog-mode'.
(bug-reference-url-format . "https://gitlab.com/nonguix/nonguix/issues/%s")
(bug-reference-bug-regexp
. "\\(#\\([0-9]+\\)\\)")))
(c-mode . ((c-file-style . "gnu")))
(scheme-mode
.
((indent-tabs-mode . nil)
(eval . (put 'eval-when 'scheme-indent-function 1))
(eval . (put 'call-with-prompt 'scheme-indent-function 1))
(eval . (put 'test-assert 'scheme-indent-function 1))
(eval . (put 'test-assertm 'scheme-indent-function 1))
(eval . (put 'test-equalm 'scheme-indent-function 1))
(eval . (put 'test-equal 'scheme-indent-function 1))
(eval . (put 'test-eq 'scheme-indent-function 1))
(eval . (put 'call-with-input-string 'scheme-indent-function 1))
(eval . (put 'guard 'scheme-indent-function 1))
(eval . (put 'lambda* 'scheme-indent-function 1))
(eval . (put 'substitute* 'scheme-indent-function 1))
(eval . (put 'match-record 'scheme-indent-function 2))
;; 'modify-phases' and its keywords.
(eval . (put 'modify-phases 'scheme-indent-function 1))
(eval . (put 'replace 'scheme-indent-function 1))
(eval . (put 'add-before 'scheme-indent-function 2))
(eval . (put 'add-after 'scheme-indent-function 2))
(eval . (put 'modify-services 'scheme-indent-function 1))
(eval . (put 'with-directory-excursion 'scheme-indent-function 1))
(eval . (put 'package 'scheme-indent-function 0))
(eval . (put 'origin 'scheme-indent-function 0))
(eval . (put 'build-system 'scheme-indent-function 0))
(eval . (put 'bag 'scheme-indent-function 0))
(eval . (put 'graft 'scheme-indent-function 0))
(eval . (put 'operating-system 'scheme-indent-function 0))
(eval . (put 'file-system 'scheme-indent-function 0))
(eval . (put 'manifest-entry 'scheme-indent-function 0))
(eval . (put 'manifest-pattern 'scheme-indent-function 0))
(eval . (put 'substitute-keyword-arguments 'scheme-indent-function 1))
(eval . (put 'with-store 'scheme-indent-function 1))
(eval . (put 'with-external-store 'scheme-indent-function 1))
(eval . (put 'with-error-handling 'scheme-indent-function 0))
(eval . (put 'with-mutex 'scheme-indent-function 1))
(eval . (put 'with-atomic-file-output 'scheme-indent-function 1))
(eval . (put 'call-with-compressed-output-port 'scheme-indent-function 2))
(eval . (put 'call-with-decompressed-port 'scheme-indent-function 2))
(eval . (put 'call-with-gzip-input-port 'scheme-indent-function 1))
(eval . (put 'call-with-gzip-output-port 'scheme-indent-function 1))
(eval . (put 'call-with-lzip-input-port 'scheme-indent-function 1))
(eval . (put 'call-with-lzip-output-port 'scheme-indent-function 1))
(eval . (put 'signature-case 'scheme-indent-function 1))
(eval . (put 'emacs-batch-eval 'scheme-indent-function 0))
(eval . (put 'emacs-batch-edit-file 'scheme-indent-function 1))
(eval . (put 'emacs-substitute-sexps 'scheme-indent-function 1))
(eval . (put 'emacs-substitute-variables 'scheme-indent-function 1))
(eval . (put 'with-derivation-narinfo 'scheme-indent-function 1))
(eval . (put 'with-derivation-substitute 'scheme-indent-function 2))
(eval . (put 'with-status-report 'scheme-indent-function 1))
(eval . (put 'with-status-verbosity 'scheme-indent-function 1))
(eval . (put 'mlambda 'scheme-indent-function 1))
(eval . (put 'mlambdaq 'scheme-indent-function 1))
(eval . (put 'syntax-parameterize 'scheme-indent-function 1))
(eval . (put 'with-monad 'scheme-indent-function 1))
(eval . (put 'mbegin 'scheme-indent-function 1))
(eval . (put 'mwhen 'scheme-indent-function 1))
(eval . (put 'munless 'scheme-indent-function 1))
(eval . (put 'mlet* 'scheme-indent-function 2))
(eval . (put 'mlet 'scheme-indent-function 2))
(eval . (put 'run-with-store 'scheme-indent-function 1))
(eval . (put 'run-with-state 'scheme-indent-function 1))
(eval . (put 'wrap-program 'scheme-indent-function 1))
(eval . (put 'with-imported-modules 'scheme-indent-function 1))
(eval . (put 'with-extensions 'scheme-indent-function 1))
(eval . (put 'with-database 'scheme-indent-function 2))
(eval . (put 'call-with-transaction 'scheme-indent-function 2))
(eval . (put 'call-with-container 'scheme-indent-function 1))
(eval . (put 'container-excursion 'scheme-indent-function 1))
(eval . (put 'eventually 'scheme-indent-function 1))
(eval . (put 'call-with-progress-reporter 'scheme-indent-function 1))
;; This notably allows '(' in Paredit to not insert a space when the
;; preceding symbol is one of these.
(eval . (modify-syntax-entry ?~ "'"))
(eval . (modify-syntax-entry ?$ "'"))
(eval . (modify-syntax-entry ?+ "'"))))
(emacs-lisp-mode . ((indent-tabs-mode . nil)))
(texinfo-mode . ((indent-tabs-mode . nil)
(fill-column . 72))))

View File

@ -1,6 +1,5 @@
(define-module (kulupu packages gotosocial)
#:use-module ((guix licenses)
#:prefix license:)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (gnu packages)
#:use-module (gnu packages golang)
#:use-module (gnu packages shells)
@ -9,14 +8,33 @@
#:use-module (guix download)
#:use-module (guix git-download)
#:use-module (guix gexp)
#:use-module (guix build-system copy)
#:use-module (guix build-system go))
(define-public gotosocial-frontend
(package
(name "gotosocial-frontend")
(version "0.10.0")
(source (origin
(method url-fetch)
(uri (string-append "https://github.com/superseriousbusiness/gotosocial/releases/download/v" version "/gotosocial_" version "_web-assets.tar.gz"))
(sha256
(base32
"1842qjb09s5rkyc1b2pwn45f3sl6dycjfzspd7z0gwh8l8dag2mm"))))
(build-system copy-build-system)
(arguments
(list #:install-plan #~'(("." "/gotosocial/web"))))
(synopsis "GoToSocial Frontend Assets")
(description "")
(home-page "")
(license license:agpl3)))
(define-public gotosocial
(let* ((import-path "github.com/superseriousbusiness/gotosocial")
(working-path (string-append "src/" import-path)))
(package
(name "gotosocial")
(version "0.8.0")
(version "0.10.0")
(source (origin
(method git-fetch)
(uri (git-reference
@ -26,7 +44,7 @@
(file-name (git-file-name name version))
(sha256
(base32
"1cxdk59r57hbg5pwpg5vhhdzwcgpa6jdwhhblhhyk7pq1ym386n1"))))
"07zf3f7ypr183d6wfy2q02vylfndwm25qg2mpb4shms0vkrswks8"))))
(build-system go-build-system)
(arguments
(list #:go go-1.20
@ -54,7 +72,7 @@
(add-before 'install-license-files 'chdir-back
(lambda _
(chdir (getenv "ORIG_DIR")))))))
(propagated-inputs (list python-minimal-wrapper zsh))
(propagated-inputs (list python-minimal-wrapper zsh gotosocial-frontend))
(home-page "https://github.com/superseriousbusiness/gotosocial")
(synopsis "GoToSocial")
(description

View File

@ -0,0 +1,171 @@
(define-module (kulupu services gotosocial)
#:use-module (guix gexp)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix records)
#:use-module (guix packages)
#: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 (gnu packages bash)
#:use-module (gnu packages base)
#:use-module (kulupu packages gotosocial)
#:use-module (ice-9 match)
#:export (gotosocial-service-type
gotosocial-configuration))
(define-maybe string)
(define-configuration gotosocial-configuration
(host
(string "localhost")
"Name to use as gotosocial host")
(gotosocial
(package gotosocial)
"The gotosocial package to use")
(frontend
(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")
(postgres?
(boolean #t)
"Set up postgres DB, use sqlite if false")
(nginx?
(boolean #t)
"Set up reverse proxy via nginx")
(https?
(boolean #t)
"Set up HTTPS via certbot")
(database-address
(string "/var/run/gotosocial/gts.db")
"Address of the database, default /var/run/gotosocial/gts.db")
(no-serialization))
(define (gotosocial-shepherd-service config)
(match-record config <gotosocial-configuration>
(gotosocial frontend config-file port work-dir run-dir host postgres? database-address)
(let* ((gts (file-append gotosocial "/bin/gotosocial")))
(list (shepherd-service
(documentation "Run GoToSocial")
(requirement `(networking ,@(if postgres? '(postgres) '())))
(provision '(gotosocial))
(start #~(make-forkexec-constructor
(list
(#$(file-append gotosocial "/bin/gotosocial")
"server" "start" "--syslog-enabled"
"--port=" (number->string #$port)
$#(when (not postgres?) "--db-type=sqlite")
"--db-address=" #$database-address
"--letsencrypt-cert-dir=" #$work-dir "/storage/certs"
"--storage-local-base-path=" #$work-dir "/storage"
"--web-asset-base-dir=" #$(file-append frontend "/gotosocial/web/assets")
"--web-template-base-dir=" #$(file-append frontend "/gotosocial/web/template")
"--host=" host))
#:user "gotosocial"
#:group "gotosocial"
#:directory #$work-dir))
(stop #~(make-kill-destructor)))))))
(define (gotosocial-postgresql-roles config)
(match-record config <gotosocial-configuration>
(postgres?)
(if postgres? (list (postgresql-role
(name "gotosocial")
(create-database? #t)))
'())))
(define (gotosocial-certbot config)
(match-record config <gotosocial-configuration>
(https? host nginx?)
(if (not https?) '()
(list (certificate-configuration
(domains (list host))
(deploy-hook (if nginx? %nginx-cert-deploy-hook %gotosocial-cert-deploy-hook)))))))
(define %nginx-cert-deploy-hook
(program-file
"nginx-cert-deploy-hook"
#~(let ((pid (call-with-input-file "/var/run/nginx/pid" read)))
(kill pid SIGHUP))))
(define %gotosocial-cert-deploy-hook
(program-file
"gotosocial-cert-deploy-hook"
(with-imported-modules '((guix build utils))
#~(begin (use-module (guix build utils))
(invoke "herd" "restart" "gotosocial")))))
(define (gotosocial-nginx config)
(match-record config <gotosocial-configuration>
(nginx? https? host run-dir)
(if (not nginx?) '()
(list (nginx-server-configuration
(listen (if https? '("443 ssl") '("80")))
(server-name (list host))
(ssl-certificate (if https? (string-append "/etc/letsencrypt/live/" host "/fullchain.pem") #f))
(ssl-certificate-key (if https? (string-append "/etc/letsencrypt/live/" host "/privkey.pem") #f))
(locations (list
(nginx-location-configuration
(uri "/")
(body `(,(string-append "proxy_pass http://unix:" run-dir "/gotosocial.socket;")
"proxy_set_header Host $host;"
"proxy_set_header X-Real_IP $remote_addr;"
"proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;"
"proxy_set_header X-Forwarded-Proto $scheme;"))))))))))
(define (gotosocial-activation config)
(match-record config <gotosocial-configuration>
(work-dir run-dir)
#~(begin
(use-modules (guix build utils)
(ice-9 string-fun))
(let* ((user (getpw "gotosocial"))
(user-id (passwd:uid user))
(group-id (passwd:gid user)))
(mkdir-p #$work-dir)
(mkdir-p #$run-dir)
(chown #$work-dir user-id group-id)
(chown #$run-dir user-id group-id)))))
(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-public gotosocial-service-type
(service-type
(name 'gotosocial)
(extensions
(list (service-extension shepherd-root-service-type gotosocial-shepherd-service)
(service-extension account-service-type gotosocial-accounts)
(service-extension activation-service-type gotosocial-activation)
(service-extension nginx-service-type gotosocial-nginx)
(service-extension certbot-service-type gotosocial-certbot)
(service-extension postgresql-role-service-type gotosocial-postgresql-roles)))
(description "Runs GoToSocial")
(default-value (gotosocial-configuration))))

View File

@ -0,0 +1,5 @@
(define-module (kulupu tests gotosocial)
#:use-module (kulupu services gotosocial)
#:use-module (kulupu packages gotosocial)
#:use-module (kulupu tests utils)
#:use-module (srfi srfi-64))

58
kulupu/tests/utils.scm Normal file
View File

@ -0,0 +1,58 @@
(define-module (kulupu tests utils)
#:use-module (gnu)
#:use-module (gnu services databases)
#:use-module (gnu services networking)
#:use-module (gnu packages databases)
#:use-module (gnu services ssh)
#:use-module (gnu services certbot)
#:use-module (gnu services web)
#:use-module (gnu packages linux)
#:use-module (gnu packages ssh)
#:use-module (kulupu services gotosocial))
(define %base-container-services
(cons
(service static-networking-service-type
(list (static-networking
(addresses
(list (network-address
(device "veth")
(value "10.0.0.2/24"))))
(routes
(list (network-route
(destination "default")
(gateway "10.0.0.1")))))))
%base-services))
(define-public %container-system
(operating-system
(kernel linux-libre-lts)
(host-name "localhost")
(bootloader (bootloader-configuration
(bootloader grub-bootloader)
(targets '("/dev/sdX"))))
;; It's fitting to support the equally bare bones -nographic
;; QEMU option, which also nicely sidesteps forcing QWERTY.
(kernel-arguments (list "console=ttyS0,115200"))
(file-systems (cons (file-system
(device (file-system-label "my-root"))
(mount-point "/")
(type "ext4"))
%base-file-systems))
(services %base-container-services)))
(define-public %gotosocial-container
(operating-system
(inherit %container-system)
(services (cons*
(service certbot-service-type
(certbot-configuration
(email "test@test.com")))
(service nginx-service-type)
(service postgresql-service-type
(postgresql-configuration
(postgresql postgresql-10)))
(service gotosocial-service-type)
%base-container-services))))
%gotosocial-container

3
run-container Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
sudo $(guix system container -N -L . kulupu/tests/utils.scm)

3
run-repl.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
guix repl -L . --listen=tcp:37146