Merge remote-tracking branch 'origin/version-1.2.0' into master
[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 #:allow-other-keys)
33 "Return the U-Boot configuration file corresponding to CONFIG, a
34 <u-boot-configuration> object, and where the store is available at STORE-FS, a
35 <file-system> object. OLD-ENTRIES is taken to be a list of menu entries
36 corresponding to old generations of the system."
37
38 (define all-entries
39 (append entries (bootloader-configuration-menu-entries config)))
40
41 (define (menu-entry->gexp entry)
42 (let ((label (menu-entry-label entry))
43 (kernel (menu-entry-linux entry))
44 (kernel-arguments (menu-entry-linux-arguments entry))
45 (initrd (menu-entry-initrd entry)))
46 #~(format port "LABEL ~a
47 MENU LABEL ~a
48 KERNEL ~a
49 FDTDIR ~a/lib/dtbs
50 INITRD ~a
51 APPEND ~a
52 ~%"
53 #$label #$label
54 #$kernel (dirname #$kernel) #$initrd
55 (string-join (list #$@kernel-arguments)))))
56
57 (define builder
58 #~(call-with-output-file #$output
59 (lambda (port)
60 (let ((timeout #$(bootloader-configuration-timeout config)))
61 (format port "# This file was generated from your Guix configuration. Any changes
62 # will be lost upon reconfiguration.
63 UI menu.c32
64 MENU TITLE GNU Guix Boot Options
65 PROMPT ~a
66 TIMEOUT ~a~%"
67 (if (> timeout 0) 1 0)
68 ;; timeout is expressed in 1/10s of seconds.
69 (* 10 timeout))
70 #$@(map menu-entry->gexp all-entries)
71
72 #$@(if (pair? old-entries)
73 #~((format port "~%")
74 #$@(map menu-entry->gexp old-entries)
75 (format port "~%"))
76 #~())))))
77
78 (computed-file "extlinux.conf" builder
79 #:options '(#:local-build? #t
80 #:substitutable? #f)))
81
82
83 \f
84
85 ;;;
86 ;;; Install procedures.
87 ;;;
88
89 (define (install-extlinux mbr)
90 #~(lambda (bootloader device mount-point)
91 (let ((extlinux (string-append bootloader "/sbin/extlinux"))
92 (install-dir (string-append mount-point "/boot/extlinux"))
93 (syslinux-dir (string-append bootloader "/share/syslinux")))
94 (for-each (lambda (file)
95 (install-file file install-dir))
96 (find-files syslinux-dir "\\.c32$"))
97 (invoke/quiet extlinux "--install" install-dir)
98 (write-file-on-device (string-append syslinux-dir "/" #$mbr)
99 440 device 0))))
100
101 (define install-extlinux-mbr
102 (install-extlinux "mbr.bin"))
103
104 (define install-extlinux-gpt
105 (install-extlinux "gptmbr.bin"))
106
107 \f
108
109 ;;;
110 ;;; Bootloader definitions.
111 ;;;
112
113 (define extlinux-bootloader
114 (bootloader
115 (name 'extlinux)
116 (package syslinux)
117 (installer install-extlinux-mbr)
118 (configuration-file "/boot/extlinux/extlinux.conf")
119 (configuration-file-generator extlinux-configuration-file)))
120
121 (define extlinux-bootloader-gpt
122 (bootloader
123 (inherit extlinux-bootloader)
124 (installer install-extlinux-gpt)))