summaryrefslogtreecommitdiff
path: root/gnu/system/vm.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2024-01-20 14:55:46 +0100
committerLudovic Courtès <ludo@gnu.org>2024-02-10 23:21:07 +0100
commit9edbb2d7a40c9da7583a1046e39b87633459f656 (patch)
treee056280c955c0ab5e09fa3e3e0d1f6a1000458e3 /gnu/system/vm.scm
parent5f34796dc4a615c8fe496bbb9cc18a489bc5d107 (diff)
services: Add ‘virtual-build-machine’ service.
* gnu/services/virtualization.scm (<virtual-build-machine>): New record type. (%build-vm-ssh-port, %build-vm-secrets-port, %x86-64-intel-cpu-models): New variables. (qemu-cpu-model-for-date, virtual-build-machine-ssh-port) (virtual-build-machine-secrets-port): New procedures. (%minimal-vm-syslog-config, %virtual-build-machine-operating-system): New variables. (virtual-build-machine-default-image): (virtual-build-machine-account-name) (virtual-build-machine-accounts) (build-vm-shepherd-services) (initialize-build-vm-substitutes) (build-vm-activation) (virtual-build-machine-offloading-ssh-key) (virtual-build-machine-activation) (virtual-build-machine-secret-root) (check-vm-availability) (build-vm-guix-extension): New procedures. (initialize-hurd-vm-substitutes): Remove. (hurd-vm-activation): Rewrite in terms of ‘build-vm-activation’. * gnu/system/vm.scm (linux-image-startup-command): New procedure. (operating-system-for-image): Export. * gnu/tests/virtualization.scm (run-command-over-ssh): New procedure, extracted from… (run-childhurd-test): … here. [test]: Adjust accordingly. (%build-vm-os): New variable. (run-build-vm-test): New procedure. (%test-build-vm): New variable. * doc/guix.texi (Virtualization Services)[Virtual Build Machines]: New section. (Build Environment Setup): Add cross-reference. Change-Id: I0a47652a583062314020325aedb654f11cb2499c
Diffstat (limited to 'gnu/system/vm.scm')
-rw-r--r--gnu/system/vm.scm62
1 files changed, 61 insertions, 1 deletions
diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index ef4c1800585..fcfd1cdb485 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -71,6 +71,8 @@
71 #:export (virtualized-operating-system 71 #:export (virtualized-operating-system
72 system-qemu-image/shared-store-script 72 system-qemu-image/shared-store-script
73 73
74 linux-image-startup-command
75
74 virtual-machine 76 virtual-machine
75 virtual-machine? 77 virtual-machine?
76 virtual-machine-operating-system 78 virtual-machine-operating-system
@@ -132,7 +134,8 @@
132 (check? #f) 134 (check? #f)
133 (create-mount-point? #t))))) 135 (create-mount-point? #t)))))
134 136
135(define* (virtualized-operating-system os mappings 137(define* (virtualized-operating-system os
138 #:optional (mappings '())
136 #:key (full-boot? #f) volatile?) 139 #:key (full-boot? #f) volatile?)
137 "Return an operating system based on OS suitable for use in a virtualized 140 "Return an operating system based on OS suitable for use in a virtualized
138environment with the store shared with the host. MAPPINGS is a list of 141environment with the store shared with the host. MAPPINGS is a list of
@@ -316,6 +319,63 @@ useful when FULL-BOOT? is true."
316 319
317 (gexp->derivation "run-vm.sh" builder))) 320 (gexp->derivation "run-vm.sh" builder)))
318 321
322(define* (linux-image-startup-command image
323 #:key
324 (system (%current-system))
325 (target #f)
326 (qemu qemu-minimal)
327 (graphic? #f)
328 (cpu "max")
329 (cpu-count 1)
330 (memory-size 1024)
331 (port-forwardings '())
332 (date #f))
333 "Return a list-valued gexp representing the command to start QEMU to run
334IMAGE, assuming it uses the Linux kernel, and not sharing the store with the
335host."
336 (define os
337 ;; Note: 'image-operating-system' would return the wrong OS, before
338 ;; its root partition has been assigned a UUID.
339 (operating-system-for-image image))
340
341 (define kernel-arguments
342 #~(list #$@(if graphic? #~() #~("console=ttyS0"))
343 #+@(operating-system-kernel-arguments os "/dev/vda1")))
344
345 #~`(#+(file-append qemu "/bin/"
346 (qemu-command (or target system)))
347 ,@(if (access? "/dev/kvm" (logior R_OK W_OK))
348 '("-enable-kvm")
349 '())
350
351 "-cpu" #$cpu
352 #$@(if (> cpu-count 1)
353 #~("-smp" #$(string-append "cpus=" (number->string cpu-count)))
354 #~())
355 "-m" #$(number->string memory-size)
356 "-nic" #$(string-append
357 "user,model=virtio-net-pci,"
358 (port-forwardings->qemu-options port-forwardings))
359 "-kernel" #$(operating-system-kernel-file os)
360 "-initrd" #$(file-append os "/initrd")
361 "-append" ,(string-join #$kernel-arguments)
362 "-serial" "stdio"
363
364 #$@(if date
365 #~("-rtc"
366 #$(string-append "base=" (date->string date "~5")))
367 #~())
368
369 "-object" "rng-random,filename=/dev/urandom,id=guix-vm-rng"
370 "-device" "virtio-rng-pci,rng=guix-vm-rng"
371
372 "-drive"
373 ,(string-append "file=" #$(system-image image)
374 ",format=qcow2,if=virtio,"
375 "cache=writeback,werror=report,readonly=off")
376 "-snapshot"
377 "-no-reboot"))
378
319 379
320;;; 380;;;
321;;; High-level abstraction. 381;;; High-level abstraction.