Subject: Re: [bug#27661] ISO-9660 image working and ready

From: Danny Milosavljevic <[email-masked]>
Date: Mon, 17 Jul 2017 21:58:19 +0200

I tried something like the following.  But now it throws away the output entirely.  That's not an improvement :)

But I think this is overcomplicating things - and the easiest way with only aesthetic downsides would be to punt and do nothing...

Or we could replace make-disk-image? and make-output-directory? by two parameters "initializer" and "serializer" which would be procedures that could do whatever they wanted.  I think that would be overly generic, though :)

Also, what amount of rebuilding would any change cause?  The procedures modified are already used quite often...

diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm
index d8c53ef37..2be060902 100644
--- a/gnu/build/vm.scm
+++ b/gnu/build/vm.scm
@@ -76,6 +76,7 @@
                            (qemu (qemu-command)) (memory-size 512)
                            linux initrd
                            make-disk-image?
+                           (make-output-directory? #f)
                            (disk-image-size (* 100 (expt 2 20)))
                            (disk-image-format "qcow2")
                            (references-graphs '()))
@@ -87,7 +88,9 @@ DISK-IMAGE-SIZE bytes 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'."
+the #:references-graphs parameter of 'derivation'.
+
+If CREATE_OUTPUT-DIRECTORY?, creates a directory OUTPUT."
   (when make-disk-image?
     (format #t "creating ~a image of ~,2f MiB...~%"
             disk-image-format (/ disk-image-size (expt 2 20)))
@@ -137,8 +140,10 @@ the #:references-graphs parameter of 'derivation'."
 
   ;; When MAKE-DISK-IMAGE? is true, the image is in OUTPUT already.
   (unless make-disk-image?
-    (mkdir output)
-    (copy-recursively "xchg" output)))
+    (if make-output-directory?
+        (begin
+          (mkdir output)
+          (copy-recursively "xchg" output)))))
diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index 66a2448ce..69ebf2377 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -106,6 +106,7 @@
                                               (%guile-for-build))
 
                                              (make-disk-image? #f)
+                                             (make-output-directory? #f)
                                              (references-graphs #f)
                                              (memory-size 256)
                                              (disk-image-format "qcow2")
@@ -121,6 +122,9 @@ DISK-IMAGE-FORMAT (e.g., 'qcow2' or 'raw'), of DISK-IMAGE-SIZE bytes and
 return it.  When DISK-IMAGE-SIZE is 'guess, estimate the image size based
 based on the size of the closure of REFERENCES-GRAPHS.
 
+When MAKE-OUTPUT-DIRECTORY? is true, then create a directory OUTPUT
+and copy the contents of /xchg there.
+
 When REFERENCES-GRAPHS is true, it must be a list of file name/store path
 pairs, as for `derivation'.  The files containing the reference graphs are
 made available under the /xchg CIFS share."
@@ -164,6 +168,7 @@ made available under the /xchg CIFS share."
                                 #:linux linux #:initrd initrd
                                 #:memory-size #$memory-size
                                 #:make-disk-image? #$make-disk-image?
+                                #:make-output-directory? #$make-output-directory?
                                 #:disk-image-format #$disk-image-format
                                 #:disk-image-size size
                                 #:references-graphs graphs)))))