diff options
author | Efraim Flashner | 2019-10-29 04:40:00 -0500 |
---|---|---|
committer | Efraim Flashner | 2019-10-29 04:40:00 -0500 |
commit | 53d26a57fdee57e3112f59b828f60143041bf5ba (patch) | |
tree | f9d7c70b04773f2cccb73ece7ecb59474a716af3 /gn | |
parent | cb302acb0e5108c4b5f0a80008725599570e25ec (diff) | |
download | guix-bioinformatics-53d26a57fdee57e3112f59b828f60143041bf5ba.tar.gz |
gn: Add gitea and service.
* gn/packages/gitea.scm (gita): New variable.
* gn/services/gitea-container.scm: New container.
* gn/services/gitea.service: Add systemd service.
Diffstat (limited to 'gn')
-rw-r--r-- | gn/packages/gitea.scm | 52 | ||||
-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 |
4 files changed, 172 insertions, 0 deletions
diff --git a/gn/packages/gitea.scm b/gn/packages/gitea.scm new file mode 100644 index 0000000..0447bb9 --- /dev/null +++ b/gn/packages/gitea.scm @@ -0,0 +1,52 @@ +(define-module (gn packages gitea) + #:use-module ((guix licenses) #:prefix license:) + #:use-module (guix packages) + #:use-module (guix download) + #:use-module (guix build-system trivial) + #:use-module (gnu packages bash) + #:use-module (gnu packages version-control)) + +(define-public gitea + (package + (name "gitea") + (version "1.9.4") + (source (origin + (method url-fetch) + (uri (string-append "https://github.com/go-gitea/gitea/releases" + "/download/v" version + "/gitea-" version "-linux-amd64")) + (sha256 + (base32 + "017bf09ym3244wqvqbpdqxmpnb7gs23fqn7h5k1vfcrwamfwc82n")))) + (build-system trivial-build-system) + (arguments + `(#:modules ((guix build utils)) + #:builder + (begin + (use-modules (guix build utils)) + (let* ((out (assoc-ref %outputs "out")) + (bin (string-append out "/bin")) + (target (string-append bin "/gitea")) + (git (assoc-ref %build-inputs "git")) + (bash (assoc-ref %build-inputs "bash")) + (path (getenv "PATH")) + (source (assoc-ref %build-inputs "source"))) + (copy-file source "gitea") + (chmod "gitea" #o555) + (install-file "gitea" bin) + (setenv "PATH" (string-append bash "/bin")) + (wrap-program target + `("PATH" ":" prefix (,(string-append git "/bin"))))) + #t))) + (native-inputs + `(("source" ,source))) + (inputs + `(("bash" ,bash-minimal) + ("git" ,git))) + (home-page "https://gitea.io/") + (synopsis "Self-hosted git service") + ;; TODO: Rewrite description + (description "Gitea is a painless self-hosted Git service. It is similar +to GitHub, Bitbucket, and GitLab.") + (supported-systems '("x86_64-linux")) + (license license:expat))) 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 |