bootloader.scm 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. (define-module (gnu bootloader)
  21. #:use-module (guix discovery)
  22. #:use-module (guix records)
  23. #:use-module (guix ui)
  24. #:use-module (srfi srfi-1)
  25. #:export (menu-entry
  26. menu-entry?
  27. menu-entry-label
  28. menu-entry-device
  29. menu-entry-linux
  30. menu-entry-linux-arguments
  31. menu-entry-initrd
  32. menu-entry-device-mount-point
  33. bootloader
  34. bootloader?
  35. bootloader-name
  36. bootloader-package
  37. bootloader-installer
  38. bootloader-configuration-file
  39. bootloader-configuration-file-generator
  40. bootloader-configuration
  41. bootloader-configuration?
  42. bootloader-configuration-bootloader
  43. bootloader-configuration-target
  44. bootloader-configuration-menu-entries
  45. bootloader-configuration-default-entry
  46. bootloader-configuration-timeout
  47. bootloader-configuration-theme
  48. bootloader-configuration-terminal-outputs
  49. bootloader-configuration-terminal-inputs
  50. bootloader-configuration-serial-unit
  51. bootloader-configuration-serial-speed
  52. bootloader-configuration-additional-configuration
  53. %bootloaders
  54. lookup-bootloader-by-name))
  55. ;;;
  56. ;;; Menu-entry record.
  57. ;;;
  58. (define-record-type* <menu-entry>
  59. menu-entry make-menu-entry
  60. menu-entry?
  61. (label menu-entry-label)
  62. (device menu-entry-device ; file system uuid, label, or #f
  63. (default #f))
  64. (device-mount-point menu-entry-device-mount-point
  65. (default #f))
  66. (linux menu-entry-linux)
  67. (linux-arguments menu-entry-linux-arguments
  68. (default '())) ; list of string-valued gexps
  69. (initrd menu-entry-initrd)) ; file name of the initrd as a gexp
  70. ;;;
  71. ;;; Bootloader record.
  72. ;;;
  73. ;; The <bootloader> record contains fields expressing how the bootloader
  74. ;; should be installed. Every bootloader in gnu/bootloader/ directory
  75. ;; has to be described by this record.
  76. (define-record-type* <bootloader>
  77. bootloader make-bootloader
  78. bootloader?
  79. (name bootloader-name)
  80. (package bootloader-package)
  81. (installer bootloader-installer)
  82. (configuration-file bootloader-configuration-file)
  83. (configuration-file-generator bootloader-configuration-file-generator))
  84. ;;;
  85. ;;; Bootloader configuration record.
  86. ;;;
  87. ;; The <bootloader-configuration> record contains bootloader independant
  88. ;; configuration used to fill bootloader configuration file.
  89. (define-record-type* <bootloader-configuration>
  90. bootloader-configuration make-bootloader-configuration
  91. bootloader-configuration?
  92. (bootloader bootloader-configuration-bootloader) ; <bootloader>
  93. (device bootloader-configuration-device ; string
  94. (default #f))
  95. (target %bootloader-configuration-target ; string
  96. (default #f))
  97. (menu-entries bootloader-configuration-menu-entries ; list of <boot-parameters>
  98. (default '()))
  99. (default-entry bootloader-configuration-default-entry ; integer
  100. (default 0))
  101. (timeout bootloader-configuration-timeout ; seconds as integer
  102. (default 5))
  103. (theme bootloader-configuration-theme ; bootloader-specific theme
  104. (default #f))
  105. (terminal-outputs bootloader-configuration-terminal-outputs ; list of symbols
  106. (default '(gfxterm)))
  107. (terminal-inputs bootloader-configuration-terminal-inputs ; list of symbols
  108. (default '()))
  109. (serial-unit bootloader-configuration-serial-unit ; integer | #f
  110. (default #f))
  111. (serial-speed bootloader-configuration-serial-speed ; integer | #f
  112. (default #f))
  113. (additional-configuration bootloader-configuration-additional-configuration ; record
  114. (default #f)))
  115. (define (bootloader-configuration-target config)
  116. (or (%bootloader-configuration-target config)
  117. (let ((device (bootloader-configuration-device config)))
  118. (when device
  119. (warning
  120. (G_ "The 'device' field of bootloader configurations is deprecated.~%"))
  121. (warning (G_ "Use 'target' instead.~%")))
  122. device)))
  123. ;;;
  124. ;;; Bootloaders.
  125. ;;;
  126. (define (bootloader-modules)
  127. "Return the list of bootloader modules."
  128. (all-modules (map (lambda (entry)
  129. `(,entry . "gnu/bootloader"))
  130. %load-path)))
  131. (define %bootloaders
  132. ;; The list of publically-known bootloaders.
  133. (delay (fold-module-public-variables (lambda (obj result)
  134. (if (bootloader? obj)
  135. (cons obj result)
  136. result))
  137. '()
  138. (bootloader-modules))))
  139. (define (lookup-bootloader-by-name name)
  140. "Return the bootloader called NAME."
  141. (or (find (lambda (bootloader)
  142. (eq? name (bootloader-name bootloader)))
  143. (force %bootloaders))
  144. (leave (G_ "~a: no such bootloader~%") name)))