aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-04-11 13:38:11 +0200
committerLudovic Courtès <ludo@gnu.org>2014-04-11 19:08:24 +0200
commite1a87b904a7f889bf080085c2aaef035b55d111a (patch)
treefa60a434633427991b4a53213adc885e6f27ad8c /guix
parent772d63658e4a90eb85bc07ceb9a5dd518baab270 (diff)
downloadgnu-guix-e1a87b904a7f889bf080085c2aaef035b55d111a.tar
gnu-guix-e1a87b904a7f889bf080085c2aaef035b55d111a.tar.gz
vm: Add (guix build vm) module.
* guix/build/vm.scm: New file. * Makefile.am (MODULES): Add it. * gnu/system/vm.scm (expression->derivation-in-linux-vm): Use it.
Diffstat (limited to 'guix')
-rw-r--r--guix/build/vm.scm97
1 files changed, 97 insertions, 0 deletions
diff --git a/guix/build/vm.scm b/guix/build/vm.scm
new file mode 100644
index 0000000000..725ede4e1f
--- /dev/null
+++ b/guix/build/vm.scm
@@ -0,0 +1,97 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix build vm)
+ #:use-module (ice-9 match)
+ #:use-module (guix build utils)
+ #:export (load-in-linux-vm))
+
+;;; Commentary:
+;;;
+;;; This module provides supporting code to run virtual machines and build
+;;; virtual machine images using QEMU.
+;;;
+;;; Code:
+
+(define (qemu-command)
+ "Return the default name of the QEMU command for the current host."
+ (string-append "qemu-system-"
+ (substring %host-type 0
+ (string-index %host-type #\-))))
+
+
+(define* (load-in-linux-vm builder
+ #:key
+ output
+ (qemu (qemu-command)) (memory-size 512)
+ linux initrd
+ make-disk-image? (disk-image-size 100)
+ (references-graphs '()))
+ "Run BUILDER, a Scheme file, into a VM running LINUX with INITRD, and copy
+the result to OUTPUT.
+
+When MAKE-DISK-IMAGE? is true, OUTPUT will contain a VM image of
+DISK-IMAGE-SIZE MiB resulting from the execution of BUILDER, which may access
+it via /dev/hda.
+
+REFERENCES-GRAPHS can specify a list of reference-graph files as produced by
+the #:references-graphs parameter of 'derivation'."
+
+ (when make-disk-image?
+ (unless (zero? (system* "qemu-img" "create" "-f" "qcow2" "image.qcow2"
+ (number->string disk-image-size)))
+ (error "qemu-img failed")))
+
+ (mkdir "xchg")
+
+ (match references-graphs
+ ((graph-files ...)
+ ;; Copy the reference-graph files under xchg/ so EXP can access it.
+ (map (lambda (file)
+ (copy-file file (string-append "xchg/" file)))
+ graph-files))
+ (_ #f))
+
+ (unless (zero?
+ (apply system* qemu "-enable-kvm" "-nographic" "-no-reboot"
+ "-m" (number->string memory-size)
+ "-net" "nic,model=virtio"
+ "-virtfs"
+ (string-append "local,id=store_dev,path="
+ (%store-directory)
+ ",security_model=none,mount_tag=store")
+ "-virtfs"
+ (string-append "local,id=xchg_dev,path=xchg"
+ ",security_model=none,mount_tag=xchg")
+ "-kernel" linux
+ "-initrd" initrd
+ "-append" (string-append "console=ttyS0 --load="
+ builder)
+ (if make-disk-image?
+ '("-hda" "image.qcow2")
+ '())))
+ (error "qemu failed" qemu))
+
+ (if make-disk-image?
+ (copy-file "image.qcow2" ; XXX: who mkdir'd OUTPUT?
+ output)
+ (begin
+ (mkdir output)
+ (copy-recursively "xchg" output))))
+
+;;; vm.scm ends here