Subject: [bug#76488] [PATCH 2/4] vm: ‘common-qemu-options’ splits command-line tokens.

From: Ludovic Courtès <[email-masked]>
Date: Sat, 22 Feb 2025 18:10:14 +0100

The result returned so far by ‘common-qemu-options’ assumed that it
would be passed to a shell.  This is the case when using
‘system-qemu-image/shared-store-script’ but possibly not in other cases.

* gnu/system/vm.scm (common-qemu-options): Add #:image-format.
[virtfs-option]: Return a list of strings instead of a single
"-virtfs xyz" string.  Update caller to use ‘append-map’.
Separate "-drive" string.

Change-Id: Ib07c27e2c4b2d222d7db2c612bb045d330bc7f68
---
 gnu/system/vm.scm | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index 1e3f72c7b2a..dbfe873e4f5 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2013-2024 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2013-2025 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2016 Christine Lemmer-Webber <[email-masked]>
 ;;; Copyright © 2016, 2017 Leo Famulari <[email-masked]>
 ;;; Copyright © 2017 Mathieu Othacehe <[email-masked]>
@@ -211,14 +211,16 @@ (define* (virtualized-operating-system os
 
 (define* (common-qemu-options image shared-fs
                               #:key
+                              (image-format "raw")
                               rw-image?
                               (target (%current-target-system)))
   "Return the a string-value gexp with the common QEMU options to boot IMAGE,
 with '-virtfs' options for the host file systems listed in SHARED-FS."
 
   (define (virtfs-option fs)
-    #~(format #f "-virtfs local,path=~s,security_model=none,mount_tag=~s"
-              #$fs #$(file-system->mount-tag fs)))
+    #~("-virtfs"
+       (format #f "local,path=~a,security_model=none,mount_tag=~a"
+               #$fs #$(file-system->mount-tag fs))))
 
   #~(;; Only enable kvm if we see /dev/kvm exists.
      ;; This allows users without hardware virtualization to still use these
@@ -230,11 +232,12 @@ (define* (common-qemu-options image shared-fs
      "-object" "rng-random,filename=/dev/urandom,id=guix-vm-rng"
      "-device" "virtio-rng-pci,rng=guix-vm-rng"
 
-     #$@(map virtfs-option shared-fs)
-     #$@(if rw-image?
-            #~((format #f "-drive file=~a,format=qcow2,if=virtio" #$image))
-            #~((format #f "-drive file=~a,format=raw,if=virtio,cache=writeback,werror=report,readonly=on"
-                       #$image)))))
+     #$@(append-map virtfs-option shared-fs)
+     "-drive"
+     #$(if rw-image?
+           #~(format #f "file=~a,format=qcow2,if=virtio" #$image)
+           #~(format #f "file=~a,format=~a,if=virtio,cache=writeback,werror=report,readonly=on"
+                     #$image #$image-format))))
 
 (define* (system-qemu-image/shared-store-script os
                                                 #:key
-- 
2.48.1