extlinux.scm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #:allow-other-keys)
  31. "Return the U-Boot configuration file corresponding to CONFIG, a
  32. <u-boot-configuration> object, and where the store is available at STORE-FS, a
  33. <file-system> object. OLD-ENTRIES is taken to be a list of menu entries
  34. corresponding to old generations of the system."
  35. (define all-entries
  36. (append entries (bootloader-configuration-menu-entries config)))
  37. (define (menu-entry->gexp entry)
  38. (let ((label (menu-entry-label entry))
  39. (kernel (menu-entry-linux entry))
  40. (kernel-arguments (menu-entry-linux-arguments entry))
  41. (initrd (menu-entry-initrd entry)))
  42. #~(format port "LABEL ~a
  43. MENU LABEL ~a
  44. KERNEL ~a
  45. FDTDIR ~a/lib/dtbs
  46. INITRD ~a
  47. APPEND ~a
  48. ~%"
  49. #$label #$label
  50. #$kernel (dirname #$kernel) #$initrd
  51. (string-join (list #$@kernel-arguments)))))
  52. (define builder
  53. #~(call-with-output-file #$output
  54. (lambda (port)
  55. (let ((timeout #$(bootloader-configuration-timeout config)))
  56. (format port "# This file was generated from your Guix configuration. Any changes
  57. # will be lost upon reconfiguration.
  58. UI menu.c32
  59. MENU TITLE GNU Guix Boot Options
  60. PROMPT ~a
  61. TIMEOUT ~a~%"
  62. (if (> timeout 0) 1 0)
  63. ;; timeout is expressed in 1/10s of seconds.
  64. (* 10 timeout))
  65. #$@(map menu-entry->gexp all-entries)
  66. #$@(if (pair? old-entries)
  67. #~((format port "~%")
  68. #$@(map menu-entry->gexp old-entries)
  69. (format port "~%"))
  70. #~())))))
  71. (computed-file "extlinux.conf" builder
  72. #:options '(#:local-build? #t
  73. #:substitutable? #f)))
  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. (invoke/quiet extlinux "--install" install-dir)
  86. (write-file-on-device (string-append syslinux-dir "/" #$mbr)
  87. 440 device 0))))
  88. (define install-extlinux-mbr
  89. (install-extlinux "mbr.bin"))
  90. (define install-extlinux-gpt
  91. (install-extlinux "gptmbr.bin"))
  92. ;;;
  93. ;;; Bootloader definitions.
  94. ;;;
  95. (define extlinux-bootloader
  96. (bootloader
  97. (name 'extlinux)
  98. (package syslinux)
  99. (installer install-extlinux-mbr)
  100. (configuration-file "/boot/extlinux/extlinux.conf")
  101. (configuration-file-generator extlinux-configuration-file)))
  102. (define extlinux-bootloader-gpt
  103. (bootloader
  104. (inherit extlinux-bootloader)
  105. (installer install-extlinux-gpt)))