Subject: Re: bug#27735: Unbootable images with GuixSD on... "GuixSD"

From: [email-masked] (Ludovic Courtès)
Date: Tue, 18 Jul 2017 13:49:01 +0200

Hello,

Danny Milosavljevic <[email-masked]> skribis:

>> The real problem here is that we're using a label as a UUID.
>
> I agree.  Unfortunately Guix UUIDs are difficult to use consistently or I would have changed it over to begin with.

What about generating a UUID in a deterministic yet somewhat unique
fashion along these lines (untested):

diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index ec3fb031a..6b53eacbf 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -56,9 +56,12 @@
   #:use-module (gnu system file-systems)
   #:use-module (gnu system)
   #:use-module (gnu services)
+  #:use-module ((gnu build file-systems)
+                #:select (string->iso9660-uuid))
 
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26)
+  #:use-module (rnrs bytevectors)
   #:use-module (ice-9 match)
 
   #:export (expression->derivation-in-linux-vm
@@ -344,12 +347,29 @@ to USB sticks meant to be read-only."
     (if (string=? "iso9660" file-system-type)
         string-upcase
         identity))
+
   (define root-label
-    ;; Volume name of the root file system.  Since we don't know which device
-    ;; will hold it, we use the volume name to find it (using the UUID would
-    ;; be even better, but somewhat less convenient.)
+    ;; Volume name of the root file system.
     (normalize-label "GuixSD_image"))
 
+  (define root-uuid
+    ;; UUID of the root file system, computed in a deterministic fashion.
+    (if (string=? "iso9660" file-system-type)
+        (let ((pad (compose (cut string-pad <> 2 #\0)
+                            number->string)))
+          (string->iso9660-uuid
+           (string-append "1970-01-01-"
+                          (pad (hash name 24))
+                          (pad (hash file-system-type 60))
+                          (pad (hash (operating-system-host-name os) 60)))))
+        (uint-list->bytevector
+         (list (hash (string-append file-system-type name)
+                     (expt 2 64))
+               (hash (operating-system-host-name os)
+                     (expt 2 64)))
+         (endianness little)
+         8)))
+
   (define file-systems-to-keep
     (remove (lambda (fs)
               (string=? (file-system-mount-point fs) "/"))
@@ -367,8 +387,8 @@ to USB sticks meant to be read-only."
               ;; Force our own root file system.
               (file-systems (cons (file-system
                                     (mount-point "/")
-                                    (device root-label)
-                                    (title 'label)
+                                    (device root-uuid)
+                                    (title 'uuid)
                                     (type file-system-type))
                                   file-systems-to-keep)))))
 
@@ -376,8 +396,7 @@ to USB sticks meant to be read-only."
                          (bootcfg  (operating-system-bootcfg os)))
       (if (string=? "iso9660" file-system-type)
           (iso9660-image #:name name
-                         #:file-system-label root-label
-                         #:file-system-uuid #f
+                         #:file-system-uuid root-uuid
                          #:os-drv os-drv
                          #:bootcfg-drv bootcfg
                          #:bootloader (bootloader-configuration-bootloader
@@ -395,7 +414,7 @@ to USB sticks meant to be read-only."
                                                        file-system-type)
                                              "ext4"
                                              file-system-type)
-                      #:file-system-label root-label
+                      #:file-system-label root-label ;FIXME: use ROOT-UUID
                       #:copy-inputs? #t
                       #:register-closures? #t
                       #:inputs `(("system" ,os-drv)

We cannot use the store file name’s hash, unfortunately, because the
UUID has to be given on the “host side.”

Thoughts?

Ludo’.