diff options
Diffstat (limited to 'gn/services')
-rw-r--r-- | gn/services/gitea-README | 17 | ||||
-rw-r--r-- | gn/services/gitea-container.scm | 94 | ||||
-rw-r--r-- | gn/services/gitea.service | 9 |
3 files changed, 120 insertions, 0 deletions
diff --git a/gn/services/gitea-README b/gn/services/gitea-README new file mode 100644 index 0000000..51be573 --- /dev/null +++ b/gn/services/gitea-README @@ -0,0 +1,17 @@ +SETUP: + +The setup process works like this: +Decide where you want the base directory for gitea + for example: /srv/services/gitea +# mkdir -p /srv/services +Make the directory itself writable +# chmod o+w /srv/services +Decide the user/group you want to own the directory and service and change the container +$ sed -i 's/1009/<insert-number>/g' gitea-container.scm + +for running the service: +see included gitea.service + +for upgrades: +# guix pull +# systemctl restart gitea.service diff --git a/gn/services/gitea-container.scm b/gn/services/gitea-container.scm new file mode 100644 index 0000000..bc861c0 --- /dev/null +++ b/gn/services/gitea-container.scm @@ -0,0 +1,94 @@ +(define-module (gn services gitea-container)) + +(use-modules (gnu) + (gn packages gitea) + (guix records) + (ice-9 match)) +(use-service-modules base networking shepherd) + +(define %GITEA_WORK_DIR "/var/lib/gitea") +(define-record-type* <gitea-configuration> + gitea-configuration + make-gitea-configuration + gitea-configuration? + (package gitea-configuration-package ; package + (default gitea)) + (work-dir gitea-configuration-work-dir ; string + (default %GITEA_WORK_DIR)) + (port gitea-configuration-port ; number + (default 3001))) + +(define gitea-activation + (match-lambda + (($ <gitea-configuration> package work-dir port) + #~(begin + (use-modules (guix build utils)) + (let ((%user (getpwnam "gitea"))) + ;; Prepare the environment for gitea: + ;; https://docs.gitea.io/en-us/install-from-binary/ + (unless (directory-exists? #$work-dir) + (mkdir-p #$work-dir) + ;; These two are supposed to be recursive. + (chown #$work-dir (passwd:uid %user) (passwd:gid %user)) + (chmod #$work-dir #o750))))))) + +(define gitea-shepherd-service + (match-lambda + (($ <gitea-configuration> package work-dir port) + (list (shepherd-service + (documentation "Run the Gitea server.") + (requirement '(networking)) + (provision '(gitea)) + (start #~(make-forkexec-constructor + (list + #$(file-append package "/bin/gitea") + "--port" #$(number->string port)) + #:environment-variables + (list (string-append "GITEA_WORK_DIR=" #$work-dir) + (string-append "HOME=" #$work-dir)) + #:user "gitea" + #:group "gitea")) + (stop #~(make-kill-destructor))))))) + +(define gitea-service-type + (service-type + (name 'gitea) + (extensions + (list (service-extension shepherd-root-service-type + gitea-shepherd-service) + (service-extension activation-service-type + gitea-activation))) + (description + "Run a Gitea server.") + (default-value (gitea-configuration)))) + + +(operating-system + (host-name "gitea") + (timezone "Etc/UTC") + (locale "en_US.utf8") + + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (target "does-not-matter"))) + (file-systems %base-file-systems) + ;; No firmware for VMs or containers. + (firmware '()) + + ;; The user and group names aren't important, but the user uid and group id + ;; NEED to match the directory outside of the container. + (users (cons (user-account + (name "gitea") + (group "gitea") + (system? #t) + (uid 1009)) + %base-user-accounts)) + + (groups (cons (user-group + (name "gitea") + (system? #t) + (id 1009)) + %base-groups)) + + (services (list (service dhcp-client-service-type) + (service gitea-service-type)))) diff --git a/gn/services/gitea.service b/gn/services/gitea.service new file mode 100644 index 0000000..3b54f85 --- /dev/null +++ b/gn/services/gitea.service @@ -0,0 +1,9 @@ +[Unit] +Description=Gitea git server and web ui +Wants=guix-daemon.service + +[Service] +ExecStart=$(/var/guix/profiles/per-user/efraim/current-guix/bin/guix system container /home/efraimf/workspace/guix-bioinformatics/gn/services/gitea-container.scm --share=/home/efraimf/tmp=/var/lib --network) + +[Install] +WantedBy=multi-user.target |