unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David Craven <david@craven.ch>
To: guix-devel@gnu.org
Subject: [PATCH 6/8] vm: Improve readability of run-vm.sh generation.
Date: Tue, 14 Feb 2017 16:28:32 +0100	[thread overview]
Message-ID: <20170214152834.19651-8-david@craven.ch> (raw)
In-Reply-To: <20170214152834.19651-1-david@craven.ch>

* gnu/system/vm.scm (common-qemu-options,
  system-qemu-image/shared-store-script): Improve readability.
---
 gnu/system/vm.scm | 69 ++++++++++++++++++++++++++++++-------------------------
 1 file changed, 38 insertions(+), 31 deletions(-)

diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index a7203d169..103af37c9 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -434,25 +434,26 @@ bootloader refers to: OS kernel, initrd, bootloader data, etc."
 (define* (common-qemu-options image shared-fs)
   "Return the a string-value gexp with the common QEMU options to boot IMAGE,
 with '-virtfs' options for the host file systems listed in SHARED-FS."
+
   (define (virtfs-option fs)
-    #~(string-append "-virtfs local,path=\"" #$fs
-                     "\",security_model=none,mount_tag=\""
-                     #$(file-system->mount-tag fs)
-                     "\" "))
+    #~(format #f "-virtfs local,path=~s,security_model=none,mount_tag=~s"
+              #$fs #$(file-system->mount-tag fs)))
 
-  #~(string-append
-     ;; Only enable kvm if we see /dev/kvm exists.
+  #~(;; Only enable kvm if we see /dev/kvm exists.
      ;; This allows users without hardware virtualization to still use these
      ;; commands.
-     #$(if (file-exists? "/dev/kvm")
-           " -enable-kvm "
-           "")
-     " -no-reboot -net nic,model=virtio \
-  " #$@(map virtfs-option shared-fs) " \
-  -vga std \
-  -drive file=" #$image
-  ",if=virtio,cache=writeback,werror=report,readonly \
-  -m 256"))
+     #$@(if (file-exists? "/dev/kvm")
+            '("-enable-kvm")
+            '())
+
+     "-no-reboot"
+     "-net nic,model=virtio"
+
+     #$@(map virtfs-option shared-fs)
+     "-vga std"
+     (format #f "-drive file=~a,if=virtio,cache=writeback,werror=report,readonly"
+             #$image)
+     "-m 256"))
 
 (define* (system-qemu-image/shared-store-script os
                                                 #:key
@@ -479,25 +480,31 @@ it is mostly useful when FULL-BOOT?  is true."
                                 os
                                 #:full-boot? full-boot?
                                 #:disk-image-size disk-image-size)))
+    (define kernel-arguments
+      #~(list "--root=/dev/vda1"
+              (string-append "--system=" #$os-drv)
+              (string-append "--load=" #$os-drv "/boot")
+              #$@(if graphic? #~() #~("console=ttyS0"))
+              #+@(operating-system-kernel-arguments os)))
+
+    (define qemu-exec
+      #~(list (string-append #$qemu "/bin/" #$(qemu-command (%current-system)))
+              #$@(if full-boot?
+                     #~()
+                     #~("-kernel" #$(operating-system-kernel-file os)
+                        "-initrd" #$(file-append os-drv "/initrd")
+                        (format #f "-append ~s"
+                                (string-join #$kernel-arguments " "))))
+              #$@(common-qemu-options image
+                                      (map file-system-mapping-source
+                                           (cons %store-mapping mappings)))))
+
     (define builder
       #~(call-with-output-file #$output
           (lambda (port)
-            (display
-             (string-append "#!" #$bash "/bin/sh
-exec " #$qemu "/bin/" #$(qemu-command (%current-system))
-
-#$@(if full-boot?
-       #~()
-       #~(" -kernel " #$(operating-system-kernel-file os) " \
-            -initrd " #$os-drv "/initrd \
-            -append \"" #$(if graphic? "" "console=ttyS0 ")
-            "--system=" #$os-drv " --load=" #$os-drv "/boot --root=/dev/vda1 "
-            (string-join (list #+@(operating-system-kernel-arguments os))) "\" "))
-#$(common-qemu-options image
-                       (map file-system-mapping-source
-                            (cons %store-mapping mappings)))
-" \"$@\"\n")
-             port)
+            (format port "#!~a~% exec ~a \"$@\"~%"
+                    #$(file-append bash "/bin/sh")
+                    (string-join #$qemu-exec " "))
             (chmod port #o555))))
 
     (gexp->derivation "run-vm.sh" builder)))
-- 
2.11.1

  parent reply	other threads:[~2017-02-14 15:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-14 15:28 [PATCH 0/8] WIP: Better support for non-grub bootloaders David Craven
2017-02-14 15:28 ` [PATCH 1/8] file-systems: Add FAT32 support David Craven
2017-03-01 16:30   ` Danny Milosavljevic
2017-02-14 15:28 ` [PATCH 2/8] system: Pass <bootloader-parameter> to grub David Craven
2017-02-14 15:28 ` [PATCH 2/8] system: Pass <boot-parameters> " David Craven
2017-02-14 15:28 ` [PATCH 3/8] system: Add extlinux support David Craven
2017-02-14 15:28 ` [PATCH 4/8] scripts: system: Rename --no-grub option to --no-bootloader David Craven
2017-02-14 15:28 ` [PATCH 5/8] vm: Remove hard coded kernel file name David Craven
2017-02-28 22:48   ` Danny Milosavljevic
2017-02-14 15:28 ` David Craven [this message]
2017-02-28 23:44   ` [PATCH 6/8] vm: Improve readability of run-vm.sh generation Danny Milosavljevic
2017-02-14 15:28 ` [PATCH 7/8] vm: Fix full-boot? option David Craven
2017-03-06 22:44   ` Ludovic Courtès
2017-02-14 15:28 ` [PATCH 8/8] bootloader: Add install procedures and use them David Craven
2017-03-06 22:04 ` [PATCH 0/8] WIP: Better support for non-grub bootloaders Ludovic Courtès
2017-03-17 12:43   ` Mathieu Othacehe
2017-03-17 12:49     ` John Darrington
2017-03-18 13:53       ` Ludovic Courtès
2017-03-18 17:25         ` David Craven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170214152834.19651-8-david@craven.ch \
    --to=david@craven.ch \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).