projects/guix·blob version-0.15.0 · refs

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