~ruther/guix-local

f634a0baab85454a6feac25e29905f564b276c9e — Timotej Lazar 4 years ago 0c21ec1
services: Add qemu-guest-agent service.

* gnu/services/virtualization.scm (<qemu-guest-agent-configuration>): New
record.
(qemu-guest-agent-shepherd-service): New procedure.
(qemu-guest-agent-service-type): New variable.
* doc/guix.texi (Virtualization Services): Document it.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2 files changed, 94 insertions(+), 1 deletions(-)

M doc/guix.texi
M gnu/services/virtualization.scm
M doc/guix.texi => doc/guix.texi +47 -0
@@ 30060,6 30060,53 @@ Return the name of @var{platform}---a string such as @code{"arm"}.
@end deffn


@subsubheading QEMU Guest Agent

@cindex emulation

The QEMU guest agent provides control over the emulated system to the
host.  The @code{qemu-guest-agent} service runs the agent on Guix
guests.  To control the agent from the host, open a socket by invoking
QEMU with the following arguments:

@example
qemu-system-x86_64 \
	-chardev socket,path=/tmp/qga.sock,server=on,wait=off,id=qga0 \
	-device virtio-serial \
	-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \
	...
@end example

This creates a socket at @file{/tmp/qga.sock} on the host.  Once the
guest agent is running, you can issue commands with @code{socat}:

@example
$ guix shell socat -- socat unix-connect:/tmp/qga.sock stdio
@{"execute": "guest-get-host-name"@}
@{"return": @{"host-name": "guix"@}@}
@end example

See @url{https://wiki.qemu.org/Features/GuestAgent,QEMU guest agent
documentation} for more options and commands.

@defvr {Scheme Variable} qemu-guest-agent-service-type
Service type for the QEMU guest agent service.
@end defvr

@deftp {Data Type} qemu-guest-agent-configuration
Configuration for the @code{qemu-guest-agent} service.

@table @asis
@item @code{qemu} (default: @code{qemu-minimal})
The QEMU package to use.

@item @code{device} (default: @code{""})
File name of the device or socket the agent uses to communicate with the
host.  If empty, QEMU uses a default file name.
@end table
@end deftp


@subsubheading The Hurd in a Virtual Machine

@cindex @code{hurd}

M gnu/services/virtualization.scm => gnu/services/virtualization.scm +47 -1
@@ 2,6 2,7 @@
;;; Copyright © 2017 Ryan Moe <ryan.moe@gmail.com>
;;; Copyright © 2018, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2020,2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2021 Timotej Lazar <timotej.lazar@araneo.si>
;;;
;;; This file is part of GNU Guix.
;;;


@@ 82,7 83,11 @@

            qemu-binfmt-configuration
            qemu-binfmt-configuration?
            qemu-binfmt-service-type))
            qemu-binfmt-service-type

            qemu-guest-agent-configuration
            qemu-guest-agent-configuration?
            qemu-guest-agent-service-type))

(define (uglify-field-name field-name)
  (let ((str (symbol->string field-name)))


@@ 849,6 854,47 @@ functionality of the kernel Linux.")))


;;;
;;; QEMU guest agent service.
;;;

(define-configuration qemu-guest-agent-configuration
  (qemu
   (package qemu-minimal)
   "QEMU package.")
  (device
   (string "")
   "Path to device or socket used to communicate with the host.  If not
specified, the QEMU default path is used."))

(define qemu-guest-agent-shepherd-service
  (match-lambda
    (($ <qemu-guest-agent-configuration> qemu device)
     (list
      (shepherd-service
       (provision '(qemu-guest-agent))
       (documentation "Run the QEMU guest agent.")
       (start #~(make-forkexec-constructor
                 `(,(string-append #$qemu "/bin/qemu-ga") "--daemon"
                   "--pidfile=/var/run/qemu-ga.pid"
                   "--statedir=/var/run"
                   ,@(if #$device
                         (list (string-append "--path=" #$device))
                         '()))
                 #:pid-file "/var/run/qemu-ga.pid"
                 #:log-file "/var/log/qemu-ga.log"))
       (stop #~(make-kill-destructor)))))))

(define qemu-guest-agent-service-type
  (service-type
   (name 'qemu-guest-agent)
   (extensions
    (list (service-extension shepherd-root-service-type
                             qemu-guest-agent-shepherd-service)))
   (default-value (qemu-guest-agent-configuration))
   (description "Run the QEMU guest agent.")))


;;;
;;; Secrets for guest VMs.
;;;