Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / bootloader.scm
CommitLineData
b09a8da4
MO
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 David Craven <david@craven.ch>
3;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
4;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
5;;;
6;;; This file is part of GNU Guix.
7;;;
8;;; GNU Guix is free software; you can redistribute it and/or modify it
9;;; under the terms of the GNU General Public License as published by
10;;; the Free Software Foundation; either version 3 of the License, or (at
11;;; your option) any later version.
12;;;
13;;; GNU Guix is distributed in the hope that it will be useful, but
14;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;;; GNU General Public License for more details.
17;;;
18;;; You should have received a copy of the GNU General Public License
19;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21(define-module (gnu bootloader)
22 #:use-module (guix discovery)
23 #:use-module (guix records)
24 #:use-module (guix ui)
25 #:use-module (srfi srfi-1)
8b22107e
MO
26 #:export (menu-entry
27 menu-entry?
28 menu-entry-label
29 menu-entry-device
30 menu-entry-linux
31 menu-entry-linux-arguments
32 menu-entry-initrd
33
34 bootloader
b09a8da4
MO
35 bootloader?
36 bootloader-name
37 bootloader-package
38 bootloader-installer
39 bootloader-configuration-file
40 bootloader-configuration-file-generator
41
42 bootloader-configuration
43 bootloader-configuration?
44 bootloader-configuration-bootloader
45 bootloader-configuration-device
46 bootloader-configuration-menu-entries
47 bootloader-configuration-default-entry
48 bootloader-configuration-timeout
49 bootloader-configuration-theme
50 bootloader-configuration-terminal-outputs
51 bootloader-configuration-terminal-inputs
52 bootloader-configuration-serial-unit
53 bootloader-configuration-serial-speed
54 bootloader-configuration-additional-configuration
55
56 %bootloaders
57 lookup-bootloader-by-name))
58
59\f
8b22107e
MO
60;;;
61;;; Menu-entry record.
62;;;
63
64(define-record-type* <menu-entry>
65 menu-entry make-menu-entry
66 menu-entry?
67 (label menu-entry-label)
68 (device menu-entry-device ; file system uuid, label, or #f
69 (default #f))
70 (linux menu-entry-linux)
71 (linux-arguments menu-entry-linux-arguments
72 (default '())) ; list of string-valued gexps
73 (initrd menu-entry-initrd)) ; file name of the initrd as a gexp
74
75\f
b09a8da4
MO
76;;;
77;;; Bootloader record.
78;;;
79
80;; The <bootloader> record contains fields expressing how the bootloader
81;; should be installed. Every bootloader in gnu/bootloader/ directory
82;; has to be described by this record.
83
84(define-record-type* <bootloader>
85 bootloader make-bootloader
86 bootloader?
87 (name bootloader-name)
88 (package bootloader-package)
89 (installer bootloader-installer)
90 (configuration-file bootloader-configuration-file)
91 (configuration-file-generator bootloader-configuration-file-generator))
92
93\f
94;;;
95;;; Bootloader configuration record.
96;;;
97
98;; The <bootloader-configuration> record contains bootloader independant
99;; configuration used to fill bootloader configuration file.
100
101(define-record-type* <bootloader-configuration>
102 bootloader-configuration make-bootloader-configuration
103 bootloader-configuration?
104 (bootloader bootloader-configuration-bootloader) ; <bootloader>
105 (device bootloader-configuration-device ; string
106 (default #f))
107 (menu-entries bootloader-configuration-menu-entries ; list of <boot-parameters>
108 (default '()))
109 (default-entry bootloader-configuration-default-entry ; integer
110 (default 0))
111 (timeout bootloader-configuration-timeout ; seconds as integer
112 (default 5))
113 (theme bootloader-configuration-theme ; bootloader-specific theme
114 (default #f))
115 (terminal-outputs bootloader-configuration-terminal-outputs ; list of symbols
116 (default '(gfxterm)))
117 (terminal-inputs bootloader-configuration-terminal-inputs ; list of symbols
118 (default '()))
119 (serial-unit bootloader-configuration-serial-unit ; integer | #f
120 (default #f))
121 (serial-speed bootloader-configuration-serial-speed ; integer | #f
122 (default #f))
123 (additional-configuration bootloader-configuration-additional-configuration ; record
124 (default #f)))
125
126\f
127;;;
128;;; Bootloaders.
129;;;
130
131(define (bootloader-modules)
132 "Return the list of bootloader modules."
133 (all-modules (map (lambda (entry)
134 `(,entry . "gnu/bootloader"))
135 %load-path)))
136
137(define %bootloaders
138 ;; The list of publically-known bootloaders.
139 (delay (fold-module-public-variables (lambda (obj result)
140 (if (bootloader? obj)
141 (cons obj result)
142 result))
143 '()
144 (bootloader-modules))))
145
146(define (lookup-bootloader-by-name name)
147 "Return the bootloader called NAME."
148 (or (find (lambda (bootloader)
149 (eq? name (bootloader-name bootloader)))
150 (force %bootloaders))
151 (leave (G_ "~a: no such bootloader~%") name)))