‘efi32-esp’ image support pulls in host-side code

  • Open
  • quality assurance status badge
Details
3 participants
  • Ludovic Courtès
  • Ludovic Courtès
  • Mathieu Othacehe
Owner
unassigned
Submitted by
Ludovic Courtès
Severity
normal
L
L
Ludovic Courtès wrote on 11 Nov 2023 16:45
(address . bug-guix@gnu.org)
874jhs1egq.fsf@inria.fr
Hello,

I noticed that 62c86c8391ceb8953ca972498fd75ea9298b85ff pulls in
host-side code on the “build side”, via (guix utils), meaning that the
closure of the (gnu build image) module would now include 80 modules.

This change also introduces uses of ‘target-x86?’ and ‘target-arm?’ on
the build side that are unlikely to have the intended effect because the
check is then done based on the native system type when running the
build process. Last, the ‘cond’ form in that commit lacks an ‘else’
clause.

Thus I’m proposing the fix below. How can I test it though? I get:

Toggle snippet (4 lines)
$ ./pre-inst-env guix system image -t efi32-raw gnu/system/examples/bare-bones.tmpl
guix system: error: EFI bootloader required with GPT partitioning

Thanks in advance!

Ludo’.
Toggle diff (58 lines)
diff --git a/gnu/build/image.scm b/gnu/build/image.scm
index 49dc01c0d1..63262a4ffe 100644
--- a/gnu/build/image.scm
+++ b/gnu/build/image.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2013-2020, 2023 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 Christine Lemmer-Webber <cwebber@dustycloud.org>
;;; Copyright © 2016, 2017 Leo Famulari <leo@famulari.name>
;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
@@ -29,7 +29,6 @@ (define-module (gnu build image)
#:use-module (guix build syscalls)
#:use-module (guix build utils)
#:use-module (guix store database)
- #:use-module (guix utils)
#:use-module (gnu build bootloader)
#:use-module (gnu build install)
#:use-module (gnu build linux-boot)
@@ -191,13 +190,11 @@ (define* (initialize-efi-partition root
(define* (initialize-efi32-partition root
#:key
grub-efi32
+ grub-targets
#:allow-other-keys)
"Install in ROOT directory, an EFI 32bit loader using GRUB-EFI32."
(install-efi-loader grub-efi32 root
- #:targets (cond ((target-x86?)
- '("i386-efi" . "BOOTIA32.EFI"))
- ((target-arm?)
- '("arm-efi" . "BOOTARM.EFI")))))
+ #:targets grub-targets))
(define* (initialize-root-partition root
#:key
diff --git a/gnu/system/image.scm b/gnu/system/image.scm
index a990c4f861..49d4287a74 100644
--- a/gnu/system/image.scm
+++ b/gnu/system/image.scm
@@ -136,7 +136,17 @@ (define esp-partition
(define esp32-partition
(partition
(inherit esp-partition)
- (initializer (gexp initialize-efi32-partition))))
+ (initializer
+ (let-system (system target)
+ (let ((targets (cond ((target-x86? (or target system))
+ #~'("i386-efi" . "BOOTIA32.EFI"))
+ ((target-arm? (or target system))
+ #~'("arm-efi" . "BOOTARM.EFI"))
+ (else #f))))
+ #~(lambda (root . args)
+ (apply initialize-efi32-partition root
+ #:grub-targets #$targets
+ args)))))))
(define root-partition
(partition
M
M
Mathieu Othacehe wrote on 14 Nov 2023 21:52
(name . Ludovic Courtès)(address . ludovic.courtes@inria.fr)
871qcskqgc.fsf@gnu.org
Hey,

Thanks for investigating this!

Toggle quote (5 lines)
> Thus I’m proposing the fix below. How can I test it though? I get:
>
> $ ./pre-inst-env guix system image -t efi32-raw gnu/system/examples/bare-bones.tmpl
> guix system: error: EFI bootloader required with GPT partitioning

I added this check recently because we do not currently support
installing the `grub-bootloader` on a non-MBR disk.

The way to test your change is to switch the bare-bones system
bootloader to `grub-efi-bootloader`, this way:

Toggle snippet (14 lines)
diff --git a/gnu/system/examples/bare-bones.tmpl b/gnu/system/examples/bare-bones.tmpl
index dc6aff5273..e11d4bd5ee 100644
--- a/gnu/system/examples/bare-bones.tmpl
+++ b/gnu/system/examples/bare-bones.tmpl
@@ -18,8 +18,9 @@
;; target hard disk, and "my-root" is the label of the target
;; root file system.
(bootloader (bootloader-configuration
- (bootloader grub-bootloader)
- (targets '("/dev/sdX"))))
+ (bootloader grub-efi-bootloader)
+ (targets '("/boot/efi"))))

We then have the following error:

Toggle snippet (3 lines)
guix system: error: #<gexp (lambda (root . args) (apply initialize-efi32-partition root #:grub-targets #<gexp-input #<gexp (quote ("i386-efi" . "BOOTIA32.EFI")) gnu/system/image.scm:142:28 7fef96f85390>:out> args)) gnu/system/image.scm:146:8 7fef96f85360>: invalid G-expression input

Mathieu
M
M
Mathieu Othacehe wrote on 25 Nov 2023 15:33
(name . Ludovic Courtès)(address . ludovic.courtes@inria.fr)
87bkbhucle.fsf@gnu.org
Hello,

Toggle quote (6 lines)
> guix system: error: #<gexp (lambda (root . args) (apply
> initialize-efi32-partition root #:grub-targets #<gexp-input #<gexp
> (quote ("i386-efi" . "BOOTIA32.EFI")) gnu/system/image.scm:142:28
> 7fef96f85390>:out> args)) gnu/system/image.scm:146:8 7fef96f85360>:
> invalid G-expression input

Expressed that way, I no longer have this error and `target` seems to
take the expected value, WDYT?

Toggle snippet (16 lines)
(define esp32-partition
(partition
(inherit esp-partition)
(initializer
#~(lambda (root . args)
(let ((targets '#$(let-system (system target)
(cond ((target-x86? (or target system))
'("i386-efi". "BOOTIA32.EFI"))
((target-arm? (or target system))
'("arm-efi" . "BOOTARM.EFI"))
(else #f)))))
(apply initialize-efi32-partition root
#:grub-targets targets
args))))))

Thanks,

Mathieu
L
L
Ludovic Courtès wrote on 27 Nov 2023 10:07
(name . Mathieu Othacehe)(address . othacehe@gnu.org)
87zfyzy36r.fsf@gnu.org
Hi,

Mathieu Othacehe <othacehe@gnu.org> skribis:

Toggle quote (24 lines)
>> guix system: error: #<gexp (lambda (root . args) (apply
>> initialize-efi32-partition root #:grub-targets #<gexp-input #<gexp
>> (quote ("i386-efi" . "BOOTIA32.EFI")) gnu/system/image.scm:142:28
>> 7fef96f85390>:out> args)) gnu/system/image.scm:146:8 7fef96f85360>:
>> invalid G-expression input
>
> Expressed that way, I no longer have this error and `target` seems to
> take the expected value, WDYT?
>
> (define esp32-partition
> (partition
> (inherit esp-partition)
> (initializer
> #~(lambda (root . args)
> (let ((targets '#$(let-system (system target)
> (cond ((target-x86? (or target system))
> '("i386-efi". "BOOTIA32.EFI"))
> ((target-arm? (or target system))
> '("arm-efi" . "BOOTARM.EFI"))
> (else #f)))))
> (apply initialize-efi32-partition root
> #:grub-targets targets
> args))))))

Am I right that it breaks if we do:

(let ((targets #$(let-system …
#~'("i386-efi". "BOOTIA32.EFI"))))
…)

?

That would be the “correct” way to do it, but the problem is that the
body of ‘let-system’ is supposed to evaluate to a file-like object,
which is not what we’re trying to do here.

Hmm, annoying.

Thanks,
Ludo’.
?