guix_mirror_bot pushed a commit to branch master
in repository guix.
commit 6fe171b45a46e79241e240dec99c9ff5f93d850a
Author: Sergio Pastor Pérez <[email protected]>
AuthorDate: Tue Jul 14 14:12:06 2026 +0200
vm: Add '--spice' flag.
* doc/guix.texi (Invoking guix system): Document '--spice' flag.
* gnu/packages/virtualization.scm (qemu): [native-search-paths]: Add
'XDG_DATA_DIRS'.
* gnu/system/vm.scm (virtualized-operating-system): Add 'spice?' keyword
argument to handle whether the 'spice-vdagent-service-type' needs to be
added
to the system.
(common-qemu-spice-options): New variable.
(system-qemu-image/shared-store-script): Add 'spice' keyword argument to
control the setup of spice in the VM startup script.
* guix/scripts/system.scm (system-derivation-for-action): Add 'spice'
keyword
argument.
(perform-action): Add 'spice' keyword argument.
(show-help): Add '--spice' flag docstring.
(%options): Handle '--spice' flag.
(process-action): Pass spice flag value.
Modified-by: Maxim Cournoyer <[email protected]>
---
doc/guix.texi | 12 ++++++++++++
gnu/packages/virtualization.scm | 6 ++++++
gnu/system/vm.scm | 32 +++++++++++++++++++++++++++++++-
guix/scripts/system.scm | 11 +++++++++++
4 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index dfd399953c8..cd99229183c 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -50884,6 +50884,18 @@ prefix to issue QEMU commands; e.g.@: @kbd{ctrl-a h}
prints a help,
@kbd{ctrl-a x} quits the VM, and @kbd{ctrl-a c} switches between the
QEMU monitor and the VM.
+The @option{--spice} option instructs @command{guix system} to spawn a
+VM with @uref{https://www.spice-space.org, Spice} support. This enables
+features such as clipboard sharing and automatic resolution resizing of
+the guest VM.
+
+This option ensures that the @code{spice-vdagent-service-type} is
+present in the VM system configuration and that QEMU is started with the
+necessary flags for communicating with the Spice agent. A compatible
+Spice viewer application will need to be available from the environment,
+such as the @command{remote-viewer} command provided by the
+@code{virt-viewer} package.
+
@cindex System images, creation in various formats
@cindex Creating system images in various formats
@item image
diff --git a/gnu/packages/virtualization.scm b/gnu/packages/virtualization.scm
index b0aed923dec..4d2f700cc41 100644
--- a/gnu/packages/virtualization.scm
+++ b/gnu/packages/virtualization.scm
@@ -45,6 +45,7 @@
;;; Copyright © 2025 Andreas Enge <[email protected]>
;;; Copyright © 2026 Nguyễn Gia Phong <[email protected]>
;;; Copyright © 2026 Cayetano Santos <[email protected]>
+;;; Copyright © 2026 Sergio Pastor Pérez <[email protected]>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -195,6 +196,7 @@
#:use-module (guix git-download)
#:use-module (guix packages)
#:use-module (guix modules)
+ #:use-module (guix search-paths)
#:use-module (guix utils)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
@@ -655,6 +657,10 @@ exec smbd $@")))
`(,glib "static")
`(,pcre2 "static")
`(,zlib "static"))))
+ ;; When using command-line options such as '-display spice-app', QEMU will
+ ;; search 'XDG_DATA_DIRS' for applications that can handle the relevant
+ ;; URI schema.
+ (native-search-paths (list $XDG_DATA_DIRS))
(home-page "https://www.qemu.org")
(synopsis "Machine emulator and virtualizer")
(description
diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index a6a05862a5c..89b25ae9b91 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -6,6 +6,7 @@
;;; Copyright © 2017 Marius Bakke <[email protected]>
;;; Copyright © 2018 Chris Marusich <[email protected]>
;;; Copyright © 2024 Zheng Junjie <[email protected]>
+;;; Copyright © 2026 Sergio Pastor Pérez <[email protected]>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -49,6 +50,7 @@
#:use-module (gnu packages virtualization)
#:use-module (gnu packages disk)
#:use-module (gnu packages linux)
+ #:use-module (gnu packages spice)
#:use-module (gnu bootloader)
#:use-module (gnu bootloader grub)
@@ -62,6 +64,7 @@
#:use-module (gnu system)
#:use-module (gnu services)
#:use-module (gnu services base)
+ #:use-module (gnu services spice)
#:use-module (gnu system uuid)
#:use-module ((srfi srfi-1) #:hide (partition))
@@ -141,7 +144,10 @@
(define* (virtualized-operating-system os
#:optional (mappings '())
- #:key (full-boot? #f) volatile?
+ #:key
+ (full-boot? #f)
+ spice?
+ volatile?
(system (%current-system))
(target (%current-target-system)))
"Return an operating system based on OS suitable for use in a virtualized
@@ -174,6 +180,17 @@ environment with the store shared with the host. MAPPINGS
is a list of
(operating-system
(inherit os)
+
+ (services
+ (if (and spice?
+ (not (find (lambda (service)
+ (eq? (service-kind service)
+ spice-vdagent-service-type))
+ services)))
+ (cons (service spice-vdagent-service-type)
+ services)
+ services))
+
(initrd (lambda (file-systems . rest)
(apply (operating-system-initrd os)
file-systems
@@ -240,6 +257,14 @@ with '-virtfs' options for the host file systems listed in
SHARED-FS."
#~(format #f
"file=~a,format=~a,if=virtio,cache=writeback,werror=report,readonly=on"
#$image #$image-format))))
+(define common-qemu-spice-options
+ '("-device" "virtio-serial"
+ "-chardev" "spicevmc,id=vdagent,name=vdagent"
+ "-device" "virtserialport,chardev=vdagent,name=com.redhat.spice.0"
+ "-display" "spice-app,gl=on"
+ "-device" "virtio-gpu-gl"
+ "-vga" "none"))
+
(define* (system-qemu-image/shared-store-script os
#:key
(system (%current-system))
@@ -250,6 +275,7 @@ with '-virtfs' options for the host file systems listed in
SHARED-FS."
(memory-size 512)
(mappings '())
full-boot?
+ spice
(disk-image-size
(* (if full-boot? 500 70)
(expt 2 20)))
@@ -269,6 +295,7 @@ parameter specifies the size in bytes of the root disk
image; it is mostly
useful when FULL-BOOT? is true."
(mlet* %store-monad ((os -> (virtualized-operating-system
os mappings
+ #:spice? spice
#:full-boot? full-boot?
#:volatile? volatile?
#:system system
@@ -297,6 +324,9 @@ useful when FULL-BOOT? is true."
(qemu-command (or target system))))
;; Tells qemu to use the terminal it was started in for IO.
#$@(if graphic? '() #~("-nographic"))
+ #$@(if (and graphic? spice)
+ common-qemu-spice-options
+ #~())
#$@(if full-boot?
#~()
#~("-kernel" #$(operating-system-kernel-file os)
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index 8277e24e5f7..635011f89c3 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -11,6 +11,7 @@
;;; Copyright © 2021 Brice Waegeneire <[email protected]>
;;; Copyright © 2021 Simon Tournier <[email protected]>
;;; Copyright © 2022 Tobias Geerinckx-Rice <[email protected]>
+;;; Copyright © 2026 Sergio Pastor Pérez <[email protected]>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -713,6 +714,7 @@ checking this by themselves in their 'check' procedure."
#:key
full-boot?
volatile?
+ (spice #f)
(graphic? #t)
container-shared-network?
mappings)
@@ -732,6 +734,7 @@ checking this by themselves in their 'check' procedure."
(system-qemu-image/shared-store-script os
#:full-boot? full-boot?
#:volatile? volatile?
+ #:spice spice
#:graphic? graphic?
#:disk-image-size image-size
#:mappings mappings))
@@ -794,6 +797,7 @@ and TARGET arguments."
load-for-kexec?
dry-run? derivations-only?
use-substitutes? target
+ spice
full-boot?
volatile-vm-root?
(graphic? #t)
@@ -851,6 +855,7 @@ static checks."
(mlet* %store-monad
((sys (system-derivation-for-action image action
+ #:spice spice
#:full-boot? full-boot?
#:volatile?
volatile-vm-root?
@@ -1049,6 +1054,8 @@ Some ACTIONS support additional ARGS.\n"))
register it as a garbage collector root"))
(display (G_ "
--full-boot for 'vm', make a full boot sequence"))
+ (display (G_ "
+ --spice for 'vm', configure for Spice support"))
(display (G_ "
--no-graphic for 'vm', use the tty that we are started in for IO"))
(display (G_ "
@@ -1144,6 +1151,9 @@ Some ACTIONS support additional ARGS.\n"))
(option '("full-boot") #f #f
(lambda (opt name arg result)
(alist-cons 'full-boot? #t result)))
+ (option '("spice") #f #f
+ (lambda (opt name arg result)
+ (alist-cons 'spice #t result)))
(option '("no-graphic") #f #f
(lambda (opt name arg result)
(alist-cons 'no-graphic? #t result)))
@@ -1371,6 +1381,7 @@ resulting from command-line parsing."
(assoc-ref opts 'skip-safety-checks?)
#:validate-reconfigure
(assoc-ref opts 'validate-reconfigure)
+ #:spice (assoc-ref opts 'spice)
#:full-boot? (assoc-ref opts 'full-boot?)
#:volatile-vm-root?
(assoc-ref opts 'volatile-vm-root?)