guix_mirror_bot pushed a commit to branch master
in repository guix.
commit 528ba9a3069a8767506f1fe6b7badeeb57a02542
Author: Ludovic Courtès <[email protected]>
AuthorDate: Wed Oct 28 23:44:48 2026 +0100
vm: Provide a writable store by default.
Until now, ‘guix system vm’ would produce an image where the store is
read-only (a 9p mount of the host store), preventing guix-daemon from
operating. With this change, it becomes possible to use Guix inside such
VMs.
* gnu/system/vm.scm (writable-store-shepherd-service)
(writable-store-file-systems): New procedures.
(writable-store-service-type): New variable.
(virtualized-operating-system): Add it to ‘services’, unless ‘full-boot?’ is
true.
* gnu/tests/virtualization.scm (run-build-vm-test): Remove “copy-on-write
store” and “guix-daemon restarted” tests, which are now redundant.
Signed-off-by: Ludovic Courtès <[email protected]>
Merges: #12174
---
gnu/system/vm.scm | 83 +++++++++++++++++++++++++++++++++++++++-----
gnu/tests/virtualization.scm | 29 ----------------
2 files changed, 75 insertions(+), 37 deletions(-)
diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index c77234cd39f..360f6cb47f4 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -36,6 +36,7 @@
#:use-module (guix records)
#:use-module (guix modules)
#:use-module (guix utils)
+ #:use-module ((guix store) #:select (%store-prefix))
#:use-module (gcrypt hash)
#:use-module (guix base32)
#:use-module ((guix self) #:select (make-config.scm))
@@ -68,6 +69,7 @@
#:use-module (gnu services)
#:use-module (gnu services base)
#:use-module (gnu services spice)
+ #:use-module (gnu services shepherd)
#:use-module (gnu system uuid)
#:use-module ((srfi srfi-1) #:hide (partition))
@@ -139,6 +141,65 @@
(check? #f)
(create-mount-point? #t)))))
+(define (writable-store-shepherd-service backing-store)
+ "Return a Shepherd service that mounts an overlay file system on the store
+such that writes go to BACKING-STORE."
+ (define (import-module? module)
+ ;; Since we don't use deduplication support in 'populate-store', don't
+ ;; import (guix store deduplication) and its dependencies, which
+ ;; includes Guile-Gcrypt.
+ (and (guix-module-name? module)
+ (not (equal? module '(guix store deduplication)))))
+
+ (list (shepherd-service
+ (provision '(writable-store))
+ (requirement
+ (list (symbol-append 'file-system-
+ (string->symbol backing-store))))
+ (documentation
+ "Make the store writable inside the virtual machine.")
+ (modules `((gnu build install)
+ ,@%default-modules))
+ (start
+ (with-imported-modules (source-module-closure
+ '((gnu build install))
+ #:select? import-module?)
+ #~(lambda ()
+ (mount-cow-store #$backing-store "/backing-store")
+ #$backing-store)))
+ (stop #~(lambda (target)
+ (umount #$(%store-prefix)))))))
+
+(define (writable-store-file-systems backing-store)
+ (list (file-system
+ (mount-point backing-store)
+ (device "none")
+ (type "tmpfs")
+ (flags '(no-suid no-dev))
+ (options "mode=755,size=50%")
+ (check? #f))))
+
+(define writable-store-service-type
+ (service-type
+ (name 'writable-store)
+
+ ;; Set up a writable store. In 'virtualized-operating-system', the root
+ ;; partition is already an overlayfs, which is not suitable as the bottom
+ ;; part of this additional overlayfs. Thus, create a tmpfs for the
+ ;; backing store.
+ (extensions
+ (list (service-extension shepherd-root-service-type
+ writable-store-shepherd-service)
+ (service-extension file-system-service-type
+ writable-store-file-systems)
+ (service-extension user-processes-service-type
+ (const '(writable-store)))))
+ (description
+ "Make the store writable (and volatile) by setting up an overlay file
+system. This is meant to be used inside a virtual machine as created by
+@command{guix system vm} where the store is a 9p mount of the host's
+store---and thus read-only.")))
+
(define* (virtualized-operating-system os
#:optional (mappings '())
#:key
@@ -179,14 +240,20 @@ environment with the store shared with the host.
MAPPINGS is a list of
(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))
+ (let ((services
+ (if full-boot?
+ services
+ (cons (service writable-store-service-type
+ "/var/tmp/writable-store")
+ 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)
diff --git a/gnu/tests/virtualization.scm b/gnu/tests/virtualization.scm
index e9dafe63431..f4f1caaf35e 100644
--- a/gnu/tests/virtualization.scm
+++ b/gnu/tests/virtualization.scm
@@ -552,35 +552,6 @@ sure that the childhurd boots and runs its SSH server.")
(wait-for-tcp-port 11022 marionette
#:peek? #t))
- (test-assert "copy-on-write store"
- ;; Set up a writable store. The root partition is already an
- ;; overlayfs, which is not suitable as the bottom part of this
- ;; additional overlayfs; thus, create a tmpfs for the backing
- ;; store.
- ;; TODO: Remove this when <virtual-machine> creates a writable
- ;; store.
- (marionette-eval
- '(begin
- (use-modules (gnu build install)
- (guix build syscalls))
-
- (mkdir "/run/writable-store")
- (mount "none" "/run/writable-store" "tmpfs")
- (mount-cow-store "/run/writable-store" "/backing-store")
- (system* "df" "-hT"))
- marionette))
-
- (test-assert "guix-daemon restarted"
- ;; Restart 'guix-daemon' after the above so that 'guix-ownership'
- ;; has a chance to successfully run if needed--e.g., because the
- ;; host store is not root-owned but the guest is running
- ;; 'guix-daemon' as root. See #8872.
- (marionette-eval
- '(begin
- (use-modules (gnu services herd))
- (restart-service 'guix-daemon))
- marionette))
-
(test-equal "guix build hello"
;; Make sure the local 'guix-daemon' is operational.
0