gnu: moka-icon-theme: Add faba-icon-theme as propagated input.
[jackhill/guix/guix.git] / gnu / packages / bootloaders.scm
CommitLineData
65d8b777 1;;; GNU Guix --- Functional package management for GNU
ef753a1a 2;;; Copyright © 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
04e0eac1 3;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
f0150f87 4;;; Copyright © 2015 Leo Famulari <leo@famulari.name>
4c726001 5;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
d846834f 6;;; Copyright © 2016, 2017 Marius Bakke <mbakke@fastmail.com>
862e38d5
DC
7;;; Copyright © 2016, 2017 Danny Milosavljevic <dannym@scratchpost.org>
8;;; Copyright © 2016, 2017 David Craven <david@craven.ch>
4adeb3f6 9;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
65d8b777
LC
10;;;
11;;; This file is part of GNU Guix.
12;;;
13;;; GNU Guix is free software; you can redistribute it and/or modify it
14;;; under the terms of the GNU General Public License as published by
15;;; the Free Software Foundation; either version 3 of the License, or (at
16;;; your option) any later version.
17;;;
18;;; GNU Guix is distributed in the hope that it will be useful, but
19;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;;; GNU General Public License for more details.
22;;;
23;;; You should have received a copy of the GNU General Public License
24;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
25
862e38d5 26(define-module (gnu packages bootloaders)
65d8b777 27 #:use-module (gnu packages)
862e38d5
DC
28 #:use-module (gnu packages admin)
29 #:use-module ((gnu packages algebra) #:select (bc))
30 #:use-module (gnu packages assembly)
7febe3a2 31 #:use-module (gnu packages disk)
65d8b777 32 #:use-module (gnu packages bison)
862e38d5
DC
33 #:use-module (gnu packages cdrom)
34 #:use-module (gnu packages cross-base)
35 #:use-module (gnu packages disk)
36 #:use-module (gnu packages flex)
a86177d6 37 #:use-module (gnu packages fontutils)
862e38d5 38 #:use-module (gnu packages gettext)
65d8b777 39 #:use-module (gnu packages linux)
862e38d5 40 #:use-module (gnu packages man)
444f9dcc 41 #:use-module (gnu packages mtools)
862e38d5 42 #:use-module (gnu packages ncurses)
96b714f5
DC
43 #:use-module (gnu packages perl)
44 #:use-module (gnu packages python)
58301666 45 #:use-module (gnu packages texinfo)
12c613b5 46 #:use-module (gnu packages swig)
59132b80 47 #:use-module (gnu packages virtualization)
862e38d5
DC
48 #:use-module (guix build-system gnu)
49 #:use-module (guix download)
50 #:use-module (guix git-download)
51 #:use-module ((guix licenses) #:prefix license:)
52 #:use-module (guix packages)
53 #:use-module (guix utils))
65d8b777 54
9b24c768
LC
55(define unifont
56 ;; GNU Unifont, <http://gnu.org/s/unifont>.
57 ;; GRUB needs it for its graphical terminal, gfxterm.
58 (origin
59 (method url-fetch)
60 (uri
61 "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz")
62 (sha256
63 (base32
64 "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
65
65d8b777
LC
66(define-public grub
67 (package
68 (name "grub")
3586a3e9 69 (version "2.02")
65d8b777
LC
70 (source (origin
71 (method url-fetch)
3586a3e9 72 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
65d8b777
LC
73 (sha256
74 (base32
3586a3e9 75 "03vvdfhdmf16121v7xs8is2krwnv15wpkhkf16a4yf8nsfc3f2w1"))))
65d8b777
LC
76 (build-system gnu-build-system)
77 (arguments
d846834f 78 '(#:phases (modify-phases %standard-phases
358db004 79 (add-after 'unpack 'patch-stuff
04e0eac1
MW
80 (lambda* (#:key inputs #:allow-other-keys)
81 (substitute* "grub-core/Makefile.in"
82 (("/bin/sh") (which "sh")))
65d8b777 83
358db004
LC
84 ;; Give the absolute file name of 'mdadm', used to
85 ;; determine the root file system when it's a RAID
86 ;; device. Failing to do that, 'grub-probe' silently
87 ;; fails if 'mdadm' is not in $PATH.
88 (substitute* "grub-core/osdep/linux/getroot.c"
89 (("argv\\[0\\] = \"mdadm\"")
90 (string-append "argv[0] = \""
91 (assoc-ref inputs "mdadm")
92 "/sbin/mdadm\"")))
93
04e0eac1
MW
94 ;; Make the font visible.
95 (copy-file (assoc-ref inputs "unifont") "unifont.bdf.gz")
96 (system* "gunzip" "unifont.bdf.gz")
23a53a95
LF
97 #t))
98 (add-before 'check 'disable-flaky-test
99 (lambda _
100 ;; This test is unreliable. For more information, see:
101 ;; <https://bugs.gnu.org/26936>.
102 (substitute* "Makefile.in"
103 (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
104 "grub_cmd_date grub_cmd_sleep"))
105 #t)))))
65d8b777 106 (inputs
10da75df
LC
107 `(("gettext" ,gettext-minimal)
108
109 ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and
110 ;; 'grub-install' to recognize mapped devices (LUKS, etc.)
111 ("lvm2" ,lvm2)
112
113 ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install'
114 ;; to determine whether the root file system is RAID.
358db004 115 ("mdadm" ,mdadm)
10da75df 116
65d8b777
LC
117 ("freetype" ,freetype)
118 ;; ("libusb" ,libusb)
04e0eac1 119 ;; ("fuse" ,fuse)
01eafd38 120 ("ncurses" ,ncurses)))
65d8b777 121 (native-inputs
9b24c768
LC
122 `(("unifont" ,unifont)
123 ("bison" ,bison)
0a3aca47
LF
124 ;; Due to a bug in flex >= 2.6.2, GRUB must be built with an older flex:
125 ;; <http://lists.gnu.org/archive/html/grub-devel/2017-02/msg00133.html>
126 ;; TODO Try building with flex > 2.6.4.
127 ("flex" ,flex-2.6.1)
58301666
MW
128 ("texinfo" ,texinfo)
129 ("help2man" ,help2man)
65d8b777
LC
130
131 ;; Dependencies for the test suite. The "real" QEMU is needed here,
132 ;; because several targets are used.
7febe3a2 133 ("parted" ,parted)
7d8f7ab9 134 ("qemu" ,qemu-minimal)
65d8b777 135 ("xorriso" ,xorriso)))
175b259c 136 (home-page "https://www.gnu.org/software/grub/")
79c311b8 137 (synopsis "GRand Unified Boot loader")
65d8b777 138 (description
a22dc0c4 139 "GRUB is a multiboot bootloader. It is used for initially loading the
35b9e423 140kernel of an operating system and then transferring control to it. The kernel
c5779c93 141then goes on to load the rest of the operating system. As a multiboot
574e86f9
LC
142bootloader, GRUB handles the presence of multiple operating systems installed
143on the same computer; upon booting the computer, the user is presented with a
a22dc0c4 144menu to select one of the installed operating systems.")
3f73aa1a 145 (license license:gpl3+)
99effc8f 146 (properties '((cpe-name . "grub2")))))
acb5f7c3
MB
147
148(define-public grub-efi
149 (package
150 (inherit grub)
151 (name "grub-efi")
152 (synopsis "GRand Unified Boot loader (UEFI version)")
153 (inputs
154 `(("efibootmgr" ,efibootmgr)
444f9dcc 155 ("mtools", mtools)
acb5f7c3
MB
156 ,@(package-inputs grub)))
157 (arguments
158 `(;; TODO: Tests need a UEFI firmware for qemu. There is one at
159 ;; https://github.com/tianocore/edk2/tree/master/OvmfPkg .
160 ;; Search for 'OVMF' in "tests/util/grub-shell.in".
161 #:tests? #f
162 ,@(substitute-keyword-arguments (package-arguments grub)
ef753a1a
LC
163 ((#:configure-flags flags ''())
164 `(cons "--with-platform=efi" ,flags))
acb5f7c3
MB
165 ((#:phases phases)
166 `(modify-phases ,phases
167 (add-after 'patch-stuff 'use-absolute-efibootmgr-path
168 (lambda* (#:key inputs #:allow-other-keys)
169 (substitute* "grub-core/osdep/unix/platform.c"
170 (("efibootmgr")
171 (string-append (assoc-ref inputs "efibootmgr")
172 "/sbin/efibootmgr")))
444f9dcc
DM
173 #t))
174 (add-after 'patch-stuff 'use-absolute-mtools-path
175 (lambda* (#:key inputs #:allow-other-keys)
176 (let ((mtools (assoc-ref inputs "mtools")))
177 (substitute* "util/grub-mkrescue.c"
178 (("\"mformat\"")
179 (string-append "\"" mtools
180 "/bin/mformat\"")))
181 (substitute* "util/grub-mkrescue.c"
182 (("\"mcopy\"")
183 (string-append "\"" mtools
184 "/bin/mcopy\"")))
185 #t))))))))))
96b714f5 186
dd4b7476
DM
187;; Because grub searches hardcoded paths it's easiest to just build grub
188;; again to make it find both grub-pc and grub-efi. There is a command
189;; line argument which allows you to specify ONE platform - but
190;; grub-mkrescue will use multiple platforms if they are available
191;; in the installation directory (without command line argument).
192(define-public grub-hybrid
193 (package
194 (inherit grub-efi)
195 (name "grub-hybrid")
196 (synopsis "GRand Unified Boot loader (hybrid version)")
197 (inputs
198 `(("grub" ,grub)
199 ,@(package-inputs grub-efi)))
200 (arguments
201 (substitute-keyword-arguments (package-arguments grub-efi)
202 ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
203 `((ice-9 ftw) ,@modules))
204 ((#:phases phases)
205 `(modify-phases ,phases
206 (add-after 'install 'install-non-efi
207 (lambda* (#:key inputs outputs #:allow-other-keys)
208 (let ((input-dir (string-append (assoc-ref inputs "grub")
209 "/lib/grub"))
210 (output-dir (string-append (assoc-ref outputs "out")
211 "/lib/grub")))
212 (for-each
213 (lambda (basename)
214 (if (not (string-prefix? "." basename))
215 (symlink (string-append input-dir "/" basename)
216 (string-append output-dir "/" basename))))
217 (scandir input-dir))
218 #t)))))))))
219
96b714f5
DC
220(define-public syslinux
221 (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
222 (package
223 (name "syslinux")
224 (version (git-version "6.04-pre" "1" commit))
225 (source (origin
226 (method git-fetch)
227 (uri (git-reference
228 (url "https://github.com/geneC/syslinux")
229 (commit commit)))
230 (file-name (git-file-name name version))
231 (sha256
232 (base32
233 "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc"))))
234 (build-system gnu-build-system)
235 (native-inputs
236 `(("nasm" ,nasm)
237 ("perl" ,perl)
238 ("python-2" ,python-2)))
239 (inputs
240 `(("libuuid" ,util-linux)))
241 (arguments
242 `(#:parallel-build? #f
243 #:make-flags
244 (list (string-append "BINDIR=" %output "/bin")
245 (string-append "SBINDIR=" %output "/sbin")
246 (string-append "LIBDIR=" %output "/lib")
247 (string-append "INCDIR=" %output "/include")
248 (string-append "DATADIR=" %output "/share")
249 (string-append "MANDIR=" %output "/share/man")
250 "PERL=perl"
251 "bios")
252 #:phases
253 (modify-phases %standard-phases
254 (add-after 'unpack 'patch-files
255 (lambda _
256 (substitute* (find-files "." "Makefile.*|ppmtolss16")
257 (("/bin/pwd") (which "pwd"))
258 (("/bin/echo") (which "echo"))
259 (("/usr/bin/perl") (which "perl")))
260 #t))
261 (delete 'configure)
262 (add-before 'build 'set-permissions
263 (lambda _
264 (zero? (system* "chmod" "a+w" "utils/isohybrid.in"))))
265 (replace 'check
266 (lambda _
267 (setenv "CC" "gcc")
268 (substitute* "tests/unittest/include/unittest/unittest.h"
269 ;; Don't look up headers under /usr.
270 (("/usr/include/") ""))
271 (zero? (system* "make" "unittest")))))))
272 (home-page "http://www.syslinux.org")
273 (synopsis "Lightweight Linux bootloader")
274 (description "Syslinux is a lightweight Linux bootloader.")
275 (license (list license:gpl2+
276 license:bsd-3 ; gnu-efi/*
277 license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/*
278 ;; Also contains:
279 license:expat license:isc license:zlib)))))
862e38d5
DC
280
281(define-public dtc
282 (package
283 (name "dtc")
ab8757c5 284 (version "1.4.5")
862e38d5
DC
285 (source (origin
286 (method url-fetch)
287 (uri (string-append
3b4efb1f 288 "mirror://kernel.org/software/utils/dtc/"
862e38d5
DC
289 "dtc-" version ".tar.xz"))
290 (sha256
291 (base32
ab8757c5 292 "08gnl39i4xy3dm8iqwlz2ygx0ml1bgc5kpiys5ll1wvah1j72b04"))))
862e38d5
DC
293 (build-system gnu-build-system)
294 (native-inputs
295 `(("bison" ,bison)
12c613b5
EF
296 ("flex" ,flex)
297 ("swig" ,swig)))
298 (inputs
299 `(("python-2" ,python-2)))
862e38d5
DC
300 (arguments
301 `(#:make-flags
302 (list "CC=gcc"
303 (string-append "PREFIX=" (assoc-ref %outputs "out"))
12c613b5 304 (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
862e38d5
DC
305 "INSTALL=install")
306 #:phases
307 (modify-phases %standard-phases
308 (delete 'configure))))
309 (home-page "https://www.devicetree.org")
310 (synopsis "Compiles device tree source files")
311 (description "@command{dtc} compiles
312@uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
313tree binary files. These are board description files used by Linux and BSD.")
314 (license license:gpl2+)))
315
316(define u-boot
317 (package
318 (name "u-boot")
13136283 319 (version "2017.07")
862e38d5
DC
320 (source (origin
321 (method url-fetch)
322 (uri (string-append
323 "ftp://ftp.denx.de/pub/u-boot/"
324 "u-boot-" version ".tar.bz2"))
325 (sha256
326 (base32
13136283 327 "1zzywk0fgngm1mfnhkp8d0v57rs51zr1y6rp4p03i6nbibfbyx2k"))))
862e38d5
DC
328 (native-inputs
329 `(("bc" ,bc)
330 ("dtc" ,dtc)
331 ("python-2" ,python-2)))
332 (build-system gnu-build-system)
333 (home-page "http://www.denx.de/wiki/U-Boot/")
334 (synopsis "ARM bootloader")
335 (description "U-Boot is a bootloader used mostly for ARM boards. It
336also initializes the boards (RAM etc).")
337 (license license:gpl2+)))
338
339(define (make-u-boot-package board triplet)
340 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
2ac42fe5
MO
341 (let ((same-arch? (if (string-prefix? (%current-system)
342 (gnu-triplet->nix-system triplet))
3bfee8ff
EF
343 `#t
344 `#f)))
345 (package
346 (inherit u-boot)
347 (name (string-append "u-boot-" (string-downcase board)))
348 (native-inputs
349 `(,@(if (not same-arch?)
350 `(("cross-gcc" ,(cross-gcc triplet))
351 ("cross-binutils" ,(cross-binutils triplet)))
352 '())
353 ,@(package-native-inputs u-boot)))
354 (arguments
355 `(#:modules ((ice-9 ftw) (guix build utils) (guix build gnu-build-system))
356 #:test-target "test"
357 #:make-flags
358 (list "HOSTCC=gcc"
359 ,@(if (not same-arch?)
360 `((string-append "CROSS_COMPILE=" ,triplet "-"))
361 '()))
362 #:phases
363 (modify-phases %standard-phases
364 (replace 'configure
365 (lambda* (#:key outputs make-flags #:allow-other-keys)
366 (let ((config-name (string-append ,board "_defconfig")))
367 (if (file-exists? (string-append "configs/" config-name))
368 (zero? (apply system* "make" `(,@make-flags ,config-name)))
369 (begin
370 (display "Invalid board name. Valid board names are:")
371 (let ((suffix-len (string-length "_defconfig")))
372 (scandir "configs"
373 (lambda (file-name)
374 (when (string-suffix? "_defconfig" file-name)
375 (format #t
376 "- ~A\n"
377 (string-drop-right file-name
378 suffix-len))))))
379 #f)))))
380 (replace 'install
381 (lambda* (#:key outputs make-flags #:allow-other-keys)
382 (let* ((out (assoc-ref outputs "out"))
383 (libexec (string-append out "/libexec"))
dd208b93
MO
384 (uboot-files (append
385 (find-files "." ".*\\.(bin|efi|img|spl)$")
10b159a3 386 (find-files "." "^MLO$"))))
3bfee8ff
EF
387 (mkdir-p libexec)
388 (for-each
389 (lambda (file)
390 (let ((target-file (string-append libexec "/" file)))
391 (mkdir-p (dirname target-file))
392 (copy-file file target-file)))
393 uboot-files))))))))))
862e38d5
DC
394
395(define-public u-boot-vexpress
396 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
397
398(define-public u-boot-malta
399 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
400
401(define-public u-boot-beagle-bone-black
402 (make-u-boot-package "am335x_boneblack" "arm-linux-gnueabihf"))
4adeb3f6
EF
403
404(define-public u-boot-odroid-c2
405 (make-u-boot-package "odroid-c2" "aarch64-linux-gnu"))
aa90375a
AI
406
407(define-public os-prober
408 (package
409 (name "os-prober")
410 (version "1.76")
411 (source
412 (origin
413 (method url-fetch)
414 (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
415 version ".tar.xz"))
416 (sha256
417 (base32
418 "1vb45i76bqivlghrq7m3n07qfmmq4wxrkplqx8gywj011rhq19fk"))))
419 (build-system gnu-build-system)
420 (arguments
421 `(#:modules ((guix build gnu-build-system)
422 (guix build utils)
423 (ice-9 regex) ; for string-match
424 (srfi srfi-26)) ; for cut
425 #:make-flags (list "CC=gcc")
426 #:tests? #f ; no tests
427 #:phases
428 (modify-phases %standard-phases
429 (replace 'configure
430 (lambda* (#:key outputs #:allow-other-keys)
431 (substitute* (find-files ".")
432 (("/usr") (assoc-ref outputs "out")))
433 (substitute* (find-files "." "50mounted-tests$")
434 (("mkdir") "mkdir -p"))
435 #t))
436 (replace 'install
437 (lambda* (#:key outputs #:allow-other-keys)
438 (define (find-files-non-recursive directory)
439 (find-files directory
440 (lambda (file stat)
441 (string-match (string-append "^" directory "/[^/]*$")
442 file))
443 #:directories? #t))
444
445 (let* ((out (assoc-ref outputs "out"))
446 (bin (string-append out "/bin"))
447 (lib (string-append out "/lib"))
448 (share (string-append out "/share")))
449 (for-each (cut install-file <> bin)
450 (list "linux-boot-prober" "os-prober"))
451 (install-file "newns" (string-append lib "/os-prober"))
452 (install-file "common.sh" (string-append share "/os-prober"))
453 (install-file "os-probes/mounted/powerpc/20macosx"
454 (string-append lib "/os-probes/mounted"))
455 (for-each
456 (lambda (directory)
457 (for-each
458 (lambda (file)
459 (let ((destination (string-append lib "/" directory
460 "/" (basename file))))
461 (mkdir-p (dirname destination))
462 (copy-recursively file destination)))
463 (append (find-files-non-recursive (string-append directory "/common"))
464 (find-files-non-recursive (string-append directory "/x86")))))
465 (list "os-probes" "os-probes/mounted" "os-probes/init"
466 "linux-boot-probes" "linux-boot-probes/mounted"))
467 #t))))))
468 (home-page "https://joeyh.name/code/os-prober")
469 (synopsis "Detect other operating systems")
470 (description "os-prober probes disks on the system for other operating
471systems so that they can be added to the bootloader. It also works out how to
472boot existing GNU/Linux systems and detects what distribution is installed in
473order to add a suitable bootloader menu entry.")
474 (license license:gpl2+)))