unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Lilah Tascheter via Guix-patches <guix-patches@gnu.org>
To: 69343@debbugs.gnu.org
Cc: Felix Lechner <felix.lechner@lease-up.com>,
	Christopher Baines <guix@cbaines.net>,
	Josselin Poiret <dev@jpoiret.xyz>,
	Ludovic Court??s <ludo@gnu.org>,
	Mathieu Othacehe <othacehe@gnu.org>,
	Simon Tournier <zimon.toutoune@gmail.com>,
	Tobias Geerinckx-Rice <me@tobias.gr>
Subject: [bug#69343] [PATCH v3 02/12] Move <boot-parameters> record to a separate file.
Date: Sat,  3 Aug 2024 22:13:24 -0500	[thread overview]
Message-ID: <84d2bacfdda34a9c8be2ed13b3d348280f9ba2ef.1722741214.git.lilah@lunabee.space> (raw)
In-Reply-To: <cover.1722741214.git.lilah@lunabee.space>

From: Felix Lechner <felix.lechner@lease-up.com>

Required to avoid a missing dependency error on build-side.

* gnu/system.scm (<boot-parameters>): Move this record, and...
  (system-linux-image-file-name, %boot-parameters-version,
  bootable-kernel-arguments, ensure-not-/dev, read-boot-parameters,
  read-boot-parameters-file): ...these procedures, to...

* gnu/system/boot.scm: ...this new file.

* gnu/machine/ssh.scm, gnu/system.scm, guix/scripts/system.scm,
  tests/boot-parameters.scm: Use new module above.

* gnu/local.mk (GNU_SYSTEM_MODULES): Add new module above.

* gnu/machine/ssh.scm (machine-boot-parameters): Don't private-import
  bootable-kernel-arguments.

Change-Id: I6944ffd4c323c776005b0cef23218bffae59be23
---
 gnu/local.mk              |   1 +
 gnu/machine/ssh.scm       |   4 +-
 gnu/system.scm            | 259 +------------------------------
 gnu/system/boot.scm       | 318 ++++++++++++++++++++++++++++++++++++++
 guix/scripts/system.scm   |   1 +
 tests/boot-parameters.scm |   1 +
 6 files changed, 323 insertions(+), 261 deletions(-)
 create mode 100644 gnu/system/boot.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index 6d2b14e72d..8375e13709 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -758,6 +758,7 @@ GNU_SYSTEM_MODULES =				\
 						\
   %D%/system.scm				\
   %D%/system/accounts.scm			\
+  %D%/system/boot.scm				\
   %D%/system/file-systems.scm			\
   %D%/system/hurd.scm				\
   %D%/system/image.scm 				\
diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm
index 0be9ebbc0d..749aa2b6d8 100644
--- a/gnu/machine/ssh.scm
+++ b/gnu/machine/ssh.scm
@@ -23,6 +23,7 @@ (define-module (gnu machine ssh)
   #:use-module (gnu machine)
   #:autoload   (gnu packages gnupg) (guile-gcrypt)
   #:use-module (gnu system)
+  #:use-module (gnu system boot)
   #:use-module (gnu system file-systems)
   #:use-module (gnu system uuid)
   #:use-module ((gnu services) #:select (sexp->system-provenance))
@@ -417,9 +418,6 @@ (define not-config?
 (define (machine-boot-parameters machine)
   "Monadic procedure returning a list of 'boot-parameters' for the generations
 of MACHINE's system profile, ordered from most recent to oldest."
-  (define bootable-kernel-arguments
-    (@@ (gnu system) bootable-kernel-arguments))
-
   (define remote-exp
     (with-extensions (list guile-gcrypt)
       (with-imported-modules `(((guix config) => ,(make-config.scm))
diff --git a/gnu/system.scm b/gnu/system.scm
index c76f4d7c50..2e4b10e2fb 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -72,6 +72,7 @@ (define-module (gnu system)
   #:use-module (gnu services shepherd)
   #:use-module (gnu services base)
   #:use-module (gnu bootloader)
+  #:use-module (gnu system boot)
   #:use-module (gnu system shadow)
   #:use-module (gnu system nss)
   #:use-module (gnu system locale)
@@ -145,31 +146,11 @@ (define-module (gnu system)
             operating-system-boot-script
             operating-system-uuid
 
-            system-linux-image-file-name
             operating-system-with-gc-roots
             operating-system-with-provenance
 
             hurd-default-essential-services
 
-            boot-parameters
-            boot-parameters?
-            boot-parameters-label
-            boot-parameters-root-device
-            boot-parameters-bootloader-name
-            boot-parameters-bootloader-menu-entries
-            boot-parameters-store-crypto-devices
-            boot-parameters-store-device
-            boot-parameters-store-directory-prefix
-            boot-parameters-store-mount-point
-            boot-parameters-locale
-            boot-parameters-kernel
-            boot-parameters-kernel-arguments
-            boot-parameters-initrd
-            boot-parameters-multiboot-modules
-            boot-parameters-version
-            %boot-parameters-version
-            read-boot-parameters
-            read-boot-parameters-file
             boot-parameters->menu-entry
 
             local-host-aliases                    ;deprecated
@@ -192,29 +173,6 @@ (define-module (gnu system)
 ;;;
 ;;; Code:
 
-(define* (bootable-kernel-arguments system root-device version)
-  "Return a list of kernel arguments (gexps) to boot SYSTEM from ROOT-DEVICE.
-VERSION is the target version of the boot-parameters record."
-  ;; If the version is newer than 0, we use the new style initrd parameter
-  ;; names, otherwise we use the legacy ones.  This is to maintain backward
-  ;; compatibility when producing bootloader configurations for older
-  ;; generations.
-  (define version>0? (> version 0))
-  (let ((root (file-system-device->string root-device
-                                          #:uuid-type 'dce)))
-    (append
-     (if (string=? root "none")
-         '() ;  Ignore the case where the root is "none" (typically tmpfs).
-         ;; Note: Always use the DCE format because that's what
-         ;; (gnu build linux-boot) expects for the 'root'
-         ;; kernel command-line option.
-         (list (string-append (if version>0? "root=" "--root=") root)))
-     (list #~(string-append (if #$version>0? "gnu.system=" "--system=") #$system)
-           #~(string-append (if #$version>0? "gnu.load=" "--load=")
-                            #$system "/boot")))))
-
-;; System-wide configuration.
-
 (define-with-syntax-properties (warn-hosts-file-field-deprecation
                                 (value properties))
   (when value
@@ -361,210 +319,6 @@ (define* (operating-system-kernel-arguments
 ;;; Boot parameters
 ;;;
 
-;;; Version 1 was introduced early 2022 to mark the departure from long option
-;;; names such as '--load' to the more conventional initrd option names like
-;;; 'gnu.load'.
-;;;
-;;; When bumping the boot-parameters version, increment it by one (1).
-(define %boot-parameters-version 1)
-
-(define-record-type* <boot-parameters>
-  boot-parameters make-boot-parameters boot-parameters?
-  (label            boot-parameters-label)
-  ;; Because we will use the 'store-device' to create the GRUB search command,
-  ;; the 'store-device' has slightly different semantics than 'root-device'.
-  ;; The 'store-device' can be a file system uuid, a file system label, or #f,
-  ;; but it cannot be a device file name such as "/dev/sda3", since GRUB would
-  ;; not understand that.  The 'root-device', on the other hand, corresponds
-  ;; exactly to the device field of the <file-system> object representing the
-  ;; OS's root file system, so it might be a device file name like
-  ;; "/dev/sda3".  The 'store-directory-prefix' field contains #f or the store
-  ;; file name inside the 'store-device' as it is seen by GRUB, e.g. it would
-  ;; contain "/storefs" if the store is located in that subvolume of a btrfs
-  ;; partition.
-  (root-device      boot-parameters-root-device)
-  (bootloader-name  boot-parameters-bootloader-name)
-  (bootloader-menu-entries                        ;list of <menu-entry>
-   boot-parameters-bootloader-menu-entries)
-  (store-device     boot-parameters-store-device)
-  (store-mount-point boot-parameters-store-mount-point)
-  (store-directory-prefix boot-parameters-store-directory-prefix)
-  (store-crypto-devices boot-parameters-store-crypto-devices
-                        (default '()))
-  (locale           boot-parameters-locale)
-  (kernel           boot-parameters-kernel)
-  (kernel-arguments boot-parameters-kernel-arguments)
-  (initrd           boot-parameters-initrd)
-  (multiboot-modules boot-parameters-multiboot-modules)
-  (version          boot-parameters-version  ;positive integer
-                    (default %boot-parameters-version)))
-
-(define (ensure-not-/dev device)
-  "If DEVICE starts with a slash, return #f.  This is meant to filter out
-Linux device names such as /dev/sda, and to preserve GRUB device names and
-file system labels."
-  (if (and (string? device) (string-prefix? "/" device))
-      #f
-      device))
-
-(define (read-boot-parameters port)
-  "Read boot parameters from PORT and return the corresponding
-<boot-parameters> object.  Raise an error if the format is unrecognized."
-  (define device-sexp->device
-    (match-lambda
-      (('uuid (? symbol? type) (? bytevector? bv))
-       (bytevector->uuid bv type))
-      (('file-system-label (? string? label))
-       (file-system-label label))
-      ((? bytevector? bv)                         ;old format
-       (bytevector->uuid bv 'dce))
-      ((? string? device)
-       (if (string-contains device ":/")
-           device ; nfs-root
-           ;; It used to be that we would not distinguish between labels and
-           ;; device names.  Try to infer the right thing here.
-           (if (string-prefix? "/" device)
-               device
-               (file-system-label device))))))
-  (define uuid-sexp->uuid
-    (match-lambda
-      (('uuid (? symbol? type) (? bytevector? bv))
-       (bytevector->uuid bv type))
-      (x
-       (warning (G_ "unrecognized uuid ~a at '~a'~%") x (port-filename port))
-       #f)))
-
-  ;; New versions are not backward-compatible, so only accept past and current
-  ;; versions, not future ones.
-  (define (version? n)
-    (member n (iota (1+ %boot-parameters-version))))
-
-  (match (read port)
-    (('boot-parameters ('version (? version? version))
-                       ('label label) ('root-device root)
-                       ('kernel kernel)
-                       rest ...)
-     (boot-parameters
-      (version version)
-      (label label)
-      (root-device (device-sexp->device root))
-
-      (bootloader-name
-       (match (assq 'bootloader-name rest)
-         ((_ args) args)
-         (#f       'grub))) ; for compatibility reasons.
-
-      (bootloader-menu-entries
-       (match (assq 'bootloader-menu-entries rest)
-         ((_ entries) (map sexp->menu-entry entries))
-         (#f          '())))
-
-      ;; In the past, we would store the directory name of linux instead of
-      ;; the absolute file name of its image.  Detect that and correct it.
-      (kernel (if (string=? kernel (direct-store-path kernel))
-                  (string-append kernel "/"
-                                 (system-linux-image-file-name))
-                  kernel))
-
-      (kernel-arguments
-       (match (assq 'kernel-arguments rest)
-         ((_ args) args)
-         (#f       '())))                         ;the old format
-
-      (initrd
-       (match (assq 'initrd rest)
-         (('initrd ('string-append directory file)) ;the old format
-          (string-append directory file))
-         (('initrd (? string? file))
-          file)
-         (#f #f)))
-
-      (multiboot-modules
-       (match (assq 'multiboot-modules rest)
-         ((_ args) args)
-         (#f       '())))
-
-      (locale
-       (match (assq 'locale rest)
-         ((_ locale) locale)
-         (#f         #f)))
-
-      (store-device
-       ;; Linux device names like "/dev/sda1" are not suitable GRUB device
-       ;; identifiers, so we just filter them out.
-       (ensure-not-/dev
-        (match (assq 'store rest)
-          (('store ('device #f) _ ...)
-           root-device)
-          (('store ('device device) _ ...)
-           (device-sexp->device device))
-          (_                                      ;the old format
-           root-device))))
-
-      (store-directory-prefix
-       (match (assq 'store rest)
-         (('store . store-data)
-          (match (assq 'directory-prefix store-data)
-            (('directory-prefix prefix) prefix)
-            ;; No directory-prefix found.
-            (_ #f)))
-         (_
-          ;; No store found, old format.
-          #f)))
-
-      (store-crypto-devices
-       (match (assq 'store rest)
-         (('store . store-data)
-          (match (assq 'crypto-devices store-data)
-            (('crypto-devices (devices ...))
-             (map uuid-sexp->uuid devices))
-            (('crypto-devices dev)
-             (warning (G_ "unrecognized crypto-devices ~S at '~a'~%")
-                      dev (port-filename port))
-             '())
-            (_
-             ;; No crypto-devices found.
-             '())))
-         (_
-          ;; No store found, old format.
-          '())))
-
-      (store-mount-point
-       (match (assq 'store rest)
-         (('store ('device _) ('mount-point mount-point) _ ...)
-          mount-point)
-         (_                                       ;the old format
-          "/")))))
-    (x                                            ;unsupported format
-     (raise
-      (make-compound-condition
-       (formatted-message
-        (G_ "unrecognized boot parameters at '~a'~%")
-        (port-filename port))
-       (condition
-        (&fix-hint (hint (format #f (G_ "This probably means that this version
-of Guix is older than the one that created @file{~a}.  To address this, you
-need to update Guix:
-
-@example
-guix pull
-@end example")
-                                 (port-filename port))))))))))
-
-(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))
-         (version (boot-parameters-version params)))
-    (boot-parameters
-     (inherit params)
-     (kernel-arguments (append (bootable-kernel-arguments system root version)
-                               (boot-parameters-kernel-arguments params))))))
-
 (define (boot-parameters->menu-entry conf)
   "Return a <menu-entry> instance given CONF, a <boot-parameters> instance."
   (let* ((kernel (boot-parameters-kernel conf))
@@ -726,17 +480,6 @@ (define (swap-services os)
   (map (compose swap-service filter-deps)
        (operating-system-swap-devices os)))
 
-(define* (system-linux-image-file-name #:optional
-                                       (target (or (%current-target-system)
-                                                   (%current-system))))
-  "Return the basename of the kernel image file for TARGET."
-  (cond
-   ((string-prefix? "arm" target) "zImage")
-   ((string-prefix? "mips" target) "vmlinuz")
-   ((string-prefix? "aarch64" target) "Image")
-   ((string-prefix? "riscv64" target) "Image")
-   (else "bzImage")))
-
 (define (operating-system-kernel-file os)
   "Return an object representing the absolute file name of the kernel image of
 OS."
diff --git a/gnu/system/boot.scm b/gnu/system/boot.scm
new file mode 100644
index 0000000000..7bae9d2102
--- /dev/null
+++ b/gnu/system/boot.scm
@@ -0,0 +1,318 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2013-2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
+;;; Copyright © 2015, 2016 Alex Kost <alezost@gmail.com>
+;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
+;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2019 Meiyo Peng <meiyo.peng@gmail.com>
+;;; Copyright © 2019, 2020 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
+;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
+;;; Copyright © 2020, 2021 Brice Waegeneire <brice@waegenei.re>
+;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
+;;; Copyright © 2020, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2020, 2023 Janneke Nieuwenhuizen <jannek@gnu.org>
+;;; Copyright © 2020, 2022 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
+;;; Copyright © 2021 raid5atemyhomework <raid5atemyhomework@protonmail.com>
+;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
+;;; Copyright © 2023 Felix Lechner <felix.lechner@lease-up.com>
+;;;
+;;; 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 (gnu system boot)
+  #:use-module (guix gexp)
+  #:use-module (guix diagnostics)
+  #:use-module (guix i18n)
+  #:use-module (guix records)
+  #:use-module (guix store)
+  #:use-module (guix utils)
+  #:use-module (gnu bootloader)
+  #:use-module (gnu system file-systems)
+  #:use-module (gnu system uuid)
+  #:use-module (ice-9 format)
+  #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35)
+  #:use-module (rnrs bytevectors)
+  #:export (boot-parameters
+            boot-parameters?
+            boot-parameters-label
+            boot-parameters-root-device
+            boot-parameters-bootloader-name
+            boot-parameters-bootloader-menu-entries
+            boot-parameters-store-crypto-devices
+            boot-parameters-store-device
+            boot-parameters-store-directory-prefix
+            boot-parameters-store-mount-point
+            boot-parameters-locale
+            boot-parameters-kernel
+            boot-parameters-kernel-arguments
+            boot-parameters-initrd
+            boot-parameters-multiboot-modules
+            boot-parameters-version
+            %boot-parameters-version
+
+            read-boot-parameters
+            read-boot-parameters-file
+            bootable-kernel-arguments
+
+            ensure-not-/dev
+            system-linux-image-file-name))
+
+;;;
+;;; Boot parameters
+;;;
+
+;;; Version 1 was introduced early 2022 to mark the departure from long option
+;;; names such as '--load' to the more conventional initrd option names like
+;;; 'gnu.load'.
+;;;
+;;; When bumping the boot-parameters version, increment it by one (1).
+(define %boot-parameters-version 1)
+
+(define-record-type* <boot-parameters>
+  boot-parameters make-boot-parameters boot-parameters?
+  (label            boot-parameters-label)
+  ;; Because we will use the 'store-device' to create the GRUB search command,
+  ;; the 'store-device' has slightly different semantics than 'root-device'.
+  ;; The 'store-device' can be a file system uuid, a file system label, or #f,
+  ;; but it cannot be a device file name such as "/dev/sda3", since GRUB would
+  ;; not understand that.  The 'root-device', on the other hand, corresponds
+  ;; exactly to the device field of the <file-system> object representing the
+  ;; OS's root file system, so it might be a device file name like
+  ;; "/dev/sda3".  The 'store-directory-prefix' field contains #f or the store
+  ;; file name inside the 'store-device' as it is seen by GRUB, e.g. it would
+  ;; contain "/storefs" if the store is located in that subvolume of a btrfs
+  ;; partition.
+  (root-device      boot-parameters-root-device)
+  (bootloader-name  boot-parameters-bootloader-name)
+  (bootloader-menu-entries                        ;list of <menu-entry>
+   boot-parameters-bootloader-menu-entries)
+  (store-device     boot-parameters-store-device)
+  (store-mount-point boot-parameters-store-mount-point)
+  (store-directory-prefix boot-parameters-store-directory-prefix)
+  (store-crypto-devices boot-parameters-store-crypto-devices
+                        (default '()))
+  (locale           boot-parameters-locale)
+  (kernel           boot-parameters-kernel)
+  (kernel-arguments boot-parameters-kernel-arguments)
+  (initrd           boot-parameters-initrd)
+  (multiboot-modules boot-parameters-multiboot-modules)
+  (version          boot-parameters-version  ;positive integer
+                    (default %boot-parameters-version)))
+
+(define (read-boot-parameters port)
+  "Read boot parameters from PORT and return the corresponding
+<boot-parameters> object.  Raise an error if the format is unrecognized."
+  (define device-sexp->device
+    (match-lambda
+      (('uuid (? symbol? type) (? bytevector? bv))
+       (bytevector->uuid bv type))
+      (('file-system-label (? string? label))
+       (file-system-label label))
+      ((? bytevector? bv)                         ;old format
+       (bytevector->uuid bv 'dce))
+      ((? string? device)
+       (if (string-contains device ":/")
+           device ; nfs-root
+           ;; It used to be that we would not distinguish between labels and
+           ;; device names.  Try to infer the right thing here.
+           (if (string-prefix? "/" device)
+               device
+               (file-system-label device))))))
+  (define uuid-sexp->uuid
+    (match-lambda
+      (('uuid (? symbol? type) (? bytevector? bv))
+       (bytevector->uuid bv type))
+      (x
+       (warning (G_ "unrecognized uuid ~a at '~a'~%") x (port-filename port))
+       #f)))
+
+  ;; New versions are not backward-compatible, so only accept past and current
+  ;; versions, not future ones.
+  (define (version? n)
+    (member n (iota (1+ %boot-parameters-version))))
+
+  (match (read port)
+    (('boot-parameters ('version (? version? version))
+                       ('label label) ('root-device root)
+                       ('kernel kernel)
+                       rest ...)
+     (boot-parameters
+      (version version)
+      (label label)
+      (root-device (device-sexp->device root))
+
+      (bootloader-name
+       (match (assq 'bootloader-name rest)
+         ((_ args) args)
+         (#f       'grub))) ; for compatibility reasons.
+
+      (bootloader-menu-entries
+       (match (assq 'bootloader-menu-entries rest)
+         ((_ entries) (map sexp->menu-entry entries))
+         (#f          '())))
+
+      ;; In the past, we would store the directory name of linux instead of
+      ;; the absolute file name of its image.  Detect that and correct it.
+      (kernel (if (string=? kernel (direct-store-path kernel))
+                  (string-append kernel "/"
+                                 (system-linux-image-file-name))
+                  kernel))
+
+      (kernel-arguments
+       (match (assq 'kernel-arguments rest)
+         ((_ args) args)
+         (#f       '())))                         ;the old format
+
+      (initrd
+       (match (assq 'initrd rest)
+         (('initrd ('string-append directory file)) ;the old format
+          (string-append directory file))
+         (('initrd (? string? file))
+          file)
+         (#f #f)))
+
+      (multiboot-modules
+       (match (assq 'multiboot-modules rest)
+         ((_ args) args)
+         (#f       '())))
+
+      (locale
+       (match (assq 'locale rest)
+         ((_ locale) locale)
+         (#f         #f)))
+
+      (store-device
+       ;; Linux device names like "/dev/sda1" are not suitable GRUB device
+       ;; identifiers, so we just filter them out.
+       (ensure-not-/dev
+        (match (assq 'store rest)
+          (('store ('device #f) _ ...)
+           root-device)
+          (('store ('device device) _ ...)
+           (device-sexp->device device))
+          (_                                      ;the old format
+           root-device))))
+
+      (store-directory-prefix
+       (match (assq 'store rest)
+         (('store . store-data)
+          (match (assq 'directory-prefix store-data)
+            (('directory-prefix prefix) prefix)
+            ;; No directory-prefix found.
+            (_ #f)))
+         (_
+          ;; No store found, old format.
+          #f)))
+
+      (store-crypto-devices
+       (match (assq 'store rest)
+         (('store . store-data)
+          (match (assq 'crypto-devices store-data)
+            (('crypto-devices (devices ...))
+             (map uuid-sexp->uuid devices))
+            (('crypto-devices dev)
+             (warning (G_ "unrecognized crypto-devices ~S at '~a'~%")
+                      dev (port-filename port))
+             '())
+            (_
+             ;; No crypto-devices found.
+             '())))
+         (_
+          ;; No store found, old format.
+          '())))
+
+      (store-mount-point
+       (match (assq 'store rest)
+         (('store ('device _) ('mount-point mount-point) _ ...)
+          mount-point)
+         (_                                       ;the old format
+          "/")))))
+    (x                                            ;unsupported format
+     (raise
+      (make-compound-condition
+       (formatted-message
+        (G_ "unrecognized boot parameters at '~a'~%")
+        (port-filename port))
+       (condition
+        (&fix-hint (hint (format #f (G_ "This probably means that this version
+of Guix is older than the one that created @file{~a}.  To address this, you
+need to update Guix:
+
+@example
+guix pull
+@end example")
+                                 (port-filename port))))))))))
+
+(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))
+         (version (boot-parameters-version params)))
+    (boot-parameters
+     (inherit params)
+     (kernel-arguments (append (bootable-kernel-arguments system root version)
+                               (boot-parameters-kernel-arguments params))))))
+
+(define* (bootable-kernel-arguments system root-device version)
+  "Return a list of kernel arguments (gexps) to boot SYSTEM from ROOT-DEVICE.
+VERSION is the target version of the boot-parameters record."
+  ;; If the version is newer than 0, we use the new style initrd parameter
+  ;; names, otherwise we use the legacy ones.  This is to maintain backward
+  ;; compatibility when producing bootloader configurations for older
+  ;; generations.
+  (define version>0? (> version 0))
+  (let ((root (file-system-device->string root-device
+                                          #:uuid-type 'dce)))
+    (append
+     (if (string=? root "none")
+         '() ;  Ignore the case where the root is "none" (typically tmpfs).
+         ;; Note: Always use the DCE format because that's what
+         ;; (gnu build linux-boot) expects for the 'root'
+         ;; kernel command-line option.
+         (list (string-append (if version>0? "root=" "--root=") root)))
+     (list #~(string-append (if #$version>0? "gnu.system=" "--system=") #$system)
+           #~(string-append (if #$version>0? "gnu.load=" "--load=")
+                            #$system "/boot")))))
+
+(define (ensure-not-/dev device)
+  "If DEVICE starts with a slash, return #f.  This is meant to filter out
+Linux device names such as /dev/sda, and to preserve GRUB device names and
+file system labels."
+  (if (and (string? device) (string-prefix? "/" device))
+      #f
+      device))
+
+;; XXX: defined here instead of (gnu system) to prevent dependency loop
+(define* (system-linux-image-file-name #:optional
+                                       (target (or (%current-target-system)
+                                                   (%current-system))))
+  "Return the basename of the kernel image file for TARGET."
+  (cond
+   ((string-prefix? "arm" target) "zImage")
+   ((string-prefix? "mips" target) "vmlinuz")
+   ((string-prefix? "aarch64" target) "Image")
+   ((string-prefix? "riscv64" target) "Image")
+   (else "bzImage")))
+
+
+;;; boot.scm ends here
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index 0305128763..7000c470ed 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -70,6 +70,7 @@ (define-module (guix scripts system)
   #:use-module (gnu image)
   #:use-module (gnu system)
   #:use-module (gnu bootloader)
+  #:use-module (gnu system boot)
   #:use-module (gnu system file-systems)
   #:use-module (gnu system image)
   #:use-module (gnu system mapped-devices)
diff --git a/tests/boot-parameters.scm b/tests/boot-parameters.scm
index 03a1d01aff..2e7976aa6c 100644
--- a/tests/boot-parameters.scm
+++ b/tests/boot-parameters.scm
@@ -27,6 +27,7 @@ (define-module (test-boot-parameters)
   #:use-module (gnu bootloader)
   #:use-module (gnu bootloader grub)
   #:use-module (gnu system)
+  #:use-module (gnu system boot)
   #:use-module (gnu system file-systems)
   #:use-module (gnu system uuid)
   #:use-module ((guix diagnostics) #:select (formatted-message?))
-- 
2.45.2





  parent reply	other threads:[~2024-08-04  3:17 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-24  1:05 [bug#69343] [PATCH 00/12] Simplify bootloader data structures and procedures Felix Lechner via Guix-patches via
2024-02-24  1:51 ` [bug#69343] [PATCH 01/12] Fix bug where the extra menu entries for a bootloader were shown twice Felix Lechner via Guix-patches via
2024-02-24  1:51 ` [bug#69343] [PATCH 02/12] Move <boot-parameters> record to a separate file Felix Lechner via Guix-patches via
2024-02-24  1:51 ` [bug#69343] [PATCH 03/12] Also move boot-parameters->menu-entry Felix Lechner via Guix-patches via
2024-02-24  1:51 ` [bug#69343] [PATCH 04/12] Rename seconds->string procedure to epoch->date-string Felix Lechner via Guix-patches via
2024-02-24  1:51 ` [bug#69343] [PATCH 05/12] Move epoch->date-string to gnu/system/boot.scm and use it elsewhere Felix Lechner via Guix-patches via
2024-02-24  1:51 ` [bug#69343] [PATCH 06/12] Offer a uniform decorated-boot-label and use it Felix Lechner via Guix-patches via
2024-02-24  1:51 ` [bug#69343] [PATCH 07/12] Rename boot-parameters to boot-alternatives when appropriate Felix Lechner via Guix-patches via
2024-02-24  1:51 ` [bug#69343] [PATCH 08/12] Rename two remote variables confusingly named 'generations' Felix Lechner via Guix-patches via
2024-02-24  1:51 ` [bug#69343] [PATCH 09/12] Give a separate name to a commonly used expression Felix Lechner via Guix-patches via
2024-02-24  1:51 ` [bug#69343] [PATCH 10/12] Simplify profile->boot-alternatives Felix Lechner via Guix-patches via
2024-02-24  1:51 ` [bug#69343] [PATCH 11/12] Split generation->boot-parameters out of profile->boot-alternatives Felix Lechner via Guix-patches via
2024-02-24  1:51 ` [bug#69343] [PATCH 12/12] Encapsulate <boot-parameters> to retain generation, system-path and epoch Felix Lechner via Guix-patches via
2024-03-02 23:46 ` [bug#69343] Simplify bootloader data structures and procedures Lilah Tascheter via Guix-patches
2024-03-08  8:11 ` [bug#69343] [PATCH v2 00/12] " Lilah Tascheter via Guix-patches
2024-03-08  8:11   ` [bug#69343] [PATCH v2 01/12] Fix bug where the extra menu entries for a bootloader were shown twice Lilah Tascheter via Guix-patches
2024-03-08  8:11   ` [bug#69343] [PATCH v2 02/12] Move <boot-parameters> record to a separate file Lilah Tascheter via Guix-patches
2024-03-08  8:11   ` [bug#69343] [PATCH v2 03/12] Also move boot-parameters->menu-entry Lilah Tascheter via Guix-patches
2024-03-08  8:12   ` [bug#69343] [PATCH v2 04/12] Rename seconds->string procedure to epoch->date-string Lilah Tascheter via Guix-patches
2024-03-08  8:12   ` [bug#69343] [PATCH v2 05/12] Move epoch->date-string to gnu/system/boot.scm and use it elsewhere Lilah Tascheter via Guix-patches
2024-03-08  8:12   ` [bug#69343] [PATCH v2 06/12] Offer a uniform decorated-boot-label and use it Lilah Tascheter via Guix-patches
2024-03-08  8:12   ` [bug#69343] [PATCH v2 07/12] Rename boot-parameters to boot-alternatives when appropriate Lilah Tascheter via Guix-patches
2024-03-08  8:12   ` [bug#69343] [PATCH v2 08/12] Rename two remote variables confusingly named 'generations' Lilah Tascheter via Guix-patches
2024-03-08  8:12   ` [bug#69343] [PATCH v2 09/12] Give a separate name to a commonly used expression Lilah Tascheter via Guix-patches
2024-03-08  8:12   ` [bug#69343] [PATCH v2 10/12] Simplify profile->boot-alternatives Lilah Tascheter via Guix-patches
2024-03-08  8:12   ` [bug#69343] [PATCH v2 11/12] Split generation->boot-parameters out of profile->boot-alternatives Lilah Tascheter via Guix-patches
2024-03-08  8:12   ` [bug#69343] [PATCH v2 12/12] Encapsulate <boot-parameters> to retain generation, system-path and epoch Lilah Tascheter via Guix-patches
2024-03-08 16:33   ` [bug#69343] Simplify bootloader data structures and procedures Felix Lechner via Guix-patches via
2024-08-04  3:13 ` [bug#69343] [PATCH v3 00/12] " Lilah Tascheter via Guix-patches
2024-08-04  3:13   ` [bug#69343] [PATCH v3 01/12] Fix bug where the extra menu entries for a bootloader were shown twice Lilah Tascheter via Guix-patches
2024-08-04  3:13   ` Lilah Tascheter via Guix-patches [this message]
2024-08-04  3:13   ` [bug#69343] [PATCH v3 03/12] Also move boot-parameters->menu-entry Lilah Tascheter via Guix-patches
2024-08-04  3:13   ` [bug#69343] [PATCH v3 04/12] Rename seconds->string procedure to epoch->date-string Lilah Tascheter via Guix-patches
2024-08-04  3:13   ` [bug#69343] [PATCH v3 05/12] Move epoch->date-string to gnu/system/boot.scm and use it elsewhere Lilah Tascheter via Guix-patches
2024-08-04  3:13   ` [bug#69343] [PATCH v3 06/12] Offer a uniform decorated-boot-label and use it Lilah Tascheter via Guix-patches
2024-08-04  3:13   ` [bug#69343] [PATCH v3 07/12] Rename boot-parameters to boot-alternatives when appropriate Lilah Tascheter via Guix-patches
2024-08-04  3:13   ` [bug#69343] [PATCH v3 08/12] Rename two remote variables confusingly named 'generations' Lilah Tascheter via Guix-patches
2024-08-04  3:13   ` [bug#69343] [PATCH v3 09/12] Give a separate name to a commonly used expression Lilah Tascheter via Guix-patches
2024-08-04  3:13   ` [bug#69343] [PATCH v3 10/12] Simplify profile->boot-alternatives Lilah Tascheter via Guix-patches
2024-08-04  3:13   ` [bug#69343] [PATCH v3 11/12] Split generation->boot-parameters out of profile->boot-alternatives Lilah Tascheter via Guix-patches
2024-08-04  3:13   ` [bug#69343] [PATCH v3 12/12] Encapsulate <boot-parameters> to retain generation, system-path and epoch Lilah Tascheter via Guix-patches
2024-09-05  7:13   ` [bug#69343] [PATCH v3 00/12] Simplify bootloader data structures and procedures Herman Rimm via Guix-patches via
2024-09-20  4:15 ` [bug#69343] [PATCH v4 00/11] " Lilah Tascheter via Guix-patches
2024-09-20  4:15   ` [bug#69343] [PATCH v4 01/11] Fix bug where the extra menu entries for a bootloader were shown twice Lilah Tascheter via Guix-patches
2024-09-20  4:15   ` [bug#69343] [PATCH v4 02/11] Move <boot-parameters> record to a separate file Lilah Tascheter via Guix-patches
2024-09-20  4:15   ` [bug#69343] [PATCH v4 03/11] Rename seconds->string procedure to epoch->date-string Lilah Tascheter via Guix-patches
2024-09-20  4:15   ` [bug#69343] [PATCH v4 04/11] Move epoch->date-string to gnu/system/boot.scm and use it elsewhere Lilah Tascheter via Guix-patches
2024-09-20  4:15   ` [bug#69343] [PATCH v4 05/11] Offer a uniform decorated-boot-label and use it Lilah Tascheter via Guix-patches
2024-09-20  4:16   ` [bug#69343] [PATCH v4 06/11] Rename boot-parameters to boot-alternatives when appropriate Lilah Tascheter via Guix-patches
2024-09-20  4:16   ` [bug#69343] [PATCH v4 07/11] Rename two remote variables confusingly named 'generations' Lilah Tascheter via Guix-patches
2024-09-20  4:16   ` [bug#69343] [PATCH v4 08/11] Give a separate name to a commonly used expression Lilah Tascheter via Guix-patches
2024-09-20  4:16   ` [bug#69343] [PATCH v4 09/11] Simplify profile->boot-alternatives Lilah Tascheter via Guix-patches
2024-09-20  4:16   ` [bug#69343] [PATCH v4 10/11] Split generation->boot-parameters out of profile->boot-alternatives Lilah Tascheter via Guix-patches
2024-09-20  4:16   ` [bug#69343] [PATCH v4 11/11] Encapsulate <boot-parameters> to retain generation, system-path and epoch Lilah Tascheter via Guix-patches
2024-09-21 10:23 ` [bug#69343] [PATCH v5 00/10] Simplify bootloader data structures and procedures Herman Rimm via Guix-patches via
2024-09-21 10:23   ` [bug#69343] [PATCH v5 01/10] Fix bug where the extra menu entries for a bootloader were shown twice Herman Rimm via Guix-patches via
2024-09-21 10:23   ` [bug#69343] [PATCH v5 02/10] Move <boot-parameters> record to a separate file Herman Rimm via Guix-patches via
2024-09-21 10:23   ` [bug#69343] [PATCH v5 03/10] Rename seconds->string procedure to epoch->date-string Herman Rimm via Guix-patches via
2024-09-21 10:23   ` [bug#69343] [PATCH v5 04/10] Move epoch->date-string to gnu/system/boot.scm and use it elsewhere Herman Rimm via Guix-patches via
2024-09-21 10:23   ` [bug#69343] [PATCH v5 05/10] Offer a uniform decorated-boot-label and use it Herman Rimm via Guix-patches via
2024-09-21 10:23   ` [bug#69343] [PATCH v5 06/10] Rename boot-parameters to boot-alternatives when appropriate Herman Rimm via Guix-patches via
2024-09-21 10:23   ` [bug#69343] [PATCH v5 07/10] Rename two remote variables confusingly named 'generations' Herman Rimm via Guix-patches via
2024-09-21 10:23   ` [bug#69343] [PATCH v5 08/10] Give a separate name to a commonly used expression Herman Rimm via Guix-patches via
2024-09-21 10:23   ` [bug#69343] [PATCH v5 09/10] Split system->boot-parameters out of profile->boot-alternatives Herman Rimm via Guix-patches via
2024-09-21 10:23   ` [bug#69343] [PATCH v5 10/10] Encapsulate <boot-parameters> to retain generation, system-path and epoch Herman Rimm via Guix-patches via

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=84d2bacfdda34a9c8be2ed13b3d348280f9ba2ef.1722741214.git.lilah@lunabee.space \
    --to=guix-patches@gnu.org \
    --cc=69343@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=felix.lechner@lease-up.com \
    --cc=guix@cbaines.net \
    --cc=lilah@lunabee.space \
    --cc=ludo@gnu.org \
    --cc=me@tobias.gr \
    --cc=othacehe@gnu.org \
    --cc=zimon.toutoune@gmail.com \
    /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).