extlinux.scm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu bootloader extlinux)
  20. #:use-module (gnu bootloader)
  21. #:use-module (gnu system)
  22. #:use-module (gnu build bootloader)
  23. #:use-module (gnu packages bootloaders)
  24. #:use-module (guix gexp)
  25. #:use-module (guix monads)
  26. #:use-module (guix records)
  27. #:use-module (guix utils)
  28. #:export (extlinux-bootloader
  29. extlinux-bootloader-gpt))
  30. (define* (extlinux-configuration-file config entries
  31. #:key
  32. (system (%current-system))
  33. (old-entries '()))
  34. "Return the U-Boot configuration file corresponding to CONFIG, a
  35. <u-boot-configuration> object, and where the store is available at STORE-FS, a
  36. <file-system> object. OLD-ENTRIES is taken to be a list of menu entries
  37. corresponding to old generations of the system."
  38. (define all-entries
  39. (append entries (bootloader-configuration-menu-entries config)))
  40. (define (menu-entry->gexp entry)
  41. (let ((label (menu-entry-label entry))
  42. (kernel (menu-entry-linux entry))
  43. (kernel-arguments (menu-entry-linux-arguments entry))
  44. (initrd (menu-entry-initrd entry)))
  45. #~(format port "LABEL ~a
  46. MENU LABEL ~a
  47. KERNEL ~a
  48. FDTDIR ~a/lib/dtbs
  49. INITRD ~a
  50. APPEND ~a
  51. ~%"
  52. #$label #$label
  53. #$kernel (dirname #$kernel) #$initrd
  54. (string-join (list #$@kernel-arguments)))))
  55. (define builder
  56. #~(call-with-output-file #$output
  57. (lambda (port)
  58. (let ((timeout #$(bootloader-configuration-timeout config)))
  59. (format port "# This file was generated from your GuixSD configuration. Any changes
  60. # will be lost upon reconfiguration.
  61. UI menu.c32
  62. PROMPT ~a
  63. TIMEOUT ~a~%"
  64. (if (> timeout 0) 1 0)
  65. ;; timeout is expressed in 1/10s of seconds.
  66. (* 10 timeout))
  67. #$@(map menu-entry->gexp all-entries)
  68. #$@(if (pair? old-entries)
  69. #~((format port "~%")
  70. #$@(map menu-entry->gexp old-entries)
  71. (format port "~%"))
  72. #~())))))
  73. (gexp->derivation "extlinux.conf" builder))
  74. ;;;
  75. ;;; Install procedures.
  76. ;;;
  77. (define (install-extlinux mbr)
  78. #~(lambda (bootloader device mount-point)
  79. (let ((extlinux (string-append bootloader "/sbin/extlinux"))
  80. (install-dir (string-append mount-point "/boot/extlinux"))
  81. (syslinux-dir (string-append bootloader "/share/syslinux")))
  82. (for-each (lambda (file)
  83. (install-file file install-dir))
  84. (find-files syslinux-dir "\\.c32$"))
  85. (unless
  86. (and (zero? (system* extlinux "--install" install-dir))
  87. (write-file-on-device
  88. (string-append syslinux-dir "/" #$mbr) 440 device 0))
  89. (error "failed to install SYSLINUX")))))
  90. (define install-extlinux-mbr
  91. (install-extlinux "mbr.bin"))
  92. (define install-extlinux-gpt
  93. (install-extlinux "gptmbr.bin"))
  94. ;;;
  95. ;;; Bootloader definitions.
  96. ;;;
  97. (define extlinux-bootloader
  98. (bootloader
  99. (name 'extlinux)
  100. (package syslinux)
  101. (installer install-extlinux-mbr)
  102. (configuration-file "/boot/extlinux/extlinux.conf")
  103. (configuration-file-generator extlinux-configuration-file)))
  104. (define extlinux-bootloader-gpt
  105. (bootloader
  106. (inherit extlinux-bootloader)
  107. (installer install-extlinux-gpt)))