projects/guix·blob version-0.14.0 · refs

132 lines · 4.4 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 David Craven <[email protected]>
3;;; Copyright © 2017 Mathieu Othacehe <[email protected]>
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 system)
23 #:use-module (gnu packages bootloaders)
24 #:use-module (guix gexp)
25 #:use-module (guix monads)
26 #:use-module (guix records)
27 #:use-module (guix utils)
28 #:export (extlinux-bootloader
29 extlinux-bootloader-gpt))
30
31(define* (extlinux-configuration-file config entries
32 #:key
33 (system (%current-system))
34 (old-entries '()))
35 "Return the U-Boot configuration file corresponding to CONFIG, a
36<u-boot-configuration> object, and where the store is available at STORE-FS, a
37<file-system> object. OLD-ENTRIES is taken to be a list of menu entries
38corresponding to old generations of the system."
39
40 (define all-entries
41 (append entries (bootloader-configuration-menu-entries config)))
42
43 (define (menu-entry->gexp entry)
44 (let ((label (menu-entry-label entry))
45 (kernel (menu-entry-linux entry))
46 (kernel-arguments (menu-entry-linux-arguments entry))
47 (initrd (menu-entry-initrd entry)))
48 #~(format port "LABEL ~a
49 MENU LABEL ~a
50 KERNEL ~a
51 FDTDIR ~a/lib/dtbs
52 INITRD ~a
53 APPEND ~a
54~%"
55 #$label #$label
56 #$kernel (dirname #$kernel) #$initrd
57 (string-join (list #$@kernel-arguments)))))
58
59 (define builder
60 #~(call-with-output-file #$output
61 (lambda (port)
62 (let ((timeout #$(bootloader-configuration-timeout config)))
63 (format port "# This file was generated from your GuixSD configuration. Any changes
64# will be lost upon reconfiguration.
65UI menu.c32
66PROMPT ~a
67TIMEOUT ~a~%"
68 (if (> timeout 0) 1 0)
69 ;; timeout is expressed in 1/10s of seconds.
70 (* 10 timeout))
71 #$@(map menu-entry->gexp all-entries)
72
73 #$@(if (pair? old-entries)
74 #~((format port "~%")
75 #$@(map menu-entry->gexp old-entries)
76 (format port "~%"))
77 #~())))))
78
79 (gexp->derivation "extlinux.conf" builder))
80
81
82
83
84;;;
85;;; Install procedures.
86;;;
87
88(define dd
89 #~(lambda (bs count if of)
90 (zero? (system* "dd"
91 (string-append "bs=" (number->string bs))
92 (string-append "count=" (number->string count))
93 (string-append "if=" if)
94 (string-append "of=" of)))))
95
96(define (install-extlinux mbr)
97 #~(lambda (bootloader device mount-point)
98 (let ((extlinux (string-append bootloader "/sbin/extlinux"))
99 (install-dir (string-append mount-point "/boot/extlinux"))
100 (syslinux-dir (string-append bootloader "/share/syslinux")))
101 (for-each (lambda (file)
102 (install-file file install-dir))
103 (find-files syslinux-dir "\\.c32$"))
104
105 (unless (and (zero? (system* extlinux "--install" install-dir))
106 (#$dd 440 1 (string-append syslinux-dir "/" #$mbr) device))
107 (error "failed to install SYSLINUX")))))
108
109(define install-extlinux-mbr
110 (install-extlinux "mbr.bin"))
111
112(define install-extlinux-gpt
113 (install-extlinux "gptmbr.bin"))
114
115
116
117;;;
118;;; Bootloader definitions.
119;;;
120
121(define extlinux-bootloader
122 (bootloader
123 (name 'extlinux)
124 (package syslinux)
125 (installer install-extlinux-mbr)
126 (configuration-file "/boot/extlinux/extlinux.conf")
127 (configuration-file-generator extlinux-configuration-file)))
128
129(define extlinux-bootloader-gpt
130 (bootloader
131 (inherit extlinux-bootloader)
132 (installer install-extlinux-gpt)))