about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-09-27 16:12:45 +0000
committerPjotr Prins <pjotr.public01@thebird.nl>2026-09-30 09:52:27 +0200
commit4ab2ca41eed1ee5fecf39d55e6944be0eeff7d21 (patch)
tree721f9012d7baf9710fd51c5c3efe09f1d2fab5f1
parentec979b0bbecdaba26d6ed70b39f18cb0eb3f0986 (diff)
downloadgn-machines-4ab2ca41eed1ee5fecf39d55e6944be0eeff7d21.tar.gz
vms: add bnw-vm.scm, BNW as a self-contained 2 GiB VM
Alternative to bnw-container.scm for public deployments: a qcow2 disk
image contains only the system's closure (no host /gnu/store mount),
the disk is writable so state survives reboots, and RAM is bounded
explicitly (run qemu with -m 2048; peak during an 8-node
structure-learning run is ~210 MiB).

The BNW services (bnw-service-type, bnw-nginx-service-type) are
imported from (genenetwork services bnw-container), which now exports
them; the OS uses real VM plumbing (grub + Guix_image root label,
%qemu-static-networking, serial console, ssh with the pinned client
key; host keys are generated at first boot and persist in the
writable image).  User-visible ports: web 8881, ssh 22 (forward with
hostfwd).

Verified: image builds, boots under qemu (-m 2048), BNW serves HTTP
200 on 8881 and the workflow.php example loads.
-rw-r--r--genenetwork/services/bnw-container.scm4
-rw-r--r--vms/bnw-vm.scm121
2 files changed, 125 insertions, 0 deletions
diff --git a/genenetwork/services/bnw-container.scm b/genenetwork/services/bnw-container.scm
index 360386c..df4ae6d 100644
--- a/genenetwork/services/bnw-container.scm
+++ b/genenetwork/services/bnw-container.scm
@@ -44,6 +44,10 @@
 ;;; like php-fpm, which works fine.
 
 (define-module (genenetwork services bnw-container)
+  #:export (bnw-configuration
+            bnw-service-type
+            bnw-nginx-configuration
+            bnw-nginx-service-type)
   #:use-module (gnu)
   #:use-module (gn packages bnw)
   #:use-module (guix gexp)
diff --git a/vms/bnw-vm.scm b/vms/bnw-vm.scm
new file mode 100644
index 0000000..bb957c8
--- /dev/null
+++ b/vms/bnw-vm.scm
@@ -0,0 +1,121 @@
+;;; 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 services bnw-container) -- build with both channels
+;;; on the load path:
+;;;
+;;;   guix system image -t qcow2 \
+;;;     -L factory/code/guix-bioinformatics \
+;;;     -L factory/code/gn-machines \
+;;;     factory/code/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-container)
+  #: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)
+
+(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))
+
+  (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)))))