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>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
20 (define-module (gnu bootloader extlinux)
21 #:use-module (gnu bootloader)
22 #:use-module (gnu system)
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))
31 (define* (extlinux-configuration-file config entries
33 (system (%current-system))
35 "Return the U-Boot configuration file corresponding to CONFIG, a
36 <u-boot-configuration> object, and where the store is available at STORE-FS, a
37 <file-system> object. OLD-ENTRIES is taken to be a list of menu entries
38 corresponding to old generations of the system."
41 (append entries (bootloader-configuration-menu-entries config)))
43 (define (menu-entry->gexp entry)
44 (let ((label (menu-entry-label entry))
45 (kernel (menu-entry-linux entry))
46 (kernel-arguments (menu-entry-linux-arguments entry))
47 (initrd (menu-entry-initrd entry)))
48 #~(format port "LABEL ~a
56 #$kernel #$kernel #$initrd
57 (string-join (list #$@kernel-arguments)))))
60 #~(call-with-output-file #$output
62 (let ((timeout #$(bootloader-configuration-timeout config)))
63 (format port "# This file was generated from your GuixSD configuration. Any changes
64 # will be lost upon reconfiguration.
68 (if (> timeout 0) 1 0)
69 ;; timeout is expressed in 1/10s of seconds.
71 #$@(map menu-entry->gexp all-entries)
73 #$@(if (pair? old-entries)
75 #$@(map menu-entry->gexp old-entries)
79 (gexp->derivation "extlinux.conf" builder))
85 ;;; Install procedures.
89 #~(lambda (bs count if of)
91 (string-append "bs=" (number->string bs))
92 (string-append "count=" (number->string count))
93 (string-append "if=" if)
94 (string-append "of=" of)))))
96 (define (install-extlinux mbr)
97 #~(lambda (bootloader device mount-point)
98 (let ((extlinux (string-append bootloader "/sbin/extlinux"))
99 (install-dir (string-append mount-point "/boot/extlinux"))
100 (syslinux-dir (string-append bootloader "/share/syslinux")))
101 (for-each (lambda (file)
102 (install-file file install-dir))
103 (find-files syslinux-dir "\\.c32$"))
105 (unless (and (zero? (system* extlinux "--install" install-dir))
106 (#$dd 440 1 (string-append syslinux-dir "/" #$mbr) device))
107 (error "failed to install SYSLINUX")))))
109 (define install-extlinux-mbr
110 (install-extlinux "mbr.bin"))
112 (define install-extlinux-gpt
113 (install-extlinux "gptmbr.bin"))
118 ;;; Bootloader definitions.
121 (define extlinux-bootloader
125 (installer install-extlinux-mbr)
126 (configuration-file "/boot/extlinux/extlinux.conf")
127 (configuration-file-generator extlinux-configuration-file)))
129 (define extlinux-bootloader-gpt
131 (inherit extlinux-bootloader)
132 (installer install-extlinux-gpt)))