From c1d081d111fb4778b6a0625abbdd8cc540ae630f Mon Sep 17 00:00:00 2001
From: Leo Famulari
Date: Sun, 2 Apr 2017 22:18:00 -0400
Subject: [PATCH] system: grub: Expose GRUB settings for interactive
interfaces.
WIP: Does not validate input and setup-io is used in the wrong place
* gnu/system/grub.scm (): Add new fields
terminal-outputs, terminal-inputs, serial-unit, and serial-speed.
(grub-setup-io, setup-gfxterm): New procedures.
* doc/guix.texi (GRUB Configuration): Document the new fields.
---
doc/guix.texi | 17 ++++++++++++
gnu/system/grub.scm | 75 +++++++++++++++++++++++++++++++++++++++++------------
2 files changed, 75 insertions(+), 17 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index aa779e38e..8107872bc 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -14920,6 +14920,23 @@ The @code{grub-theme} object describing the theme to use.
@item @code{grub} (default: @code{grub})
The GRUB package to use.
+
address@hidden @code{terminal-outputs} (default: @code{'gfxterm})
+The output terminals used for the GRUB boot menu, as a list of symbols.
+
address@hidden @code{terminal-inputs} (default: @code{'()})
+The input terminals used for the GRUB boot menu, as a list of symbols.
+The default is the native platform terminal as determined by GRUB at
+run-time.
+
address@hidden @code{serial-unit} (default: @code{#f})
+The serial unit used by GRUB, as an integer from 0 to 3. The default
+value is deferred to GRUB; currently GRUB choosese 0, which corresponds
+to COM1.
+
address@hidden @code{serial-speed} (default: @code{#f})
+The speed of the serial interface, as an integer. The default value is
+deferred to GRUB; currently GRUB chooses 9600bps.
@end table
@end deftp
diff --git a/gnu/system/grub.scm b/gnu/system/grub.scm
index 4f9bde6a6..8a516f05f 100644
--- a/gnu/system/grub.scm
+++ b/gnu/system/grub.scm
@@ -107,17 +107,25 @@ denoting a file name."
(define-record-type*
grub-configuration make-grub-configuration
grub-configuration?
- (grub grub-configuration-grub ; package
- (default (@ (gnu packages bootloaders) grub)))
- (device grub-configuration-device) ; string
- (menu-entries grub-configuration-menu-entries ; list
- (default '()))
- (default-entry grub-configuration-default-entry ; integer
- (default 0))
- (timeout grub-configuration-timeout ; integer
- (default 5))
- (theme grub-configuration-theme ;
- (default %default-theme)))
+ (grub grub-configuration-grub ; package
+ (default (@ (gnu packages bootloaders) grub)))
+ (device grub-configuration-device) ; string
+ (menu-entries grub-configuration-menu-entries ; list
+ (default '()))
+ (default-entry grub-configuration-default-entry ; integer
+ (default 0))
+ (timeout grub-configuration-timeout ; integer
+ (default 5))
+ (theme grub-configuration-theme ;
+ (default %default-theme))
+ (terminal-outputs grub-configuration-terminal-outputs ; list of symbols
+ (default '(gfxterm)))
+ (terminal-inputs grub-configuration-terminal-inputs ; list of symbols
+ (default '()))
+ (serial-unit grub-configuration-serial-unit ; integer | #f
+ (default #f))
+ (serial-speed grub-configuration-serial-speed ; integer | #f
+ (default #f)))
(define-record-type*
menu-entry make-menu-entry
@@ -198,11 +206,16 @@ system string---e.g., \"x86_64-linux\"."
insmod vbe
insmod vga
fi
-
- terminal_output gfxterm
"
""))
+ (define (setup-gfxterm config font-file)
+ (if (memq 'gfxterm (grub-configuration-terminal-outputs config))
+ #~(format #f "if loadfont ~a; then
+ setup_gfxterm
+fi~%" #$font-file)
+ ""))
+
(define (theme-colors type)
(let* ((theme (grub-configuration-theme config))
(colors (type theme)))
@@ -221,9 +234,8 @@ function setup_gfxterm {~a}
# Set 'root' to the partition that contains /gnu/store.
~a
-if loadfont ~a; then
- setup_gfxterm
-fi
+~a
+~a
insmod png
if background_image ~a; then
@@ -235,7 +247,8 @@ else
fi~%"
#$setup-gfxterm-body
#$(grub-root-search store-device font-file)
- #$font-file
+ #$(grub-setup-io config)
+ #$(setup-gfxterm config font-file)
#$(strip-mount-point store-mount-point image)
#$(theme-colors grub-theme-color-normal)
@@ -246,6 +259,34 @@ fi~%"
;;; Configuration file.
;;;
+(define (grub-setup-io config)
+ "Return GRUB commands to configure the input / output interfaces. The result
+is a string that can be inserted in grub.cfg.
+TODO Check the bounds of unit, and compare outputs and inputs to a list of
+valid interfaces taken from the GRUB manual."
+ (let* ((symbols->string (lambda (list)
+ (string-join (map symbol->string list) " ")))
+ (outputs (grub-configuration-terminal-outputs config))
+ (inputs (grub-configuration-terminal-inputs config))
+ (unit (grub-configuration-serial-unit config))
+ (speed (grub-configuration-serial-speed config))
+ (io (string-append
+ "terminal_output " (symbols->string outputs) "\n"
+ (if (null? inputs)
+ ""
+ (string-append "terminal_input "
+ (symbols->string inputs) "\n"))
+ (if (or unit speed)
+ (string-append "serial"
+ (if unit
+ (string-append " --unit="
+ (number->string unit)) "")
+ (if speed
+ (string-append " --speed="
+ (number->string speed)) ""))
+ ""))))
+ (format #f "~a" io)))
+
(define (grub-root-search device file)
"Return the GRUB 'search' command to look for DEVICE, which contains FILE,
a gexp. The result is a gexp that can be inserted in the grub.cfg-generation
--
2.12.2