gnu: bootloader: extlinux: Rewrite completely.

* gnu/bootloader/extlinux.scm (install-extlinux-config): Add procedure.
(extlinux-configuration-file): Delete procedure.
(install-extlinux): Use install-extlinux-config.
(install-extlinux-mbr, install-extlinux-gpt): Delete variables.
(extlinux-bootloader): Update to new bootloader record.
(extlinux-gpt-bootloader): Update extlinux-bootloader-gpt to this.
(extlinux-bootloader-gpt): Deprecate variable.
* gnu/tests/install.scm (%minimal-extlinux-os)[bootloader]: Use proper
extlinux variable.

Change-Id: I3654d160f7306bb45a78b82ea6b249ff4281f739
This commit is contained in:
Lilah Tascheter 2024-08-06 19:11:17 -05:00 committed by Ryan Schanzenbacher
parent f171385ab4
commit a0a99c446b
Signed by: ryan77627
GPG key ID: 81B0E222A3E2308E
2 changed files with 74 additions and 77 deletions

View file

@ -2,6 +2,7 @@
;;; Copyright © 2017 David Craven <david@craven.ch> ;;; Copyright © 2017 David Craven <david@craven.ch>
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com> ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2022 Reza Alizadeh Majd <r.majd@pantherx.org> ;;; Copyright © 2022 Reza Alizadeh Majd <r.majd@pantherx.org>
;;; Copyright © 2024 Lilah Tascheter <lilah@lunabee.space>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -21,112 +22,108 @@
(define-module (gnu bootloader extlinux) (define-module (gnu bootloader extlinux)
#:use-module (gnu bootloader) #:use-module (gnu bootloader)
#:use-module (gnu packages bootloaders) #:use-module (gnu packages bootloaders)
#:use-module (gnu system boot)
#:use-module (guix gexp) #:use-module (guix gexp)
#:use-module (guix deprecation)
#:use-module (guix records)
#:use-module (guix utils) #:use-module (guix utils)
#:export (extlinux-bootloader #:export (install-extlinux-config ; for u-boot
extlinux-bootloader
extlinux-gpt-bootloader
extlinux-bootloader-gpt)) extlinux-bootloader-gpt))
(define* (extlinux-configuration-file config entries
#:key ;;;
(system (%current-system)) ;;; Config procedures.
(old-entries '()) ;;;
#:allow-other-keys)
"Return the U-Boot configuration file corresponding to CONFIG, a
<u-boot-configuration> object, and where the store is available at STORE-FS, a
<file-system> object. OLD-ENTRIES is taken to be a list of menu entries
corresponding to old generations of the system."
(define all-entries (define* (install-extlinux-config #:key bootloader-config
(append entries (bootloader-configuration-menu-entries config))) current-boot-alternative
old-boot-alternatives
(define with-fdtdir? #:allow-other-keys)
(bootloader-configuration-device-tree-support? config)) "Installer for the extlinux configuration file, meant to be shared by
all bootloaders that use the format to specify boot options."
(define (menu-entry->gexp entry) (match-bootloader-configuration
(let ((label (menu-entry-label entry)) bootloader-config
(kernel (menu-entry-linux entry)) (targets menu-entries device-tree-support? timeout)
(kernel-arguments (menu-entry-linux-arguments entry)) (define (menu-entry->gexp entry)
(initrd (menu-entry-initrd entry))) (match-menu-entry entry (label linux linux-arguments initrd)
#~(format port "LABEL ~a (let* ((linux (normalize-file entry linux))
(fdt #~(string-append "FDTDIR " (dirname #$linux) "/lib/dtbs")))
#~(format port "LABEL ~a
MENU LABEL ~a MENU LABEL ~a
KERNEL ~a KERNEL ~a
~a ~a
INITRD ~a INITRD ~a
APPEND ~a APPEND ~a
~%" ~%"
#$label #$label #$label #$label #$linux
#$kernel #$(if device-tree-support? fdt "")
(if #$with-fdtdir? #$(normalize-file entry initrd)
(string-append "FDTDIR " (dirname #$kernel) "/lib/dtbs") (string-join (list #$@linux-arguments))))))
"")
#$initrd
(string-join (list #$@kernel-arguments)))))
(define builder (let ((entries (cons (boot-alternative->menu-entry
#~(call-with-output-file #$output current-boot-alternative)
(lambda (port) (append menu-entries
(let ((timeout #$(bootloader-configuration-timeout config))) (map boot-alternative->menu-entry
(format port "# This file was generated from your Guix configuration. Any changes old-boot-alternatives)))))
(with-targets targets
(('extlinux => (path :path))
#~(begin
(mkdir-p #$path)
(call-with-output-file #$(string-append path
"/extlinux.conf")
(lambda (port)
(format port "\
# This file was generated from your Guix configuration. Any changes
# will be lost upon reconfiguration. # will be lost upon reconfiguration.
UI menu.c32 UI menu.c32
MENU TITLE GNU Guix Boot Options MENU TITLE GNU Guix Boot Options
PROMPT ~a PROMPT ~a
TIMEOUT ~a~%" TIMEOUT ~a~%" ; Timeout is expressed in tenths of a second.
(if (> timeout 0) 1 0) #$(if (> timeout 0) 1 0) #$(* 10 timeout))
;; timeout is expressed in 1/10s of seconds. #$@(map menu-entry->gexp entries)))))))))
(* 10 timeout))
#$@(map menu-entry->gexp all-entries)
#$@(if (pair? old-entries)
#~((format port "~%")
#$@(map menu-entry->gexp old-entries)
(format port "~%"))
#~())))))
(computed-file "extlinux.conf" builder
#:options '(#:local-build? #t
#:substitutable? #f)))
;;; ;;;
;;; Install procedures. ;;; Install procedure.
;;; ;;;
(define (install-extlinux mbr) (define (install-extlinux mbr)
#~(lambda (bootloader device mount-point) (lambda* (#:key bootloader-config #:allow-other-keys . args)
(let ((extlinux (string-append bootloader "/sbin/extlinux")) (with-targets (bootloader-configuration-targets bootloader-config)
(install-dir (string-append mount-point "/boot/extlinux")) (('extlinux => (path :path))
(syslinux-dir (string-append bootloader "/share/syslinux"))) #~(begin
(for-each (lambda (file) #$(apply install-extlinux-config args)
(install-file file install-dir)) (copy-recursively #$(file-append syslinux "/share/syslinux") #$path)
(find-files syslinux-dir "\\.c32$")) (invoke/quiet #+(file-append syslinux "/sbin/extlinux")
(invoke/quiet extlinux "--install" install-dir) "--install" #$path)))
(write-file-on-device (string-append syslinux-dir "/" #$mbr) (('disk => (disk :device))
440 device 0)))) #~(write-file-on-device #$(file-append syslinux "/share/syslinux/" mbr)
440 #$disk 0)))))
(define install-extlinux-mbr
(install-extlinux "mbr.bin"))
(define install-extlinux-gpt
(install-extlinux "gptmbr.bin"))
;;; ;;;
;;; Bootloader definitions. ;;; Bootloader definitions.
;;; ;;;
(define extlinux-bootloader (define extlinux-bootloader
(bootloader (bootloader
(name 'extlinux) (name 'extlinux)
(package syslinux) (default-targets (list (bootloader-target
(installer install-extlinux-mbr) (type 'install)
(configuration-file "/boot/extlinux/extlinux.conf") (offset 'root)
(configuration-file-generator extlinux-configuration-file))) (path "boot"))
(bootloader-target
(type 'extlinux)
(offset 'install)
(path "extlinux"))))
(installer (install-extlinux "mbr.bin"))))
(define extlinux-bootloader-gpt (define extlinux-gpt-bootloader
(bootloader (bootloader
(inherit extlinux-bootloader) (inherit extlinux-bootloader)
(installer install-extlinux-gpt))) (installer (install-extlinux "gptmbr.bin"))))
(define-deprecated/alias extlinux-bootloader-gpt extlinux-gpt-bootloader)

View file

@ -140,7 +140,7 @@ (define-os-with-source (%minimal-extlinux-os
(locale "en_US.UTF-8") (locale "en_US.UTF-8")
(bootloader (bootloader-configuration (bootloader (bootloader-configuration
(bootloader extlinux-bootloader-gpt) (bootloader extlinux-gpt-bootloader)
(targets (list "/dev/vdb")))) (targets (list "/dev/vdb"))))
(kernel-arguments '("console=ttyS0")) (kernel-arguments '("console=ttyS0"))
(file-systems (cons (file-system (file-systems (cons (file-system