summaryrefslogtreecommitdiff
path: root/gnu/system/vm.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-11-29 14:19:55 +0000
committerChristopher Baines <mail@cbaines.net>2020-11-29 17:34:18 +0000
commitff01206345e2306cc633db48e0b29eab9077091a (patch)
tree25c7ee17005dadc9bf4fae3f0873e03a4704f782 /gnu/system/vm.scm
parented2545f0fa0e2ad99d5a0c45f532c539b299b9fb (diff)
parent7c2e67400ffaef8eb6f30ef7126c976ee3d7e36c (diff)
Merge remote-tracking branch 'origin/master' into core-updates
Diffstat (limited to 'gnu/system/vm.scm')
-rw-r--r--gnu/system/vm.scm92
1 files changed, 18 insertions, 74 deletions
diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index 3a5204e11b2..93a79b12d60 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -77,7 +77,6 @@
77 77
78 system-qemu-image/shared-store 78 system-qemu-image/shared-store
79 system-qemu-image/shared-store-script 79 system-qemu-image/shared-store-script
80 system-disk-image-in-vm
81 system-docker-image 80 system-docker-image
82 81
83 virtual-machine 82 virtual-machine
@@ -224,6 +223,12 @@ substitutable."
224 (use-modules (guix build utils) 223 (use-modules (guix build utils)
225 (gnu build vm)) 224 (gnu build vm))
226 225
226 ;; Allow non-ASCII file names--e.g., 'nss-certs'--to be decoded
227 ;; by 'estimated-partition-size' below.
228 (setenv "GUIX_LOCPATH"
229 #+(file-append glibc-utf8-locales "/lib/locale"))
230 (setlocale LC_ALL "en_US.utf8")
231
227 (let* ((native-inputs 232 (let* ((native-inputs
228 '#+(list qemu (canonical-package coreutils))) 233 '#+(list qemu (canonical-package coreutils)))
229 (linux (string-append 234 (linux (string-append
@@ -557,77 +562,6 @@ the operating system."
557;;; VM and disk images. 562;;; VM and disk images.
558;;; 563;;;
559 564
560(define* (system-disk-image-in-vm os
561 #:key
562 (name "disk-image")
563 (file-system-type "ext4")
564 (disk-image-size (* 900 (expt 2 20)))
565 (volatile? #t)
566 (substitutable? #t))
567 "Return the derivation of a disk image of DISK-IMAGE-SIZE bytes of the
568system described by OS. Said image can be copied on a USB stick as is. When
569VOLATILE? is true, the root file system is made volatile; this is useful
570to USB sticks meant to be read-only.
571
572SUBSTITUTABLE? determines whether the returned derivation should be marked as
573substitutable."
574 (define root-label
575 "Guix_image")
576
577 (define (root-uuid os)
578 ;; UUID of the root file system, computed in a deterministic fashion.
579 ;; This is what we use to locate the root file system so it has to be
580 ;; different from the user's own file system UUIDs.
581 (operating-system-uuid os 'dce))
582
583 (define file-systems-to-keep
584 (remove (lambda (fs)
585 (string=? (file-system-mount-point fs) "/"))
586 (operating-system-file-systems os)))
587
588 (let* ((os (operating-system (inherit os)
589 ;; Since this is meant to be used on real hardware, don't
590 ;; install QEMU networking or anything like that. Assume USB
591 ;; mass storage devices (usb-storage.ko) are available.
592 (initrd (lambda (file-systems . rest)
593 (apply (operating-system-initrd os)
594 file-systems
595 #:volatile-root? volatile?
596 rest)))
597
598 (bootloader (operating-system-bootloader os))
599
600 ;; Force our own root file system. (We need a "/" file system
601 ;; to call 'root-uuid'.)
602 (file-systems (cons (file-system
603 (mount-point "/")
604 (device "/dev/placeholder")
605 (type file-system-type))
606 file-systems-to-keep))))
607 (uuid (root-uuid os))
608 (os (operating-system
609 (inherit os)
610 (file-systems (cons (file-system
611 (mount-point "/")
612 (device uuid)
613 (type file-system-type))
614 file-systems-to-keep))))
615 (bootcfg (operating-system-bootcfg os)))
616 (qemu-image #:name name
617 #:os os
618 #:bootcfg-drv bootcfg
619 #:bootloader (bootloader-configuration-bootloader
620 (operating-system-bootloader os))
621 #:disk-image-size disk-image-size
622 #:disk-image-format "raw"
623 #:file-system-type file-system-type
624 #:file-system-label root-label
625 #:file-system-uuid uuid
626 #:copy-inputs? #t
627 #:inputs `(("system" ,os)
628 ("bootcfg" ,bootcfg))
629 #:substitutable? substitutable?)))
630
631(define* (system-qemu-image os 565(define* (system-qemu-image os
632 #:key 566 #:key
633 (file-system-type "ext4") 567 (file-system-type "ext4")
@@ -641,7 +575,10 @@ of the GNU system as described by OS."
641 (let ((target (file-system-mount-point fs)) 575 (let ((target (file-system-mount-point fs))
642 (source (file-system-device fs))) 576 (source (file-system-device fs)))
643 (or (string=? target "/") 577 (or (string=? target "/")
644 (string-prefix? "/dev/" source)))) 578 (and (string? source)
579 (string-prefix? "/dev/" source))
580 (uuid? source)
581 (file-system-label? source))))
645 (operating-system-file-systems os))) 582 (operating-system-file-systems os)))
646 583
647 (define root-uuid 584 (define root-uuid
@@ -652,7 +589,14 @@ of the GNU system as described by OS."
652 'dce))) 589 'dce)))
653 590
654 591
655 (let* ((os (operating-system (inherit os) 592 (let* ((os (operating-system
593 (inherit os)
594
595 ;; As in 'virtualized-operating-system', use BIOS-style GRUB.
596 (bootloader (bootloader-configuration
597 (bootloader grub-bootloader)
598 (target "/dev/vda")))
599
656 ;; Assume we have an initrd with the whole QEMU shebang. 600 ;; Assume we have an initrd with the whole QEMU shebang.
657 601
658 ;; Force our own root file system. Refer to it by UUID so that 602 ;; Force our own root file system. Refer to it by UUID so that