bootloader.scm 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 David Craven <david@craven.ch>
  3. ;;; Copyright © 2017, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
  4. ;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
  5. ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
  6. ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (gnu bootloader)
  23. #:use-module (guix discovery)
  24. #:use-module (guix records)
  25. #:use-module (guix ui)
  26. #:use-module (srfi srfi-1)
  27. #:use-module (ice-9 match)
  28. #:export (menu-entry
  29. menu-entry?
  30. menu-entry-label
  31. menu-entry-device
  32. menu-entry-linux
  33. menu-entry-linux-arguments
  34. menu-entry-initrd
  35. menu-entry-device-mount-point
  36. menu-entry-multiboot-kernel
  37. menu-entry-multiboot-arguments
  38. menu-entry-multiboot-modules
  39. menu-entry->sexp
  40. sexp->menu-entry
  41. bootloader
  42. bootloader?
  43. bootloader-name
  44. bootloader-package
  45. bootloader-installer
  46. bootloader-disk-image-installer
  47. bootloader-configuration-file
  48. bootloader-configuration-file-generator
  49. bootloader-configuration
  50. bootloader-configuration?
  51. bootloader-configuration-bootloader
  52. bootloader-configuration-target
  53. bootloader-configuration-menu-entries
  54. bootloader-configuration-default-entry
  55. bootloader-configuration-timeout
  56. bootloader-configuration-keyboard-layout
  57. bootloader-configuration-theme
  58. bootloader-configuration-terminal-outputs
  59. bootloader-configuration-terminal-inputs
  60. bootloader-configuration-serial-unit
  61. bootloader-configuration-serial-speed
  62. bootloader-configuration-additional-configuration
  63. %bootloaders
  64. lookup-bootloader-by-name))
  65. ;;;
  66. ;;; Menu-entry record.
  67. ;;;
  68. (define-record-type* <menu-entry>
  69. menu-entry make-menu-entry
  70. menu-entry?
  71. (label menu-entry-label)
  72. (device menu-entry-device ; file system uuid, label, or #f
  73. (default #f))
  74. (device-mount-point menu-entry-device-mount-point
  75. (default #f))
  76. (linux menu-entry-linux
  77. (default #f))
  78. (linux-arguments menu-entry-linux-arguments
  79. (default '())) ; list of string-valued gexps
  80. (initrd menu-entry-initrd ; file name of the initrd as a gexp
  81. (default #f))
  82. (multiboot-kernel menu-entry-multiboot-kernel
  83. (default #f))
  84. (multiboot-arguments menu-entry-multiboot-arguments
  85. (default '())) ; list of string-valued gexps
  86. (multiboot-modules menu-entry-multiboot-modules
  87. (default '()))) ; list of multiboot commands, where
  88. ; a command is a list of <string>
  89. (define (menu-entry->sexp entry)
  90. "Return ENTRY serialized as an sexp."
  91. (match entry
  92. (($ <menu-entry> label device mount-point linux linux-arguments initrd #f
  93. ())
  94. `(menu-entry (version 0)
  95. (label ,label)
  96. (device ,device)
  97. (device-mount-point ,mount-point)
  98. (linux ,linux)
  99. (linux-arguments ,linux-arguments)
  100. (initrd ,initrd)))
  101. (($ <menu-entry> label device mount-point #f () #f
  102. multiboot-kernel multiboot-arguments multiboot-modules)
  103. `(menu-entry (version 0)
  104. (label ,label)
  105. (device ,device)
  106. (device-mount-point ,mount-point)
  107. (multiboot-kernel ,multiboot-kernel)
  108. (multiboot-arguments ,multiboot-arguments)
  109. (multiboot-modules ,multiboot-modules)))))
  110. (define (sexp->menu-entry sexp)
  111. "Turn SEXP, an sexp as returned by 'menu-entry->sexp', into a <menu-entry>
  112. record."
  113. (match sexp
  114. (('menu-entry ('version 0)
  115. ('label label) ('device device)
  116. ('device-mount-point mount-point)
  117. ('linux linux) ('linux-arguments linux-arguments)
  118. ('initrd initrd) _ ...)
  119. (menu-entry
  120. (label label)
  121. (device device)
  122. (device-mount-point mount-point)
  123. (linux linux)
  124. (linux-arguments linux-arguments)
  125. (initrd initrd)))
  126. (('menu-entry ('version 0)
  127. ('label label) ('device device)
  128. ('device-mount-point mount-point)
  129. ('multiboot-kernel multiboot-kernel)
  130. ('multiboot-arguments multiboot-arguments)
  131. ('multiboot-modules multiboot-modules) _ ...)
  132. (menu-entry
  133. (label label)
  134. (device device)
  135. (device-mount-point mount-point)
  136. (multiboot-kernel multiboot-kernel)
  137. (multiboot-arguments multiboot-arguments)
  138. (multiboot-modules multiboot-modules)))))
  139. ;;;
  140. ;;; Bootloader record.
  141. ;;;
  142. ;; The <bootloader> record contains fields expressing how the bootloader
  143. ;; should be installed. Every bootloader in gnu/bootloader/ directory
  144. ;; has to be described by this record.
  145. (define-record-type* <bootloader>
  146. bootloader make-bootloader
  147. bootloader?
  148. (name bootloader-name)
  149. (package bootloader-package)
  150. (installer bootloader-installer)
  151. (disk-image-installer bootloader-disk-image-installer
  152. (default #f))
  153. (configuration-file bootloader-configuration-file)
  154. (configuration-file-generator bootloader-configuration-file-generator))
  155. ;;;
  156. ;;; Bootloader configuration record.
  157. ;;;
  158. ;; The <bootloader-configuration> record contains bootloader independant
  159. ;; configuration used to fill bootloader configuration file.
  160. (define-record-type* <bootloader-configuration>
  161. bootloader-configuration make-bootloader-configuration
  162. bootloader-configuration?
  163. (bootloader bootloader-configuration-bootloader) ;<bootloader>
  164. (target bootloader-configuration-target ;string
  165. (default #f))
  166. (menu-entries bootloader-configuration-menu-entries ;list of <menu-entry>
  167. (default '()))
  168. (default-entry bootloader-configuration-default-entry ;integer
  169. (default 0))
  170. (timeout bootloader-configuration-timeout ;seconds as integer
  171. (default 5))
  172. (keyboard-layout bootloader-configuration-keyboard-layout ;<keyboard-layout> | #f
  173. (default #f))
  174. (theme bootloader-configuration-theme ;bootloader-specific theme
  175. (default #f))
  176. (terminal-outputs bootloader-configuration-terminal-outputs ;list of symbols
  177. (default '(gfxterm)))
  178. (terminal-inputs bootloader-configuration-terminal-inputs ;list of symbols
  179. (default '()))
  180. (serial-unit bootloader-configuration-serial-unit ;integer | #f
  181. (default #f))
  182. (serial-speed bootloader-configuration-serial-speed ;integer | #f
  183. (default #f)))
  184. ;;;
  185. ;;; Bootloaders.
  186. ;;;
  187. (define (bootloader-modules)
  188. "Return the list of bootloader modules."
  189. (all-modules (map (lambda (entry)
  190. `(,entry . "gnu/bootloader"))
  191. %load-path)
  192. #:warn warn-about-load-error))
  193. (define %bootloaders
  194. ;; The list of publically-known bootloaders.
  195. (delay (fold-module-public-variables (lambda (obj result)
  196. (if (bootloader? obj)
  197. (cons obj result)
  198. result))
  199. '()
  200. (bootloader-modules))))
  201. (define (lookup-bootloader-by-name name)
  202. "Return the bootloader called NAME."
  203. (or (find (lambda (bootloader)
  204. (eq? name (bootloader-name bootloader)))
  205. (force %bootloaders))
  206. (leave (G_ "~a: no such bootloader~%") name)))