bootloader.scm 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. (target bootloader-configuration-target ; string
  94. (default #f))
  95. (menu-entries bootloader-configuration-menu-entries ; list of <boot-parameters>
  96. (default '()))
  97. (default-entry bootloader-configuration-default-entry ; integer
  98. (default 0))
  99. (timeout bootloader-configuration-timeout ; seconds as integer
  100. (default 5))
  101. (theme bootloader-configuration-theme ; bootloader-specific theme
  102. (default #f))
  103. (terminal-outputs bootloader-configuration-terminal-outputs ; list of symbols
  104. (default '(gfxterm)))
  105. (terminal-inputs bootloader-configuration-terminal-inputs ; list of symbols
  106. (default '()))
  107. (serial-unit bootloader-configuration-serial-unit ; integer | #f
  108. (default #f))
  109. (serial-speed bootloader-configuration-serial-speed ; integer | #f
  110. (default #f))
  111. (additional-configuration bootloader-configuration-additional-configuration ; record
  112. (default #f)))
  113. ;;;
  114. ;;; Bootloaders.
  115. ;;;
  116. (define (bootloader-modules)
  117. "Return the list of bootloader modules."
  118. (all-modules (map (lambda (entry)
  119. `(,entry . "gnu/bootloader"))
  120. %load-path)
  121. #:warn warn-about-load-error))
  122. (define %bootloaders
  123. ;; The list of publically-known bootloaders.
  124. (delay (fold-module-public-variables (lambda (obj result)
  125. (if (bootloader? obj)
  126. (cons obj result)
  127. result))
  128. '()
  129. (bootloader-modules))))
  130. (define (lookup-bootloader-by-name name)
  131. "Return the bootloader called NAME."
  132. (or (find (lambda (bootloader)
  133. (eq? name (bootloader-name bootloader)))
  134. (force %bootloaders))
  135. (leave (G_ "~a: no such bootloader~%") name)))