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)) | |
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 | |
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))) | |
65efb3c0 MO |
60 | (format port "# This file was generated from your GuixSD configuration. Any changes |
61 | # will be lost upon reconfiguration. | |
b09a8da4 | 62 | UI menu.c32 |
afca98ff | 63 | MENU TITLE GuixSD Boot Options |
b09a8da4 MO |
64 | PROMPT ~a |
65 | TIMEOUT ~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 | ||
46c296dc | 77 | (computed-file "extlinux.conf" builder)) |
b09a8da4 MO |
78 | |
79 | ||
80 | \f | |
81 | ||
82 | ;;; | |
83 | ;;; Install procedures. | |
84 | ;;; | |
85 | ||
dbaef95a | 86 | (define (install-extlinux mbr) |
b09a8da4 MO |
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$")) | |
4307397b MO |
94 | (unless |
95 | (and (zero? (system* extlinux "--install" install-dir)) | |
e2248203 MO |
96 | (write-file-on-device |
97 | (string-append syslinux-dir "/" #$mbr) 440 device 0)) | |
b09a8da4 MO |
98 | (error "failed to install SYSLINUX"))))) |
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))) |