2017-05-15 22:24:18 +02:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
|
;;; Copyright © 2017 David Craven <david@craven.ch>
|
|
|
|
|
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
|
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
(define-module (gnu bootloader extlinux)
|
|
|
|
|
#:use-module (gnu bootloader)
|
|
|
|
|
#:use-module (gnu system)
|
2017-12-05 12:59:15 +01:00
|
|
|
|
#:use-module (gnu build bootloader)
|
2017-05-15 22:24:18 +02:00
|
|
|
|
#:use-module (gnu packages bootloaders)
|
|
|
|
|
#:use-module (guix gexp)
|
|
|
|
|
#:use-module (guix monads)
|
|
|
|
|
#:use-module (guix records)
|
|
|
|
|
#:use-module (guix utils)
|
2017-05-18 12:06:36 +02:00
|
|
|
|
#:export (extlinux-bootloader
|
|
|
|
|
extlinux-bootloader-gpt))
|
2017-05-15 22:24:18 +02:00
|
|
|
|
|
|
|
|
|
(define* (extlinux-configuration-file config entries
|
|
|
|
|
#:key
|
|
|
|
|
(system (%current-system))
|
|
|
|
|
(old-entries '()))
|
|
|
|
|
"Return the U-Boot configuration file corresponding to CONFIG, a
|
|
|
|
|
<u-boot-configuration> object, and where the store is available at STORE-FS, a
|
|
|
|
|
<file-system> object. OLD-ENTRIES is taken to be a list of menu entries
|
|
|
|
|
corresponding to old generations of the system."
|
|
|
|
|
|
|
|
|
|
(define all-entries
|
2017-06-29 12:42:59 +02:00
|
|
|
|
(append entries (bootloader-configuration-menu-entries config)))
|
2017-05-15 22:24:18 +02:00
|
|
|
|
|
2017-06-29 12:42:59 +02:00
|
|
|
|
(define (menu-entry->gexp entry)
|
|
|
|
|
(let ((label (menu-entry-label entry))
|
|
|
|
|
(kernel (menu-entry-linux entry))
|
|
|
|
|
(kernel-arguments (menu-entry-linux-arguments entry))
|
|
|
|
|
(initrd (menu-entry-initrd entry)))
|
2017-05-15 22:24:18 +02:00
|
|
|
|
#~(format port "LABEL ~a
|
|
|
|
|
MENU LABEL ~a
|
|
|
|
|
KERNEL ~a
|
|
|
|
|
FDTDIR ~a/lib/dtbs
|
|
|
|
|
INITRD ~a
|
|
|
|
|
APPEND ~a
|
|
|
|
|
~%"
|
|
|
|
|
#$label #$label
|
2017-11-22 20:14:16 +01:00
|
|
|
|
#$kernel (dirname #$kernel) #$initrd
|
2017-05-15 22:24:18 +02:00
|
|
|
|
(string-join (list #$@kernel-arguments)))))
|
|
|
|
|
|
|
|
|
|
(define builder
|
|
|
|
|
#~(call-with-output-file #$output
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(let ((timeout #$(bootloader-configuration-timeout config)))
|
2017-05-21 18:56:03 +02:00
|
|
|
|
(format port "# This file was generated from your GuixSD configuration. Any changes
|
|
|
|
|
# will be lost upon reconfiguration.
|
2017-05-15 22:24:18 +02:00
|
|
|
|
UI menu.c32
|
2018-05-12 00:02:01 +02:00
|
|
|
|
MENU TITLE GuixSD Boot Options
|
2017-05-15 22:24:18 +02:00
|
|
|
|
PROMPT ~a
|
|
|
|
|
TIMEOUT ~a~%"
|
|
|
|
|
(if (> timeout 0) 1 0)
|
|
|
|
|
;; timeout is expressed in 1/10s of seconds.
|
|
|
|
|
(* 10 timeout))
|
2017-06-29 12:42:59 +02:00
|
|
|
|
#$@(map menu-entry->gexp all-entries)
|
2017-05-15 22:24:18 +02:00
|
|
|
|
|
|
|
|
|
#$@(if (pair? old-entries)
|
|
|
|
|
#~((format port "~%")
|
2017-06-29 12:42:59 +02:00
|
|
|
|
#$@(map menu-entry->gexp old-entries)
|
2017-05-15 22:24:18 +02:00
|
|
|
|
(format port "~%"))
|
|
|
|
|
#~())))))
|
|
|
|
|
|
|
|
|
|
(gexp->derivation "extlinux.conf" builder))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Install procedures.
|
|
|
|
|
;;;
|
|
|
|
|
|
2017-05-18 12:06:36 +02:00
|
|
|
|
(define (install-extlinux mbr)
|
2017-05-15 22:24:18 +02:00
|
|
|
|
#~(lambda (bootloader device mount-point)
|
|
|
|
|
(let ((extlinux (string-append bootloader "/sbin/extlinux"))
|
|
|
|
|
(install-dir (string-append mount-point "/boot/extlinux"))
|
|
|
|
|
(syslinux-dir (string-append bootloader "/share/syslinux")))
|
|
|
|
|
(for-each (lambda (file)
|
|
|
|
|
(install-file file install-dir))
|
|
|
|
|
(find-files syslinux-dir "\\.c32$"))
|
2017-12-01 14:09:38 +01:00
|
|
|
|
(unless
|
|
|
|
|
(and (zero? (system* extlinux "--install" install-dir))
|
2017-12-05 12:59:15 +01:00
|
|
|
|
(write-file-on-device
|
|
|
|
|
(string-append syslinux-dir "/" #$mbr) 440 device 0))
|
2017-05-15 22:24:18 +02:00
|
|
|
|
(error "failed to install SYSLINUX")))))
|
|
|
|
|
|
2017-05-18 12:06:36 +02:00
|
|
|
|
(define install-extlinux-mbr
|
|
|
|
|
(install-extlinux "mbr.bin"))
|
|
|
|
|
|
|
|
|
|
(define install-extlinux-gpt
|
|
|
|
|
(install-extlinux "gptmbr.bin"))
|
|
|
|
|
|
2017-05-15 22:24:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Bootloader definitions.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define extlinux-bootloader
|
|
|
|
|
(bootloader
|
|
|
|
|
(name 'extlinux)
|
|
|
|
|
(package syslinux)
|
2017-05-18 12:06:36 +02:00
|
|
|
|
(installer install-extlinux-mbr)
|
2017-05-15 22:24:18 +02:00
|
|
|
|
(configuration-file "/boot/extlinux/extlinux.conf")
|
|
|
|
|
(configuration-file-generator extlinux-configuration-file)))
|
2017-05-18 12:06:36 +02:00
|
|
|
|
|
|
|
|
|
(define extlinux-bootloader-gpt
|
|
|
|
|
(bootloader
|
|
|
|
|
(inherit extlinux-bootloader)
|
|
|
|
|
(installer install-extlinux-gpt)))
|