about summary refs log tree commit diff
path: root/vms/cgit-vm.scm
blob: 6816930e768481a5d8c61d21634beb15bb6f93a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
;;; genenetwork-machines --- Guix configuration for genenetwork machines
;;; Copyright © 2024 Pjotr Prins <pjotr.prins@thebird.nl>
;;;
;;; This file is part of genenetwork-machines.
;;;
;;; genenetwork-machines is free software: you can redistribute it
;;; and/or modify it under the terms of the GNU General Public License
;;; as published by the Free Software Foundation, either version 3 of
;;; the License, or (at your option) any later version.
;;;
;;; genenetwork-machines is distributed in the hope that it will be
;;; useful, but WITHOUT ANY WARRANTY; without even the implied
;;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;;; See the GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with genenetwork-machines.  If not, see
;;; <https://www.gnu.org/licenses/>.

;;; CGIT as a SELF-CONTAINED VM.
;;;
;;; Unlike the full guix-forge stack (which brings acme, webhook,
;;; laminar and Anubis along), this VM only runs the slim cgit
;;; services from (genenetwork services cgit) -- cgit-pink behind
;;; fcgiwrap on a unix socket, foreground nginx, and the
;;; git-http-backend location for the smart HTTP protocol.  Those
;;; services are derived from guix-forge's (forge cgit)/(forge
;;; fcgiwrap)/(forge anubis), but avoid the stock nginx shepherd
;;; services that wedge system containers.
;;;
;;; A VM (unlike a system container) has its own writable disk, so
;;; state survives reboots and SSH host keys are generated at first
;;; boot.  Run it with:
;;;
;;;   qemu-system-x86_64 -m 1024 \
;;;     -drive file=/gnu/store/...-image.qcow2,format=qcow2 \
;;;     -netdev user,id=n0,hostfwd=tcp:127.0.0.1:8883-:8883,hostfwd=tcp:127.0.0.1:2224-:22 \
;;;     -device virtio-net-pci,netdev=n0 \
;;;     -nographic
;;;
;;; (-enable-kvm on the host for usable speed.)  Build the image with:
;;;
;;; ($base = a directory holding the checkouts side by side; adapt to
;;; your layout.)
;;;
;;;   guix system image -t qcow2 \
;;;     -L $base/guix-bioinformatics \
;;;     -L $base/gn-machines \
;;;     -L $base/contrib/guix-forge/guix \
;;;     $base/gn-machines/vms/cgit-vm.scm

(define-module (genenetwork services cgit-vm)
  #:use-module (gnu)
  #:use-module (genenetwork services cgit)
  #:use-module (gnu services base)
  #:use-module (gnu services networking)
  #:use-module (gnu services ssh)
  #:use-module (gnu packages version-control))

(use-service-modules ssh)
(use-package-modules base bash admin compression python version-control linux)

(define %cgit-web-config
  (cgit-web-configuration
   (root-title "GeneNetwork cgit")
   (root-desc "Git repositories for the GeneNetwork project")
   (repository-directory "/srv/git")))

(operating-system
  (host-name "cgit-vm")
  (timezone "Etc/UTC")
  (locale "en_US.utf8")
  (kernel-arguments '("console=ttyS0,115200"))
  (bootloader (bootloader-configuration
               (bootloader grub-bootloader)
               (targets '("/dev/vda"))))
  ;; The qcow2 image type creates a root partition labelled
  ;; "Guix_image" (hardcoded in gnu/system/image.scm).
  (file-systems (cons (file-system
                        (device (file-system-label "Guix_image"))
                        (mount-point "/")
                        (type "ext4"))
                      %base-file-systems))

  (users (cons (user-account
                (name "root")
                (uid 0)
                (group "root")
                (password (crypt "hello" "$6$abc$0123456789abcdef$")))
               %base-user-accounts))

  ;; Minimal packages: nginx, fcgiwrap and cgit come in through the
  ;; cgit services, ssh tools through the openssh service, 'herd'
  ;; through the essential shepherd service.  git seeds the demo
  ;; repository, gzip would serve cgit snapshots, python is needed by
  ;; cgit's md2html about-filter.
  (packages (list bash coreutils shadow grep procps git gzip python))

  (services
   (append
    (list
     ;; One shared configuration for both services (the nginx
     ;; front-end needs the same record to generate the cgitrc for
     ;; fcgiwrap's CGIT_CONFIG environment).
     (service cgit-web-service-type
              %cgit-web-config)
     (service cgit-nginx-service-type
              %cgit-web-config)
     ;; Seed the demo repository (shared with the cgit container).
     cgit-demo-repository-service

     ;; QEMU user-mode network stack (10.0.2.15, gateway 10.0.2.2).
     (service static-networking-service-type (list %qemu-static-networking))

     ;; Password-less root login with etc/hello-container-key on the
     ;; guest's port 22; the VM runner forwards a host port to it.
     ;; Host keys are generated at first boot and persist in the
     ;; (writable) image.
     (service openssh-service-type
              (openssh-configuration
               (permit-root-login #t)
               (password-authentication? #f)
               (authorized-keys
                `(("root" ,(local-file
                            "../../run-guix-container/etc/hello-container-key.pub"
                            "authorized_keys"))))))

     ;; Serial console login, for debugging when ssh does not work.
     (service agetty-service-type
              (agetty-configuration
               (extra-options '("-L"))
               (baud-rate "115200")
               (term "vt100")
               (tty "ttyS0"))))
    (modify-services %base-services
      ;; No guix-daemon in the VM: images are built on the host.
      (delete guix-service-type)))))