From a90ea1bdebc997ce275c1b03b9e44b78c712b526 Mon Sep 17 00:00:00 2001 From: Hilton Chain Date: Sat, 27 Sep 2025 23:21:35 +0800 Subject: [PATCH] bootloader: Add uefi-uki-removable-bootloader. * modules/rosenthal/bootloader/uki.scm: New file. --- modules/rosenthal/bootloader/uki.scm | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 modules/rosenthal/bootloader/uki.scm diff --git a/modules/rosenthal/bootloader/uki.scm b/modules/rosenthal/bootloader/uki.scm new file mode 100644 index 0000000..2b813de --- /dev/null +++ b/modules/rosenthal/bootloader/uki.scm @@ -0,0 +1,66 @@ +;;; Copyright © 2024 Lilah Tascheter +;;; Copyright © 2024, 2025 Hilton Chain +;;; SPDX-License-Identifier: GPL-3.0-or-later + +(define-module (rosenthal bootloader uki) + #:use-module (srfi srfi-1) + #:use-module (guix gexp) + #:use-module (guix modules) + #:use-module (guix utils) + #:use-module (gnu bootloader) + #:use-module (rosenthal packages bootloaders) + #:export (uefi-uki-removable-bootloader)) + +(define script-path "/boot/install-uki.scm") + +(define (uefi-uki-configuration-file config entries . rest) + + (define (menu-entry->ukify-args entry) + (let* ((label (menu-entry-label entry)) + (linux (menu-entry-linux entry)) + (initrd (menu-entry-initrd entry)) + (arguments (menu-entry-linux-arguments entry)) + (boot (bootloader-configuration-bootloader config)) + (stub (bootloader-package boot))) + #~(list "--os-release" #$label + "--linux" #$linux + "--initrd" #$initrd + "--cmdline" (string-join (list #$@arguments)) + "--stub" #$(file-append stub "/libexec/" (systemd-stub-name))))) + + (program-file "install-uki" + (with-imported-modules (source-module-closure '((guix build utils))) + #~(begin + (use-modules (srfi srfi-1) + (guix build utils)) + (let* ((ukify #$(file-append ukify "/bin/ukify")) + (installation-path + (format #f "~a/EFI/BOOT/BOOT~a.EFI" + (second (command-line)) + #$(cond + ((target-x86-32?) "IA32") + ((target-x86-64?) "X64") + ((target-arm32?) "ARM") + ((target-aarch64?) "AA64") + ((target-riscv64?) "RISCV64"))))) + (mkdir-p (dirname installation-path)) + (apply invoke ukify "build" "--output" installation-path + #$(menu-entry->ukify-args (first entries)))))))) + +(define install-uefi-uki + #~(lambda (bootloader target mount-point) + (invoke (string-append mount-point #$script-path) + (string-append mount-point target)))) + +;; ‘configuration-file’ here is actually an activation script to be invoked by +;; ‘installer’. +;; FIXME: Not expected by ‘reinstall-bootloader’ in (guix scripts system). +;; NOTE: Faking name here to support rolling-back with '--no-bootloader' option. +(define uefi-uki-removable-bootloader + (bootloader + (name 'grub-efi-removable-bootloader) + (package systemd-stub) + (installer install-uefi-uki) + (disk-image-installer #f) + (configuration-file script-path) + (configuration-file-generator uefi-uki-configuration-file)))