Subject: [PATCH] Preparation for bootloader rewrite.

From: Herman Rimm <[email-masked]>
Date: Thu, 3 Oct 2024 22:32:30 +0200

Hi Lilah,

I wrote a series of annotated Guile code snippets, regarding an
alternative implementation of bootloader-target, and example user
configuration (with tftp/NFS).  See below, and please let me know what
you think.

Cheers,
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")))))))

;; 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)))))

;; 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")))