gnu: spice: Add libcacard as an input to enable smartcard support.
[jackhill/guix/guix.git] / gnu / bootloader / extlinux.scm
CommitLineData
b09a8da4
MO
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)
b09a8da4
MO
22 #:use-module (gnu packages bootloaders)
23 #:use-module (guix gexp)
b09a8da4 24 #:use-module (guix utils)
dbaef95a
MO
25 #:export (extlinux-bootloader
26 extlinux-bootloader-gpt))
b09a8da4
MO
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
35corresponding to old generations of the system."
36
37 (define all-entries
1975c754 38 (append entries (bootloader-configuration-menu-entries config)))
b09a8da4 39
1975c754
DM
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)))
b09a8da4
MO
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
be07cc45 53 #$kernel (dirname #$kernel) #$initrd
b09a8da4
MO
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)))
59e80445 60 (format port "# This file was generated from your Guix configuration. Any changes
65efb3c0 61# will be lost upon reconfiguration.
b09a8da4 62UI menu.c32
59e80445 63MENU TITLE GNU Guix Boot Options
b09a8da4
MO
64PROMPT ~a
65TIMEOUT ~a~%"
66 (if (> timeout 0) 1 0)
67 ;; timeout is expressed in 1/10s of seconds.
68 (* 10 timeout))
1975c754 69 #$@(map menu-entry->gexp all-entries)
b09a8da4
MO
70
71 #$@(if (pair? old-entries)
72 #~((format port "~%")
1975c754 73 #$@(map menu-entry->gexp old-entries)
b09a8da4
MO
74 (format port "~%"))
75 #~())))))
76
9512ba6b
LC
77 (computed-file "extlinux.conf" builder
78 #:options '(#:local-build? #t
79 #:substitutable? #f)))
b09a8da4
MO
80
81
82\f
83
84;;;
85;;; Install procedures.
86;;;
87
dbaef95a 88(define (install-extlinux mbr)
b09a8da4
MO
89 #~(lambda (bootloader device mount-point)
90 (let ((extlinux (string-append bootloader "/sbin/extlinux"))
91 (install-dir (string-append mount-point "/boot/extlinux"))
92 (syslinux-dir (string-append bootloader "/share/syslinux")))
93 (for-each (lambda (file)
94 (install-file file install-dir))
95 (find-files syslinux-dir "\\.c32$"))
21fcfe1e
LC
96 (invoke/quiet extlinux "--install" install-dir)
97 (write-file-on-device (string-append syslinux-dir "/" #$mbr)
98 440 device 0))))
b09a8da4 99
dbaef95a
MO
100(define install-extlinux-mbr
101 (install-extlinux "mbr.bin"))
102
103(define install-extlinux-gpt
104 (install-extlinux "gptmbr.bin"))
105
b09a8da4
MO
106\f
107
108;;;
109;;; Bootloader definitions.
110;;;
111
112(define extlinux-bootloader
113 (bootloader
114 (name 'extlinux)
115 (package syslinux)
dbaef95a 116 (installer install-extlinux-mbr)
b09a8da4
MO
117 (configuration-file "/boot/extlinux/extlinux.conf")
118 (configuration-file-generator extlinux-configuration-file)))
dbaef95a
MO
119
120(define extlinux-bootloader-gpt
121 (bootloader
122 (inherit extlinux-bootloader)
123 (installer install-extlinux-gpt)))