Subject: bug#26544: [PATCH v4 05/10] system: Introduce read-boot-parameters-file.

From: Danny Milosavljevic <[email-masked]>
Date: Fri, 21 Apr 2017 14:37:09 +0200

* gnu/system.scm (read-boot-parameters): Remove export.
(read-boot-parameters-file): New variable. Export it.
* guix/scripts/system.scm (profile-boot-parameters): Use
read-boot-parameters-file.
(profile-grub-entries): Use read-boot-parameters-file.
(reinstall-grub): Use read-boot-parameters-file.
(display-system-generation): Use read-boot-parameters-file.
---
 gnu/system.scm          | 22 +++++++++++++++++++++-
 guix/scripts/system.scm | 14 ++++----------
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/gnu/system.scm b/gnu/system.scm
index a4f15f7f5..9921a9786 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -109,7 +109,7 @@
             boot-parameters-kernel
             boot-parameters-kernel-arguments
             boot-parameters-initrd
-            read-boot-parameters
+            read-boot-parameters-file
 
             local-host-aliases
             %setuid-programs
@@ -907,4 +907,24 @@ being stored into the \"parameters\" file)."
               system)
      #f)))
 
+(define (read-boot-parameters-file system)
+  "Read boot parameters from SYSTEM's (system or generation) \"parameters\"
+file and returns the corresponding <boot-parameters> object or #f if the
+format is unrecognized.
+The object has its kernel-arguments extended in order to make it bootable."
+  (let* ((file (string-append system "/parameters"))
+         (params (call-with-input-file file read-boot-parameters))
+         (root (boot-parameters-root-device params))
+         (root-device (if (bytevector? root)
+                          (uuid->string root)
+                          root))
+         (kernel-arguments (boot-parameters-kernel-arguments params)))
+    (if params
+      (boot-parameters
+        (inherit params)
+        (kernel-arguments (bootable-kernel-arguments kernel-arguments
+                                                     system
+                                                     root-device)))
+      #f)))
+
 ;;; system.scm ends here
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index 8fabdb5c1..b278b6683 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -369,9 +369,7 @@ it atomically, and then run OS's activation script."
 NUMBERS, which is a list of generation numbers."
   (define (system->boot-parameters system number time)
     (unless-file-not-found
-     (let* ((file             (string-append system "/parameters"))
-            (params           (call-with-input-file file
-                                read-boot-parameters)))
+     (let* ((params           (read-boot-parameters-file system)))
        params)))
   (let* ((systems (map (cut generation-file-name profile <>)
                        numbers))
@@ -387,9 +385,7 @@ NUMBERS, which is a list of generation numbers."
 NUMBERS, which is a list of generation numbers."
   (define (system->grub-entry system number time)
     (unless-file-not-found
-     (let* ((file             (string-append system "/parameters"))
-            (params           (call-with-input-file file
-                                read-boot-parameters))
+     (let* ((params           (read-boot-parameters-file system))
             (label            (boot-parameters-label params))
             (root             (boot-parameters-root-device params))
             (root-device      (if (bytevector? root)
@@ -447,9 +443,8 @@ generation as its default entry.  STORE is an open connection to the store."
   "Re-install grub for existing system profile generation NUMBER.  STORE is an
 open connection to the store."
   (let* ((generation (generation-file-name %system-profile number))
-         (file (string-append generation "/parameters"))
          (params (unless-file-not-found
-                  (call-with-input-file file read-boot-parameters)))
+                  (read-boot-parameters-file generation)))
          (root-device (boot-parameters-root-device params))
          ;; We don't currently keep track of past menu entries' details.  The
          ;; default values will allow the system to boot, even if they differ
@@ -533,8 +528,7 @@ list of services."
   "Display a summary of system generation NUMBER in a human-readable format."
   (unless (zero? number)
     (let* ((generation  (generation-file-name profile number))
-           (param-file  (string-append generation "/parameters"))
-           (params      (call-with-input-file param-file read-boot-parameters))
+           (params      (read-boot-parameters-file generation))
            (label       (boot-parameters-label params))
            (root        (boot-parameters-root-device params))
            (root-device (if (bytevector? root)