Merge remote-tracking branch 'master' into core-updates.
[jackhill/guix/guix.git] / gnu / bootloader / extlinux.scm
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
20 (define-module (gnu bootloader extlinux)
21 #:use-module (gnu bootloader)
22 #:use-module (gnu packages bootloaders)
23 #:use-module (guix gexp)
24 #:use-module (guix utils)
25 #:export (extlinux-bootloader
26 extlinux-bootloader-gpt))
27
28 (define* (extlinux-configuration-file config entries
29 #:key
30 (system (%current-system))
31 (old-entries '()))
32 "Return the U-Boot configuration file corresponding to CONFIG, a
33 <u-boot-configuration> object, and where the store is available at STORE-FS, a
34 <file-system> object. OLD-ENTRIES is taken to be a list of menu entries
35 corresponding to old generations of the system."
36
37 (define all-entries
38 (append entries (bootloader-configuration-menu-entries config)))
39
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
56 (define builder
57 #~(call-with-output-file #$output
58 (lambda (port)
59 (let ((timeout #$(bootloader-configuration-timeout config)))
60 (format port "# This file was generated from your Guix configuration. Any changes
61 # will be lost upon reconfiguration.
62 UI menu.c32
63 MENU TITLE GNU Guix Boot Options
64 PROMPT ~a
65 TIMEOUT ~a~%"
66 (if (> timeout 0) 1 0)
67 ;; timeout is expressed in 1/10s of seconds.
68 (* 10 timeout))
69 #$@(map menu-entry->gexp all-entries)
70
71 #$@(if (pair? old-entries)
72 #~((format port "~%")
73 #$@(map menu-entry->gexp old-entries)
74 (format port "~%"))
75 #~())))))
76
77 (computed-file "extlinux.conf" builder))
78
79
80 \f
81
82 ;;;
83 ;;; Install procedures.
84 ;;;
85
86 (define (install-extlinux mbr)
87 #~(lambda (bootloader device mount-point)
88 (let ((extlinux (string-append bootloader "/sbin/extlinux"))
89 (install-dir (string-append mount-point "/boot/extlinux"))
90 (syslinux-dir (string-append bootloader "/share/syslinux")))
91 (for-each (lambda (file)
92 (install-file file install-dir))
93 (find-files syslinux-dir "\\.c32$"))
94 (invoke/quiet extlinux "--install" install-dir)
95 (write-file-on-device (string-append syslinux-dir "/" #$mbr)
96 440 device 0))))
97
98 (define install-extlinux-mbr
99 (install-extlinux "mbr.bin"))
100
101 (define install-extlinux-gpt
102 (install-extlinux "gptmbr.bin"))
103
104 \f
105
106 ;;;
107 ;;; Bootloader definitions.
108 ;;;
109
110 (define extlinux-bootloader
111 (bootloader
112 (name 'extlinux)
113 (package syslinux)
114 (installer install-extlinux-mbr)
115 (configuration-file "/boot/extlinux/extlinux.conf")
116 (configuration-file-generator extlinux-configuration-file)))
117
118 (define extlinux-bootloader-gpt
119 (bootloader
120 (inherit extlinux-bootloader)
121 (installer install-extlinux-gpt)))