Subject: [bug#73202] [PATCH] Preparation for bootloader rewrite.

From: Lilah Tascheter <[email-masked]>
Date: Fri, 04 Oct 2024 00:07:16 -0500

hey herman!

> ;; In (gnu bootloader grub):
> (define (grub-efi-default-targets esp)
>   (tree->target ; like arborify
>                 (bootloader-target
>                   (type 'esp)
>                   (path esp)
>                   (targets ; counterpart of offset
>                            (list (bootloader-target
>                                    (type 'vendir)
>                                    (path "EFI/Guix"))
>                                  (bootloader-target
>                                    (type 'install)
>                                    (path "grub")))))))
how would this handle root offsets, eg by guix system init? is
everything assumed to be offset from root? I'm also worried about
indentation growing too quickly. otherwise, though, it's definately an
improvement over offset!

> ;; This is the same as (grub-efi-default-targets "boot").  It could
> be
> ;; exported standalone, instead of using bootloader default-targets.
> (define %grub-efi-default-targets
>   '((esp     . "/boot")
>     (install . "/boot/EFI/Guix")
>     (vendir  . "/boot/grub")))
> 
> ;; A simple consequence of this change is that this:
> (with-targets %grub-efi-default-targets
>   (('install => (path :path))
>    ...))
> ;; becomes:
> (let ((install-path (assoc-ref %grub-efi-default-targets 'install)))
>   ...)
> 
> ;; But e.g. device is provided separately (or derived from path):
> (with-targets %grub-efi-default-targets
>   (('esp => (device :device))
>    ...))
> ;; becomes:
> (let* ((path (assoc-ref %grub-efi-default-targets 'esp))
>        ;; A single root-device is provided in addition to targets.
>        (device (root-device->block-device root-device path)))
>   ...)
> 
> ;; This procedure is in (gnu bootloader).  Something like:
> (define (root-device->block-device device path)
>   (match device
>     ((? block-device?) device) ; string with /dev/ prefix
>     ((? uuid?) (find-partition-for-uuid device))
>     ((? string?) (find-partition-for-label device))
>     ;; This might be necessary, but should not be relied on.
>     (_ (mount-source (find-mount path)))))
how are you replacing device-local paths? some bootloaders need that
information to access files before fully loading. also, if the path,
device, label, and uuid fields are combined, the guix system image
won't be able to get all the info it needs to the bootloader
installers. uuid or label needs to be there to identify the device on-
boot, but also path, device, and devpath are required to actually
install bootloader files.

also, one reason with-targets exists is as a safeguard for future
people writing bootloaders. guix system image tends to be overlooked,
so it performs checks to make sure the bootloader targets requested are
available during image generation.

> ;; Example user configuration:
> (define %grub-efi-bootloader
>   (bootloader-configuration
>     (bootloader grub-efi-bootloader)
>     ;; This is for bootloader configuration (not installation), e.g.
>     ;; GRUB search or install-efi disk argument.
>     (root-device "UUID, label, or block device.")
>     ;; This is complementary to root-device.  It will configure some
>     ;; files to be fetched remotely instead of installed.
>     (tftp "Varies for UEFI/GRUB/U-Boot.")))
> 
> (operating-system
>   (bootloader (list %grub-efi-bootloader))
>   ;; This is shared between bootloaders.  Ideally, it does not affect
>   ;; which files are installed or their contents, but only the
> location.
>   (bootloader-targets (grub-efi-default-targets "boot")))
I do really like the conceptual separation between configuration and
installation! though, users would now need to enter the root device
details three times, potentially in inconsistant formats.

- lilah