1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
| | ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 David Craven <david@craven.ch>
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2022 Reza Alizadeh Majd <r.majd@pantherx.org>
;;; Copyright © 2024 Lilah Tascheter <lilah@lunabee.space>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu bootloader extlinux)
#:use-module (gnu bootloader)
#:use-module (gnu packages bootloaders)
#:use-module (gnu system boot)
#:use-module (guix gexp)
#:use-module (guix deprecation)
#:use-module (guix records)
#:use-module (guix utils)
#:export (install-extlinux-config ; for u-boot
extlinux-bootloader
extlinux-gpt-bootloader
extlinux-bootloader-gpt))
\f
;;;
;;; Config procedures.
;;;
(define* (install-extlinux-config #:key bootloader-config
current-boot-alternative
old-boot-alternatives
#:allow-other-keys)
"Installer for the extlinux configuration file, meant to be shared by
all bootloaders that use the format to specify boot options."
(match-bootloader-configuration
bootloader-config
(targets menu-entries device-tree-support? timeout)
(define (menu-entry->gexp entry)
(match-menu-entry entry (label linux linux-arguments initrd)
(let* ((linux (normalize-file entry linux))
(fdt #~(string-append "FDTDIR " (dirname #$linux) "/lib/dtbs")))
#~(format port "LABEL ~a
MENU LABEL ~a
KERNEL ~a
~a
INITRD ~a
APPEND ~a
~%"
#$label #$label #$linux
#$(if device-tree-support? fdt "")
#$(normalize-file entry initrd)
(string-join (list #$@linux-arguments))))))
(let ((entries (cons (boot-alternative->menu-entry
current-boot-alternative)
(append menu-entries
(map boot-alternative->menu-entry
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.
UI menu.c32
MENU TITLE GNU Guix Boot Options
PROMPT ~a
TIMEOUT ~a~%" ; Timeout is expressed in tenths of a second.
#$(if (> timeout 0) 1 0) #$(* 10 timeout))
#$@(map menu-entry->gexp entries)))))))))
\f
;;;
;;; Install procedure.
;;;
(define (install-extlinux mbr)
(lambda* (#:key bootloader-config #:allow-other-keys . args)
(with-targets (bootloader-configuration-targets bootloader-config)
(('extlinux => (path :path))
#~(begin
#$(apply install-extlinux-config args)
(copy-recursively #$(file-append syslinux "/share/syslinux") #$path)
(invoke/quiet #+(file-append syslinux "/sbin/extlinux")
"--install" #$path)))
(('disk => (disk :device))
#~(write-file-on-device #$(file-append syslinux "/share/syslinux/" mbr)
440 #$disk 0)))))
\f
;;;
;;; Bootloader definitions.
;;;
(define extlinux-bootloader
(bootloader
(name 'extlinux)
(default-targets (list (bootloader-target
(type 'install)
(offset 'root)
(path "boot"))
(bootloader-target
(type 'extlinux)
(offset 'install)
(path "extlinux"))))
(installer (install-extlinux "mbr.bin"))))
(define extlinux-gpt-bootloader
(bootloader
(inherit extlinux-bootloader)
(installer (install-extlinux "gptmbr.bin"))))
(define-deprecated/alias extlinux-bootloader-gpt extlinux-gpt-bootloader)
|