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
|
;;; 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/>.
;;; BNW as a SELF-CONTAINED VM (alternative to bnw-container.scm).
;;;
;;; The container shares the host's whole /gnu/store read-only; a
;;; qcow2 disk image contains only this system's closure, so a VM is
;;; the right shape for a PUBLIC deployment: nothing of the host is
;;; mounted, the disk is writable (state survives reboots), and RAM
;;; is bounded explicitly -- this VM is sized for 2 GiB:
;;;
;;; qemu-system-x86_64 -m 2048 \
;;; -drive file=/gnu/store/...-image.qcow2,format=qcow2 \
;;; -netdev user,id=n0,hostfwd=tcp:127.0.0.1:8881-:8881,hostfwd=tcp:127.0.0.1:2222-:22 \
;;; -device virtio-net-pci,netdev=n0 \
;;; -nographic
;;;
;;; (use -enable-kvm on the host for usable speed; TCG works but is
;;; slow. Peak memory during an 8-node structure-learning run is
;;; ~210 MiB, so 2 GiB leaves ample headroom for larger datasets.)
;;;
;;; The BNW services (bnw-service-type, bnw-nginx-service-type with
;;; the foreground-nginx fix) are imported from
;;; (genenetwork containers bnw-container) -- build with both channels
;;; on the load path:
;;;
;;; ($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 \
;;; $base/gn-machines/vms/bnw-vm.scm
;;;
;;; ssh: guest port 22 (forward to a host port with hostfwd), root
;;; login with etc/hello-container-key. Host keys are generated at
;;; first boot and persist in the writable image.
(define-module (genenetwork services bnw-vm)
#:use-module (gnu)
#:use-module (genenetwork services bnw)
#:use-module (gnu services base)
#:use-module (gnu services ssh)
#:use-module (gnu services networking))
(use-service-modules ssh)
(use-package-modules base bash admin linux)
(operating-system
(host-name "bnw-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, php-fpm and bnw come in through the
;; bnw/bnw-nginx services, ssh tools through the openssh service,
;; 'herd' through the essential shepherd service.
(packages (list bash coreutils shadow grep procps))
(services
(append
(list
(service bnw-service-type)
(service bnw-nginx-service-type)
;; 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 -- no pinning needed.
(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)))))
|