Subject: [bug#75445] [PATCH 7/7] services: Add xen-guest-agent-service-type.

From: Karl Hallsby <[email-masked]>
Date: Wed, 8 Jan 2025 14:19:01 -0600

* gnu/services/virtualization.scm (xen-guest-agent-configuration,
  xen-guest-agent-service-type): New variables.
* doc/guix.texi: Document them.

Change-Id: Id1b1f4fc2b193d73f4401e74a214222dfe1b6ea7
---
 doc/guix.texi                   | 24 +++++++++++++++++++++++
 gnu/services/virtualization.scm | 34 ++++++++++++++++++++++++++++++++-
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index ee827717a1..89f153146a 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -37365,6 +37365,30 @@ Virtualization Services
 @end table
 @end deftp
 
+@code{xe-guest-utilities} is the standard guest utilities used for Xen
+guests.  More recently the Xen Project has been working to develop
+@code{xen-guest-agent}, a modern drop-in replacement for
+@code{xe-guest-utilities}.  While they nearly have feature-parity,
+@code{xen-guest-agent} currently lacks some of the features of its
+predecessor, namely disk metrics and ``PV drivers version''.
+
+@defvar xen-guest-agent-service-type
+Service type for the Xen guest agent service.
+@end defvar
+
+@deftp {Data Type} xen-guest-agent-configuration
+Configuration for the @code{xen-guest-agent} service.
+
+@table @asis
+@item @code{package} (default: @code{xen-guest-agent})
+The Xen guest agent package to use.
+@end table
+@end deftp
+
+@quotation Warning
+@code{xe-guest-utilities} and @code{xen-guest-agent} are mutually exclusive.
+@end quotation
+
 
 @anchor{build-vm}
 @subsubheading Virtual Build Machines
diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm
index 874abcd73f..b697ae9526 100644
--- a/gnu/services/virtualization.scm
+++ b/gnu/services/virtualization.scm
@@ -113,7 +113,9 @@ (define-module (gnu services virtualization)
             qemu-guest-agent-service-type
 
             xe-guest-utilities-configuration
-            xe-guest-utilities-service-type))
+            xe-guest-utilities-service-type
+            xen-guest-agent-configuration
+            xen-guest-agent-service-type))
 
 (define (uglify-field-name field-name)
   (let ((str (symbol->string field-name)))
@@ -1083,6 +1085,36 @@ (define xe-guest-utilities-service-type
    (default-value (xe-guest-utilities-configuration))
    (description "Run the Xen guest management utilities.")))
 
+(define-configuration/no-serialization xen-guest-agent-configuration
+  (package
+    (package xen-guest-agent)
+    "Xen guest agent package."))
+
+(define (generate-xen-guest-agent-documentation)
+  "Generate documentation for xen-guest-agent-configuration fields"
+  (generate-documentation
+   `((xen-guest-agent-configuration ,xen-guest-agent-configuration-fields))
+   'xen-guest-agent-configuration))
+
+(define (xen-guest-agent-shepherd-service config)
+  (list
+   (shepherd-service
+    (provision '(xen-guest-agent))
+    (requirement '(networking user-processes udev))
+    (documentation "Run the Xen guest management agent.")
+    (start #~(make-forkexec-constructor
+              (list #$(file-append xen-guest-agent "/bin/xen-guest-agent"))))
+    (stop #~(make-kill-destructor)))))
+
+(define xen-guest-agent-service-type
+  (service-type
+   (name 'xen-guest-agent)
+   (extensions
+    (list (service-extension shepherd-root-service-type
+                             xen-guest-agent-shepherd-service)))
+   (default-value (xen-guest-agent-configuration))
+   (description "Run the Xen guest management utilities.")))
+
 
 ;;;
 ;;; Secrets for guest VMs.
-- 
2.46.0