2013-09-11 22:36:50 +02:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2017-01-03 18:14:50 +01:00
|
|
|
|
;;; Copyright © 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
|
2016-10-28 12:07:18 +02:00
|
|
|
|
;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
|
2013-09-11 22:36:50 +02:00
|
|
|
|
;;;
|
|
|
|
|
;;; 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 system grub)
|
|
|
|
|
#:use-module (guix store)
|
|
|
|
|
#:use-module (guix packages)
|
|
|
|
|
#:use-module (guix derivations)
|
|
|
|
|
#:use-module (guix records)
|
gnu: vm: Rewrite helper functions as monadic functions.
* gnu/system/dmd.scm (host-name-service, nscd-service, mingetty-service,
syslog-service, guix-service, static-networking-service): Rewrite as
monadic functions.
(dmd-configuration-file): Use 'text-file' instead of
'add-text-to-store'.
* gnu/system/grub.scm (grub-configuration-file): Rewrite as a monadic
function.
* gnu/system/linux.scm (pam-services->directory): Likewise.
* gnu/system/shadow.scm (group-file, passwd-file, guix-build-accounts):
Likewise.
* gnu/system/vm.scm (expression->derivation-in-linux-vm, qemu-image,
union, system-qemu-image): Likewise.
2013-10-03 21:30:30 +02:00
|
|
|
|
#:use-module (guix monads)
|
2014-04-28 23:40:24 +02:00
|
|
|
|
#:use-module (guix gexp)
|
2014-11-08 15:07:18 +01:00
|
|
|
|
#:use-module (guix download)
|
2014-11-12 14:28:36 +01:00
|
|
|
|
#:use-module (gnu artwork)
|
2016-01-21 22:45:54 +01:00
|
|
|
|
#:use-module (gnu system file-systems)
|
2014-11-08 15:07:18 +01:00
|
|
|
|
#:autoload (gnu packages grub) (grub)
|
|
|
|
|
#:autoload (gnu packages compression) (gzip)
|
2016-10-25 00:58:26 +02:00
|
|
|
|
#:autoload (gnu packages gtk) (guile-cairo guile-rsvg)
|
2013-09-11 22:36:50 +02:00
|
|
|
|
#:use-module (ice-9 match)
|
2015-08-10 00:45:49 +02:00
|
|
|
|
#:use-module (ice-9 regex)
|
2013-09-11 22:36:50 +02:00
|
|
|
|
#:use-module (srfi srfi-1)
|
2016-10-28 12:07:18 +02:00
|
|
|
|
#:use-module (rnrs bytevectors)
|
2014-11-08 15:07:18 +01:00
|
|
|
|
#:export (grub-image
|
|
|
|
|
grub-image?
|
|
|
|
|
grub-image-aspect-ratio
|
|
|
|
|
grub-image-file
|
|
|
|
|
|
|
|
|
|
grub-theme
|
|
|
|
|
grub-theme?
|
|
|
|
|
grub-theme-images
|
|
|
|
|
grub-theme-color-normal
|
|
|
|
|
grub-theme-color-highlight
|
|
|
|
|
|
|
|
|
|
%background-image
|
|
|
|
|
%default-theme
|
|
|
|
|
|
|
|
|
|
grub-configuration
|
2014-05-18 21:58:01 +02:00
|
|
|
|
grub-configuration?
|
|
|
|
|
grub-configuration-device
|
2016-11-07 12:56:52 +01:00
|
|
|
|
grub-configuration-grub
|
2014-05-18 21:58:01 +02:00
|
|
|
|
|
|
|
|
|
menu-entry
|
2013-09-11 22:36:50 +02:00
|
|
|
|
menu-entry?
|
2014-05-18 21:58:01 +02:00
|
|
|
|
|
2013-09-11 22:36:50 +02:00
|
|
|
|
grub-configuration-file))
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
;;;
|
|
|
|
|
;;; Configuration of GNU GRUB.
|
|
|
|
|
;;;
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2016-10-28 12:07:18 +02:00
|
|
|
|
(define (strip-mount-point mount-point file)
|
|
|
|
|
"Strip MOUNT-POINT from FILE, which is a gexp or other lowerable object
|
|
|
|
|
denoting a file name."
|
|
|
|
|
(if (string=? mount-point "/")
|
|
|
|
|
file
|
|
|
|
|
#~(let ((file #$file))
|
|
|
|
|
(if (string-prefix? #$mount-point file)
|
|
|
|
|
(substring #$file #$(string-length mount-point))
|
|
|
|
|
file))))
|
2016-09-14 16:13:24 +02:00
|
|
|
|
|
2014-11-08 15:07:18 +01:00
|
|
|
|
(define-record-type* <grub-image>
|
|
|
|
|
grub-image make-grub-image
|
|
|
|
|
grub-image?
|
|
|
|
|
(aspect-ratio grub-image-aspect-ratio ;rational number
|
|
|
|
|
(default 4/3))
|
|
|
|
|
(file grub-image-file)) ;file-valued gexp (SVG)
|
|
|
|
|
|
|
|
|
|
(define-record-type* <grub-theme>
|
|
|
|
|
grub-theme make-grub-theme
|
|
|
|
|
grub-theme?
|
|
|
|
|
(images grub-theme-images
|
|
|
|
|
(default '())) ;list of <grub-image>
|
|
|
|
|
(color-normal grub-theme-color-normal
|
|
|
|
|
(default '((fg . cyan) (bg . blue))))
|
|
|
|
|
(color-highlight grub-theme-color-highlight
|
|
|
|
|
(default '((fg . white) (bg . blue)))))
|
|
|
|
|
|
|
|
|
|
(define %background-image
|
|
|
|
|
(grub-image
|
|
|
|
|
(aspect-ratio 4/3)
|
2015-05-07 23:07:54 +02:00
|
|
|
|
(file #~(string-append #$%artwork-repository
|
|
|
|
|
"/grub/GuixSD-fully-black-4-3.svg"))))
|
2014-11-08 15:07:18 +01:00
|
|
|
|
|
|
|
|
|
(define %default-theme
|
|
|
|
|
;; Default theme contributed by Felipe López.
|
|
|
|
|
(grub-theme
|
|
|
|
|
(images (list %background-image))
|
2015-02-12 23:42:29 +01:00
|
|
|
|
(color-highlight '((fg . yellow) (bg . black)))
|
2014-11-08 15:07:18 +01:00
|
|
|
|
(color-normal '((fg . light-gray) (bg . black))))) ;XXX: #x303030
|
|
|
|
|
|
2014-05-18 21:58:01 +02:00
|
|
|
|
(define-record-type* <grub-configuration>
|
|
|
|
|
grub-configuration make-grub-configuration
|
|
|
|
|
grub-configuration?
|
|
|
|
|
(grub grub-configuration-grub ; package
|
|
|
|
|
(default (@ (gnu packages grub) grub)))
|
|
|
|
|
(device grub-configuration-device) ; string
|
|
|
|
|
(menu-entries grub-configuration-menu-entries ; list
|
|
|
|
|
(default '()))
|
|
|
|
|
(default-entry grub-configuration-default-entry ; integer
|
2014-08-08 06:50:53 +02:00
|
|
|
|
(default 0))
|
2014-05-18 21:58:01 +02:00
|
|
|
|
(timeout grub-configuration-timeout ; integer
|
2014-11-08 15:07:18 +01:00
|
|
|
|
(default 5))
|
|
|
|
|
(theme grub-configuration-theme ; <grub-theme>
|
|
|
|
|
(default %default-theme)))
|
2014-05-18 21:58:01 +02:00
|
|
|
|
|
2013-09-11 22:36:50 +02:00
|
|
|
|
(define-record-type* <menu-entry>
|
|
|
|
|
menu-entry make-menu-entry
|
|
|
|
|
menu-entry?
|
|
|
|
|
(label menu-entry-label)
|
2016-10-28 12:07:18 +02:00
|
|
|
|
(device menu-entry-device ; file system uuid, label, or #f
|
|
|
|
|
(default #f))
|
|
|
|
|
(device-mount-point menu-entry-device-mount-point
|
|
|
|
|
(default "/"))
|
2013-09-11 22:36:50 +02:00
|
|
|
|
(linux menu-entry-linux)
|
|
|
|
|
(linux-arguments menu-entry-linux-arguments
|
2014-04-28 23:40:24 +02:00
|
|
|
|
(default '())) ; list of string-valued gexps
|
|
|
|
|
(initrd menu-entry-initrd)) ; file name of the initrd as a gexp
|
2013-09-11 22:36:50 +02:00
|
|
|
|
|
2014-11-08 15:07:18 +01:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Background image & themes.
|
|
|
|
|
;;;
|
|
|
|
|
|
2016-10-25 00:58:26 +02:00
|
|
|
|
(define* (svg->png svg #:key width height)
|
|
|
|
|
"Build a PNG of HEIGHT x WIDTH from SVG."
|
2014-11-08 15:07:18 +01:00
|
|
|
|
(gexp->derivation "grub-image.png"
|
2016-10-25 00:58:26 +02:00
|
|
|
|
(with-imported-modules '((gnu build svg))
|
|
|
|
|
#~(begin
|
|
|
|
|
;; We need these two libraries.
|
|
|
|
|
(add-to-load-path (string-append #$guile-rsvg
|
|
|
|
|
"/share/guile/site/"
|
|
|
|
|
(effective-version)))
|
|
|
|
|
(add-to-load-path (string-append #$guile-cairo
|
|
|
|
|
"/share/guile/site/"
|
|
|
|
|
(effective-version)))
|
|
|
|
|
|
|
|
|
|
(use-modules (gnu build svg))
|
|
|
|
|
(svg->png #$svg #$output
|
|
|
|
|
#:width #$width
|
|
|
|
|
#:height #$height)))))
|
2014-11-08 15:07:18 +01:00
|
|
|
|
|
2015-11-01 22:29:53 +01:00
|
|
|
|
(define* (grub-background-image config #:key (width 1024) (height 768))
|
2014-11-08 15:07:18 +01:00
|
|
|
|
"Return the GRUB background image defined in CONFIG with a ratio of
|
|
|
|
|
WIDTH/HEIGHT, or #f if none was found."
|
|
|
|
|
(let* ((ratio (/ width height))
|
|
|
|
|
(image (find (lambda (image)
|
|
|
|
|
(= (grub-image-aspect-ratio image) ratio))
|
|
|
|
|
(grub-theme-images (grub-configuration-theme config)))))
|
|
|
|
|
(if image
|
2016-10-25 00:58:26 +02:00
|
|
|
|
(svg->png (grub-image-file image)
|
|
|
|
|
#:width width #:height height)
|
2014-11-08 15:07:18 +01:00
|
|
|
|
(with-monad %store-monad
|
|
|
|
|
(return #f)))))
|
|
|
|
|
|
2016-10-28 12:07:18 +02:00
|
|
|
|
(define* (eye-candy config store-device store-mount-point
|
|
|
|
|
#:key system port)
|
2014-11-08 15:07:18 +01:00
|
|
|
|
"Return in %STORE-MONAD a gexp that writes to PORT (a port-valued gexp) the
|
|
|
|
|
'grub.cfg' part concerned with graphics mode, background images, colors, and
|
2016-10-28 12:07:18 +02:00
|
|
|
|
all that. STORE-DEVICE designates the device holding the store, and
|
|
|
|
|
STORE-MOUNT-POINT is its mount point; these are used to determine where the
|
|
|
|
|
background image and fonts must be searched for. SYSTEM must be the target
|
|
|
|
|
system string---e.g., \"x86_64-linux\"."
|
2015-08-10 00:45:49 +02:00
|
|
|
|
(define setup-gfxterm-body
|
2017-01-03 18:14:50 +01:00
|
|
|
|
;; Intel and EFI systems need to be switched into graphics mode, whereas
|
|
|
|
|
;; most other modern architectures have no other mode and therefore don't
|
|
|
|
|
;; need to be switched.
|
2015-08-10 00:45:49 +02:00
|
|
|
|
(if (string-match "^(x86_64|i[3-6]86)-" system)
|
|
|
|
|
"
|
2015-10-29 09:58:17 +01:00
|
|
|
|
# Leave 'gfxmode' to 'auto'.
|
2015-08-10 00:45:49 +02:00
|
|
|
|
insmod vbe
|
|
|
|
|
insmod vga
|
|
|
|
|
insmod video_bochs
|
|
|
|
|
insmod video_cirrus
|
|
|
|
|
insmod gfxterm
|
2017-01-03 18:14:50 +01:00
|
|
|
|
|
|
|
|
|
if [ \"${grub_platform}\" == efi ]; then
|
|
|
|
|
# This is for (U)EFI systems (these modules are unavailable in the
|
|
|
|
|
# non-EFI GRUB.) If we don't load them, GRUB boots in \"blind mode\",
|
|
|
|
|
# which isn't convenient.
|
|
|
|
|
insmod efi_gop
|
|
|
|
|
insmod efi_uga
|
|
|
|
|
fi
|
|
|
|
|
|
2015-08-10 00:45:49 +02:00
|
|
|
|
terminal_output gfxterm
|
|
|
|
|
"
|
|
|
|
|
""))
|
|
|
|
|
|
2014-11-08 15:07:18 +01:00
|
|
|
|
(define (theme-colors type)
|
|
|
|
|
(let* ((theme (grub-configuration-theme config))
|
|
|
|
|
(colors (type theme)))
|
|
|
|
|
(string-append (symbol->string (assoc-ref colors 'fg)) "/"
|
|
|
|
|
(symbol->string (assoc-ref colors 'bg)))))
|
|
|
|
|
|
2016-01-21 22:45:54 +01:00
|
|
|
|
(define font-file
|
2016-10-28 12:07:18 +02:00
|
|
|
|
(strip-mount-point store-mount-point
|
2016-09-14 16:13:24 +02:00
|
|
|
|
(file-append grub "/share/grub/unicode.pf2")))
|
2016-01-21 22:45:54 +01:00
|
|
|
|
|
2014-11-08 15:07:18 +01:00
|
|
|
|
(mlet* %store-monad ((image (grub-background-image config)))
|
2015-08-10 00:45:49 +02:00
|
|
|
|
(return (and image
|
|
|
|
|
#~(format #$port "
|
|
|
|
|
function setup_gfxterm {~a}
|
2014-11-08 15:07:18 +01:00
|
|
|
|
|
2014-12-13 22:15:01 +01:00
|
|
|
|
# Set 'root' to the partition that contains /gnu/store.
|
2016-01-21 22:45:54 +01:00
|
|
|
|
~a
|
2014-12-13 22:15:01 +01:00
|
|
|
|
|
2016-01-21 22:45:54 +01:00
|
|
|
|
if loadfont ~a; then
|
2015-08-10 00:45:49 +02:00
|
|
|
|
setup_gfxterm
|
2014-11-08 15:07:18 +01:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
insmod png
|
|
|
|
|
if background_image ~a; then
|
|
|
|
|
set color_normal=~a
|
|
|
|
|
set color_highlight=~a
|
|
|
|
|
else
|
|
|
|
|
set menu_color_normal=cyan/blue
|
|
|
|
|
set menu_color_highlight=white/blue
|
|
|
|
|
fi~%"
|
2015-08-10 00:45:49 +02:00
|
|
|
|
#$setup-gfxterm-body
|
2016-10-28 12:07:18 +02:00
|
|
|
|
#$(grub-root-search store-device font-file)
|
2016-01-21 22:45:54 +01:00
|
|
|
|
#$font-file
|
|
|
|
|
|
2016-10-28 12:07:18 +02:00
|
|
|
|
#$(strip-mount-point store-mount-point image)
|
2015-08-10 00:45:49 +02:00
|
|
|
|
#$(theme-colors grub-theme-color-normal)
|
|
|
|
|
#$(theme-colors grub-theme-color-highlight))))))
|
2014-11-08 15:07:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Configuration file.
|
|
|
|
|
;;;
|
|
|
|
|
|
2016-10-28 12:07:18 +02:00
|
|
|
|
(define (grub-root-search device file)
|
|
|
|
|
"Return the GRUB 'search' command to look for DEVICE, which contains FILE,
|
2016-01-21 22:45:54 +01:00
|
|
|
|
a gexp. The result is a gexp that can be inserted in the grub.cfg-generation
|
|
|
|
|
code."
|
2016-09-25 17:12:50 +02:00
|
|
|
|
;; Usually FILE is a file name gexp like "/gnu/store/…-linux/vmlinuz", but
|
|
|
|
|
;; it can also be something like "(hd0,msdos1)/vmlinuz" in the case of
|
|
|
|
|
;; custom menu entries. In the latter case, don't emit a 'search' command.
|
|
|
|
|
(if (and (string? file) (not (string-prefix? "/" file)))
|
|
|
|
|
""
|
2016-10-28 12:07:18 +02:00
|
|
|
|
(match device
|
|
|
|
|
;; Preferably refer to DEVICE by its UUID or label. This is more
|
2016-09-25 17:12:50 +02:00
|
|
|
|
;; efficient and less ambiguous, see <>.
|
2016-10-28 12:07:18 +02:00
|
|
|
|
((? bytevector? uuid)
|
2016-09-25 17:12:50 +02:00
|
|
|
|
(format #f "search --fs-uuid --set ~a"
|
2016-10-28 12:07:18 +02:00
|
|
|
|
(uuid->string device)))
|
|
|
|
|
((? string? label)
|
|
|
|
|
(format #f "search --label --set ~a" label))
|
|
|
|
|
(#f
|
2016-09-25 17:12:50 +02:00
|
|
|
|
#~(format #f "search --file --set ~a" #$file)))))
|
2016-01-21 22:45:54 +01:00
|
|
|
|
|
2016-10-28 12:07:18 +02:00
|
|
|
|
(define* (grub-configuration-file config entries
|
2014-06-25 22:54:52 +02:00
|
|
|
|
#:key
|
|
|
|
|
(system (%current-system))
|
|
|
|
|
(old-entries '()))
|
2014-05-18 21:58:01 +02:00
|
|
|
|
"Return the GRUB configuration file corresponding to CONFIG, a
|
2016-01-21 22:45:54 +01:00
|
|
|
|
<grub-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."
|
2014-05-18 21:58:01 +02:00
|
|
|
|
(define all-entries
|
|
|
|
|
(append entries (grub-configuration-menu-entries config)))
|
|
|
|
|
|
2014-04-28 23:40:24 +02:00
|
|
|
|
(define entry->gexp
|
2013-09-11 22:36:50 +02:00
|
|
|
|
(match-lambda
|
2016-10-28 12:07:18 +02:00
|
|
|
|
(($ <menu-entry> label device device-mount-point
|
|
|
|
|
linux arguments initrd)
|
|
|
|
|
;; Here DEVICE is the store and DEVICE-MOUNT-POINT is its mount point.
|
|
|
|
|
;; Use the right file names for LINUX and INITRD in case
|
|
|
|
|
;; DEVICE-MOUNT-POINT is not "/", meaning that the store is on a
|
|
|
|
|
;; separate partition.
|
|
|
|
|
(let ((linux (strip-mount-point device-mount-point linux))
|
|
|
|
|
(initrd (strip-mount-point device-mount-point initrd)))
|
2016-09-14 16:13:24 +02:00
|
|
|
|
#~(format port "menuentry ~s {
|
2016-01-21 22:45:54 +01:00
|
|
|
|
~a
|
2016-09-09 23:27:00 +02:00
|
|
|
|
linux ~a ~a
|
gnu: vm: Rewrite helper functions as monadic functions.
* gnu/system/dmd.scm (host-name-service, nscd-service, mingetty-service,
syslog-service, guix-service, static-networking-service): Rewrite as
monadic functions.
(dmd-configuration-file): Use 'text-file' instead of
'add-text-to-store'.
* gnu/system/grub.scm (grub-configuration-file): Rewrite as a monadic
function.
* gnu/system/linux.scm (pam-services->directory): Likewise.
* gnu/system/shadow.scm (group-file, passwd-file, guix-build-accounts):
Likewise.
* gnu/system/vm.scm (expression->derivation-in-linux-vm, qemu-image,
union, system-qemu-image): Likewise.
2013-10-03 21:30:30 +02:00
|
|
|
|
initrd ~a
|
2013-09-11 22:36:50 +02:00
|
|
|
|
}~%"
|
2016-09-14 16:13:24 +02:00
|
|
|
|
#$label
|
2016-10-28 12:07:18 +02:00
|
|
|
|
#$(grub-root-search device linux)
|
2016-09-14 16:13:24 +02:00
|
|
|
|
#$linux (string-join (list #$@arguments))
|
|
|
|
|
#$initrd)))))
|
2014-04-28 23:40:24 +02:00
|
|
|
|
|
2016-10-28 12:07:18 +02:00
|
|
|
|
(mlet %store-monad ((sugar (eye-candy config
|
|
|
|
|
(menu-entry-device (first entries))
|
|
|
|
|
(menu-entry-device-mount-point
|
|
|
|
|
(first entries))
|
|
|
|
|
#:system system
|
|
|
|
|
#:port #~port)))
|
2014-11-08 15:07:18 +01:00
|
|
|
|
(define builder
|
|
|
|
|
#~(call-with-output-file #$output
|
|
|
|
|
(lambda (port)
|
2016-09-08 14:56:14 +02:00
|
|
|
|
(format port
|
|
|
|
|
"# This file was generated from your GuixSD configuration. Any changes
|
|
|
|
|
# will be lost upon reconfiguration.
|
|
|
|
|
")
|
2014-11-08 15:07:18 +01:00
|
|
|
|
#$sugar
|
|
|
|
|
(format port "
|
2014-04-28 23:40:24 +02:00
|
|
|
|
set default=~a
|
2014-12-13 21:28:12 +01:00
|
|
|
|
set timeout=~a~%"
|
2014-11-08 15:07:18 +01:00
|
|
|
|
#$(grub-configuration-default-entry config)
|
2014-12-13 21:28:12 +01:00
|
|
|
|
#$(grub-configuration-timeout config))
|
2014-11-08 15:07:18 +01:00
|
|
|
|
#$@(map entry->gexp all-entries)
|
|
|
|
|
|
|
|
|
|
#$@(if (pair? old-entries)
|
|
|
|
|
#~((format port "
|
2014-06-25 22:54:52 +02:00
|
|
|
|
submenu \"GNU system, old configurations...\" {~%")
|
2014-11-08 15:07:18 +01:00
|
|
|
|
#$@(map entry->gexp old-entries)
|
|
|
|
|
(format port "}~%"))
|
|
|
|
|
#~()))))
|
2013-09-11 22:36:50 +02:00
|
|
|
|
|
2014-11-08 15:07:18 +01:00
|
|
|
|
(gexp->derivation "grub.cfg" builder)))
|
2013-09-11 22:36:50 +02:00
|
|
|
|
|
|
|
|
|
;;; grub.scm ends here
|