2013-09-11 20:36:50 +00:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2014-01-29 12:04:00 +00:00
|
|
|
|
;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
|
2013-09-11 20:36:50 +00: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 19:30:30 +00:00
|
|
|
|
#:use-module (guix monads)
|
2014-04-28 21:40:24 +00:00
|
|
|
|
#:use-module (guix gexp)
|
2014-11-08 14:07:18 +00:00
|
|
|
|
#:use-module (guix download)
|
2014-11-12 13:28:36 +00:00
|
|
|
|
#:use-module (gnu artwork)
|
2014-11-08 14:07:18 +00:00
|
|
|
|
#:autoload (gnu packages grub) (grub)
|
|
|
|
|
#:autoload (gnu packages inkscape) (inkscape)
|
|
|
|
|
#:autoload (gnu packages imagemagick) (imagemagick)
|
|
|
|
|
#:autoload (gnu packages compression) (gzip)
|
2013-09-11 20:36:50 +00:00
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
|
#:use-module (srfi srfi-1)
|
2014-11-08 14:07:18 +00: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 19:58:01 +00:00
|
|
|
|
grub-configuration?
|
|
|
|
|
grub-configuration-device
|
|
|
|
|
|
|
|
|
|
menu-entry
|
2013-09-11 20:36:50 +00:00
|
|
|
|
menu-entry?
|
2014-05-18 19:58:01 +00:00
|
|
|
|
|
2013-09-11 20:36:50 +00:00
|
|
|
|
grub-configuration-file))
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
;;;
|
|
|
|
|
;;; Configuration of GNU GRUB.
|
|
|
|
|
;;;
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2014-11-08 14:07:18 +00: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)
|
|
|
|
|
(file #~(string-append #$%artwork-repository "/grub/guix-4-3.svg"))))
|
|
|
|
|
|
|
|
|
|
(define %default-theme
|
|
|
|
|
;; Default theme contributed by Felipe López.
|
|
|
|
|
(grub-theme
|
|
|
|
|
(images (list %background-image))
|
2014-11-08 21:11:56 +00:00
|
|
|
|
(color-highlight '((fg . cyan) (bg . black))) ;XXX: fg should be #x3bb7f5
|
2014-11-08 14:07:18 +00:00
|
|
|
|
(color-normal '((fg . light-gray) (bg . black))))) ;XXX: #x303030
|
|
|
|
|
|
2014-05-18 19:58:01 +00: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 04:50:53 +00:00
|
|
|
|
(default 0))
|
2014-05-18 19:58:01 +00:00
|
|
|
|
(timeout grub-configuration-timeout ; integer
|
2014-11-08 14:07:18 +00:00
|
|
|
|
(default 5))
|
|
|
|
|
(theme grub-configuration-theme ; <grub-theme>
|
|
|
|
|
(default %default-theme)))
|
2014-05-18 19:58:01 +00:00
|
|
|
|
|
2013-09-11 20:36:50 +00:00
|
|
|
|
(define-record-type* <menu-entry>
|
|
|
|
|
menu-entry make-menu-entry
|
|
|
|
|
menu-entry?
|
|
|
|
|
(label menu-entry-label)
|
|
|
|
|
(linux menu-entry-linux)
|
|
|
|
|
(linux-arguments menu-entry-linux-arguments
|
2014-04-28 21:40:24 +00:00
|
|
|
|
(default '())) ; list of string-valued gexps
|
|
|
|
|
(initrd menu-entry-initrd)) ; file name of the initrd as a gexp
|
2013-09-11 20:36:50 +00:00
|
|
|
|
|
2014-11-08 14:07:18 +00:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Background image & themes.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define (svg->png svg)
|
|
|
|
|
"Build a PNG from SVG."
|
|
|
|
|
;; Don't use #:local-build? so that it's substitutable.
|
|
|
|
|
(gexp->derivation "grub-image.png"
|
|
|
|
|
#~(zero?
|
|
|
|
|
(system* (string-append #$inkscape "/bin/inkscape")
|
|
|
|
|
"--without-gui"
|
|
|
|
|
(string-append "--export-png=" #$output)
|
|
|
|
|
#$svg))))
|
|
|
|
|
|
|
|
|
|
(define (resize-image image width height)
|
|
|
|
|
"Resize IMAGE to WIDTHxHEIGHT."
|
|
|
|
|
;; Don't use #:local-build? so that it's substitutable.
|
|
|
|
|
(let ((size (string-append (number->string width)
|
|
|
|
|
"x" (number->string height))))
|
|
|
|
|
(gexp->derivation "grub-image.resized.png"
|
|
|
|
|
#~(zero?
|
|
|
|
|
(system* (string-append #$imagemagick "/bin/convert")
|
|
|
|
|
"-resize" #$size #$image #$output)))))
|
|
|
|
|
|
|
|
|
|
(define* (grub-background-image config #:key (width 640) (height 480))
|
|
|
|
|
"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
|
|
|
|
|
(mlet %store-monad ((png (svg->png (grub-image-file image))))
|
|
|
|
|
(resize-image png width height))
|
|
|
|
|
(with-monad %store-monad
|
|
|
|
|
(return #f)))))
|
|
|
|
|
|
|
|
|
|
(define (eye-candy config port)
|
|
|
|
|
"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
|
|
|
|
|
all that."
|
|
|
|
|
(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)))))
|
|
|
|
|
|
|
|
|
|
(mlet* %store-monad ((image (grub-background-image config)))
|
|
|
|
|
(return (and image #~(format #$port "
|
|
|
|
|
function load_video {
|
|
|
|
|
insmod vbe
|
|
|
|
|
insmod vga
|
|
|
|
|
insmod video_bochs
|
|
|
|
|
insmod video_cirrus
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if loadfont ~a/share/grub/unicode.pf2; then
|
|
|
|
|
set gfxmode=640x480
|
|
|
|
|
load_video
|
|
|
|
|
insmod gfxterm
|
|
|
|
|
terminal_output gfxterm
|
|
|
|
|
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~%"
|
|
|
|
|
#$grub
|
|
|
|
|
#$image
|
|
|
|
|
#$(theme-colors grub-theme-color-normal)
|
|
|
|
|
#$(theme-colors grub-theme-color-highlight))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Configuration file.
|
|
|
|
|
;;;
|
|
|
|
|
|
2014-05-18 19:58:01 +00:00
|
|
|
|
(define* (grub-configuration-file config entries
|
2014-06-25 20:54:52 +00:00
|
|
|
|
#:key
|
|
|
|
|
(system (%current-system))
|
|
|
|
|
(old-entries '()))
|
2014-05-18 19:58:01 +00:00
|
|
|
|
"Return the GRUB configuration file corresponding to CONFIG, a
|
2014-06-25 20:54:52 +00:00
|
|
|
|
<grub-configuration> object. OLD-ENTRIES is taken to be a list of menu
|
|
|
|
|
entries corresponding to old generations of the system."
|
2014-05-18 19:58:01 +00:00
|
|
|
|
(define all-entries
|
|
|
|
|
(append entries (grub-configuration-menu-entries config)))
|
|
|
|
|
|
2014-04-28 21:40:24 +00:00
|
|
|
|
(define entry->gexp
|
2013-09-11 20:36:50 +00:00
|
|
|
|
(match-lambda
|
|
|
|
|
(($ <menu-entry> label linux arguments initrd)
|
2014-04-28 21:40:24 +00:00
|
|
|
|
#~(format port "menuentry ~s {
|
2014-12-13 20:28:12 +00:00
|
|
|
|
# Set 'root' to the partition that contains the kernel.
|
|
|
|
|
search --file --set ~a/bzImage~%
|
|
|
|
|
|
2014-04-28 21:40:24 +00:00
|
|
|
|
linux ~a/bzImage ~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 19:30:30 +00:00
|
|
|
|
initrd ~a
|
2013-09-11 20:36:50 +00:00
|
|
|
|
}~%"
|
2014-04-28 21:40:24 +00:00
|
|
|
|
#$label
|
2014-12-13 20:28:12 +00:00
|
|
|
|
#$linux #$linux (string-join (list #$@arguments))
|
2014-04-28 21:40:24 +00:00
|
|
|
|
#$initrd))))
|
|
|
|
|
|
2014-11-08 14:07:18 +00:00
|
|
|
|
(mlet %store-monad ((sugar (eye-candy config #~port)))
|
|
|
|
|
(define builder
|
|
|
|
|
#~(call-with-output-file #$output
|
|
|
|
|
(lambda (port)
|
|
|
|
|
#$sugar
|
|
|
|
|
(format port "
|
2014-04-28 21:40:24 +00:00
|
|
|
|
set default=~a
|
2014-12-13 20:28:12 +00:00
|
|
|
|
set timeout=~a~%"
|
2014-11-08 14:07:18 +00:00
|
|
|
|
#$(grub-configuration-default-entry config)
|
2014-12-13 20:28:12 +00:00
|
|
|
|
#$(grub-configuration-timeout config))
|
2014-11-08 14:07:18 +00:00
|
|
|
|
#$@(map entry->gexp all-entries)
|
|
|
|
|
|
|
|
|
|
#$@(if (pair? old-entries)
|
|
|
|
|
#~((format port "
|
2014-06-25 20:54:52 +00:00
|
|
|
|
submenu \"GNU system, old configurations...\" {~%")
|
2014-11-08 14:07:18 +00:00
|
|
|
|
#$@(map entry->gexp old-entries)
|
|
|
|
|
(format port "}~%"))
|
|
|
|
|
#~()))))
|
2013-09-11 20:36:50 +00:00
|
|
|
|
|
2014-11-08 14:07:18 +00:00
|
|
|
|
(gexp->derivation "grub.cfg" builder)))
|
2013-09-11 20:36:50 +00:00
|
|
|
|
|
|
|
|
|
;;; grub.scm ends here
|