bootloader.scm 6.9 KB

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