Commit | Line | Data |
---|---|---|
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)) | |
b460ba79 MC |
31 | (old-entries '()) |
32 | #:allow-other-keys) | |
b09a8da4 MO |
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 | |
1975c754 | 39 | (append entries (bootloader-configuration-menu-entries config))) |
b09a8da4 | 40 | |
1975c754 DM |
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))) | |
b09a8da4 MO |
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 | |
be07cc45 | 54 | #$kernel (dirname #$kernel) #$initrd |
b09a8da4 MO |
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))) | |
59e80445 | 61 | (format port "# This file was generated from your Guix configuration. Any changes |
65efb3c0 | 62 | # will be lost upon reconfiguration. |
b09a8da4 | 63 | UI menu.c32 |
59e80445 | 64 | MENU TITLE GNU Guix Boot Options |
b09a8da4 MO |
65 | PROMPT ~a |
66 | TIMEOUT ~a~%" | |
67 | (if (> timeout 0) 1 0) | |
68 | ;; timeout is expressed in 1/10s of seconds. | |
69 | (* 10 timeout)) | |
1975c754 | 70 | #$@(map menu-entry->gexp all-entries) |
b09a8da4 MO |
71 | |
72 | #$@(if (pair? old-entries) | |
73 | #~((format port "~%") | |
1975c754 | 74 | #$@(map menu-entry->gexp old-entries) |
b09a8da4 MO |
75 | (format port "~%")) |
76 | #~()))))) | |
77 | ||
9512ba6b LC |
78 | (computed-file "extlinux.conf" builder |
79 | #:options '(#:local-build? #t | |
80 | #:substitutable? #f))) | |
b09a8da4 MO |
81 | |
82 | ||
83 | \f | |
84 | ||
85 | ;;; | |
86 | ;;; Install procedures. | |
87 | ;;; | |
88 | ||
dbaef95a | 89 | (define (install-extlinux mbr) |
b09a8da4 MO |
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$")) | |
21fcfe1e LC |
97 | (invoke/quiet extlinux "--install" install-dir) |
98 | (write-file-on-device (string-append syslinux-dir "/" #$mbr) | |
99 | 440 device 0)))) | |
b09a8da4 | 100 | |
dbaef95a MO |
101 | (define install-extlinux-mbr |
102 | (install-extlinux "mbr.bin")) | |
103 | ||
104 | (define install-extlinux-gpt | |
105 | (install-extlinux "gptmbr.bin")) | |
106 | ||
b09a8da4 MO |
107 | \f |
108 | ||
109 | ;;; | |
110 | ;;; Bootloader definitions. | |
111 | ;;; | |
112 | ||
113 | (define extlinux-bootloader | |
114 | (bootloader | |
115 | (name 'extlinux) | |
116 | (package syslinux) | |
dbaef95a | 117 | (installer install-extlinux-mbr) |
b09a8da4 MO |
118 | (configuration-file "/boot/extlinux/extlinux.conf") |
119 | (configuration-file-generator extlinux-configuration-file))) | |
dbaef95a MO |
120 | |
121 | (define extlinux-bootloader-gpt | |
122 | (bootloader | |
123 | (inherit extlinux-bootloader) | |
124 | (installer install-extlinux-gpt))) |