extlinux.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 packages bootloaders)
  22. #:use-module (guix gexp)
  23. #:use-module (guix utils)
  24. #:export (extlinux-bootloader
  25. extlinux-bootloader-gpt))
  26. (define* (extlinux-configuration-file config entries
  27. #:key
  28. (system (%current-system))
  29. (old-entries '()))
  30. "Return the U-Boot configuration file corresponding to CONFIG, a
  31. <u-boot-configuration> object, and where the store is available at STORE-FS, a
  32. <file-system> object. OLD-ENTRIES is taken to be a list of menu entries
  33. corresponding to old generations of the system."
  34. (define all-entries
  35. (append entries (bootloader-configuration-menu-entries config)))
  36. (define (menu-entry->gexp entry)
  37. (let ((label (menu-entry-label entry))
  38. (kernel (menu-entry-linux entry))
  39. (kernel-arguments (menu-entry-linux-arguments entry))
  40. (initrd (menu-entry-initrd entry)))
  41. #~(format port "LABEL ~a
  42. MENU LABEL ~a
  43. KERNEL ~a
  44. FDTDIR ~a/lib/dtbs
  45. INITRD ~a
  46. APPEND ~a
  47. ~%"
  48. #$label #$label
  49. #$kernel (dirname #$kernel) #$initrd
  50. (string-join (list #$@kernel-arguments)))))
  51. (define builder
  52. #~(call-with-output-file #$output
  53. (lambda (port)
  54. (let ((timeout #$(bootloader-configuration-timeout config)))
  55. (format port "# This file was generated from your GuixSD configuration. Any changes
  56. # will be lost upon reconfiguration.
  57. UI menu.c32
  58. MENU TITLE GuixSD Boot Options
  59. PROMPT ~a
  60. TIMEOUT ~a~%"
  61. (if (> timeout 0) 1 0)
  62. ;; timeout is expressed in 1/10s of seconds.
  63. (* 10 timeout))
  64. #$@(map menu-entry->gexp all-entries)
  65. #$@(if (pair? old-entries)
  66. #~((format port "~%")
  67. #$@(map menu-entry->gexp old-entries)
  68. (format port "~%"))
  69. #~())))))
  70. (computed-file "extlinux.conf" builder))
  71. ;;;
  72. ;;; Install procedures.
  73. ;;;
  74. (define (install-extlinux mbr)
  75. #~(lambda (bootloader device mount-point)
  76. (let ((extlinux (string-append bootloader "/sbin/extlinux"))
  77. (install-dir (string-append mount-point "/boot/extlinux"))
  78. (syslinux-dir (string-append bootloader "/share/syslinux")))
  79. (for-each (lambda (file)
  80. (install-file file install-dir))
  81. (find-files syslinux-dir "\\.c32$"))
  82. (unless
  83. (and (zero? (system* extlinux "--install" install-dir))
  84. (write-file-on-device
  85. (string-append syslinux-dir "/" #$mbr) 440 device 0))
  86. (error "failed to install SYSLINUX")))))
  87. (define install-extlinux-mbr
  88. (install-extlinux "mbr.bin"))
  89. (define install-extlinux-gpt
  90. (install-extlinux "gptmbr.bin"))
  91. ;;;
  92. ;;; Bootloader definitions.
  93. ;;;
  94. (define extlinux-bootloader
  95. (bootloader
  96. (name 'extlinux)
  97. (package syslinux)
  98. (installer install-extlinux-mbr)
  99. (configuration-file "/boot/extlinux/extlinux.conf")
  100. (configuration-file-generator extlinux-configuration-file)))
  101. (define extlinux-bootloader-gpt
  102. (bootloader
  103. (inherit extlinux-bootloader)
  104. (installer install-extlinux-gpt)))