Subject: bug#67109: ‘efi32-esp’ image support pulls in host-side code

From: Ludovic Courtès <[email-masked]>
Date: Sat, 11 Nov 2023 16:45:09 +0100

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:

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix system image -t efi32-raw gnu/system/examples/bare-bones.tmpl
guix system: error: EFI bootloader required with GPT partitioning
--8<---------------cut here---------------end--------------->8---

Thanks in advance!

Ludo’.

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 <[email-masked]>
+;;; Copyright © 2013-2020, 2023 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2016 Christine Lemmer-Webber <[email-masked]>
 ;;; Copyright © 2016, 2017 Leo Famulari <[email-masked]>
 ;;; Copyright © 2017 Marius Bakke <[email-masked]>
@@ -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