guix/gnu/bootloader/grub.scm

512 lines
19 KiB
Scheme
Raw Normal View History

;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2019, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@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 grub)
#:use-module (guix records)
#:use-module ((guix utils) #:select (%current-system))
#:use-module (guix gexp)
#:use-module (gnu artwork)
#:use-module (gnu bootloader)
2017-09-06 03:28:28 -04:00
#:use-module (gnu system uuid)
file-systems: Remove 'title' field and add <file-system-label>. The 'title' field was easily overlooked and was an endless source of confusion. Now, the value of the 'device' field is self-contained. * gnu/system/file-systems.scm (<file-system>): Change constructor name to '%file-system'. [title]: Remove. (<file-system-label>): New record type with printer. (report-deprecation, device-expression) (process-file-system-declaration, file-system): New macros. (file-system-title): New procedure. (file-system->spec, spec->file-system): Adjust to handle <file-system-label>. * gnu/system.scm (bootable-kernel-arguments): Add case for 'file-system-label?'. (read-boot-parameters): Likewise. (mapped-device-user): Avoid 'file-system-title'. (fs->boot-device): Remove. (operating-system-boot-parameters): Use 'file-system-device' instead of 'fs->boot-device'. (device->sexp): Add case for 'file-system-label?'. * gnu/bootloader/grub.scm (grub-root-search): Add case for 'file-system-label?'. * gnu/system/examples/bare-bones.tmpl, gnu/system/examples/beaglebone-black.tmpl, gnu/system/examples/lightweight-desktop.tmpl, gnu/system/examples/vm-image.tmpl: Remove uses of 'title'. * gnu/system/vm.scm (virtualized-operating-system): Remove uses of 'file-system-title'. * guix/scripts/system.scm (check-file-system-availability): Likewise, and adjust fix-it hint. (check-initrd-modules)[file-system-/dev]: Likewise. * gnu/build/file-systems.scm (canonicalize-device-spec): Remove 'title' parameter. [canonical-title]: Remove. Match on SPEC's type rather than on CANONICAL-TITLE. (mount-file-system): Adjust caller. * gnu/build/linux-boot.scm (boot-system): Interpret ROOT here. * gnu/services/base.scm (file-system->fstab-entry): Remove use of 'file-system-title'. * doc/guix.texi (File Systems): Remove documentation of the 'title' field. Rewrite documentation of 'device' and document 'file-system-label'.
2018-05-18 07:43:07 -04:00
#:use-module (gnu system file-systems)
#:use-module (gnu system keyboard)
#:use-module (gnu packages bootloaders)
#:autoload (gnu packages gtk) (guile-cairo guile-rsvg)
#:autoload (gnu packages xorg) (xkeyboard-config)
#:use-module (ice-9 match)
#:use-module (ice-9 regex)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-2)
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
#:export (grub-theme
grub-theme?
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
grub-theme-image
grub-theme-resolution
grub-theme-color-normal
grub-theme-color-highlight
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
grub-theme-gfxmode
grub-bootloader
grub-efi-bootloader
grub-mkrescue-bootloader
grub-minimal-bootloader
grub-configuration))
;;; Commentary:
;;;
;;; Configuration of GNU GRUB.
;;;
;;; Code:
(define* (normalize-file file mount-point btrfs-subvolume-file-name)
"Strip MOUNT-POINT and prepend BTRFS-SUBVOLUME-FILE-NAME to FILE, a
G-expression or other lowerable object denoting a file name."
(define (strip-mount-point mount-point file)
(if mount-point
(if (string=? mount-point "/")
file
#~(let ((file #$file))
(if (string-prefix? #$mount-point file)
(substring #$file #$(string-length mount-point))
file)))
file))
(define (prepend-btrfs-subvolume-file-name btrfs-subvolume-file-name file)
(if btrfs-subvolume-file-name
#~(string-append #$btrfs-subvolume-file-name #$file)
file))
(prepend-btrfs-subvolume-file-name btrfs-subvolume-file-name
(strip-mount-point mount-point file)))
(define-record-type* <grub-theme>
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
;; Default theme contributed by Felipe López.
grub-theme make-grub-theme
grub-theme?
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
(image grub-theme-image
(default (file-append %artwork-repository
"/grub/GuixSD-fully-black-4-3.svg")))
(resolution grub-theme-resolution
(default '(1024 . 768)))
(color-normal grub-theme-color-normal
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
(default '((fg . light-gray) (bg . black))))
(color-highlight grub-theme-color-highlight
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
(default '((fg . yellow) (bg . black))))
(gfxmode grub-theme-gfxmode
(default '("auto")))) ;list of string
;;;
;;; Background image & themes.
;;;
(define (bootloader-theme config)
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
"Return user defined theme in CONFIG if defined or a default theme
otherwise."
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
(or (bootloader-configuration-theme config) (grub-theme)))
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
(define* (image->png image #:key width height)
"Build a PNG of HEIGHT x WIDTH from IMAGE if its file suffix is \".svg\".
Otherwise the picture in IMAGE is just copied."
(computed-file "grub-image.png"
(with-imported-modules '((gnu build svg))
(with-extensions (list guile-rsvg guile-cairo)
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
#~(if (string-suffix? ".svg" #+image)
(begin
(use-modules (gnu build svg))
(svg->png #+image #$output
#:width #$width
#:height #$height))
(copy-file #+image #$output))))))
(define* (grub-background-image config)
"Return the GRUB background image defined in CONFIG or #f if none was found.
If the suffix of the image file is \".svg\", then it is converted into a PNG
file with the resolution provided in CONFIG."
(let* ((theme (bootloader-theme config))
(image (grub-theme-image theme)))
(and image
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
(match (grub-theme-resolution theme)
(((? number? width) . (? number? height))
(image->png image #:width width #:height height))
(_ #f)))))
(define* (eye-candy config store-device store-mount-point
#:key btrfs-store-subvolume-file-name system port)
"Return a gexp that writes to PORT (a port-valued gexp) the 'grub.cfg' part
concerned with graphics mode, background images, colors, and 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\". BTRFS-STORE-SUBVOLUME-FILE-NAME is the file name of the
Btrfs subvolume, to be prepended to any store path, if any."
(define setup-gfxterm-body
(let ((gfxmode
(or (and-let* ((theme (bootloader-configuration-theme config))
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution". * gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2020-05-17 17:53:50 -04:00
(gfxmode (grub-theme-gfxmode theme)))
(string-join gfxmode ";"))
"auto")))
;; 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.
;; XXX: Do we really need to restrict to x86 systems? We could imitate
;; what the GRUB default configuration does and decide based on whether
;; a user provided 'gfxterm' in the terminal-outputs field of their
;; bootloader-configuration record.
(if (string-match "^(x86_64|i[3-6]86)-" system)
(format #f "
set gfxmode=~a
insmod all_video
insmod gfxterm~%" gfxmode)
"")))
(define (setup-gfxterm config font-file)
(if (memq 'gfxterm (bootloader-configuration-terminal-outputs config))
#~(format #f "if loadfont ~a; then
setup_gfxterm
fi~%" #+font-file)
""))
(define (theme-colors type)
(let* ((theme (bootloader-theme config))
(colors (type theme)))
(string-append (symbol->string (assoc-ref colors 'fg)) "/"
(symbol->string (assoc-ref colors 'bg)))))
(define font-file
(normalize-file (file-append grub "/share/grub/unicode.pf2")
store-mount-point
btrfs-store-subvolume-file-name))
(define image
(normalize-file (grub-background-image config)
store-mount-point
btrfs-store-subvolume-file-name))
(and image
#~(format #$port "
function setup_gfxterm {~a}
# Set 'root' to the partition that contains /gnu/store.
~a
~a
~a
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~%"
#$setup-gfxterm-body
#$(grub-root-search store-device font-file)
#$(setup-gfxterm config font-file)
#$(grub-setup-io config)
#$image
#$(theme-colors grub-theme-color-normal)
#$(theme-colors grub-theme-color-highlight))))
;;;
;;; Configuration file.
;;;
(define* (keyboard-layout-file layout
#:key
(grub grub))
"Process the X keyboard layout description LAYOUT, a <keyboard-layout> record,
and return a file in the format for GRUB keymaps. LAYOUT must be present in
the 'share/X11/xkb/symbols/' directory of 'xkeyboard-config'."
(define builder
(with-imported-modules '((guix build utils))
#~(begin
(use-modules (guix build utils))
;; 'grub-kbdcomp' passes all its arguments but '-o' to 'ckbcomp'
;; (from the 'console-setup' package).
(invoke #+(file-append grub "/bin/grub-mklayout")
"-i" #+(keyboard-layout->console-keymap layout)
"-o" #$output))))
(computed-file (string-append "grub-keymap."
(string-map (match-lambda
(#\, #\-)
(chr chr))
(keyboard-layout-name layout)))
builder))
(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."
(let* ((symbols->string (lambda (list)
(string-join (map symbol->string list) " ")))
(outputs (bootloader-configuration-terminal-outputs config))
(inputs (bootloader-configuration-terminal-inputs config))
(unit (bootloader-configuration-serial-unit config))
(speed (bootloader-configuration-serial-speed config))
;; Respectively, GRUB_TERMINAL_OUTPUT and GRUB_TERMINAL_INPUT,
;; as documented in GRUB manual section "Simple Configuration
;; Handling".
(valid-outputs '(console serial serial_0 serial_1 serial_2 serial_3
gfxterm vga_text mda_text morse spkmodem))
(valid-inputs '(console serial serial_0 serial_1 serial_2 serial_3
at_keyboard usb_keyboard))
(io (string-append
"terminal_output "
(symbols->string
(map
(lambda (output)
(if (memq output valid-outputs) output #f)) outputs)) "\n"
(if (null? inputs)
""
(string-append
"terminal_input "
(symbols->string
(map
(lambda (input)
(if (memq input valid-inputs) input #f)) inputs)) "\n"))
;; UNIT and SPEED are arguments to the same GRUB command
;; ("serial"), so we process them together.
(if (or unit speed)
(string-append
"serial"
(if unit
;; COM ports 1 through 4
(if (and (exact-integer? unit) (<= unit 3) (>= unit 0))
(string-append " --unit=" (number->string unit))
#f)
"")
(if speed
(if (exact-integer? speed)
(string-append " --speed=" (number->string speed))
#f)
""))
""))))
(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
code."
;; 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)))
""
(match device
;; Preferably refer to DEVICE by its UUID or label. This is more
;; efficient and less ambiguous, see <http://bugs.gnu.org/22281>.
2017-09-06 03:28:28 -04:00
((? uuid? uuid)
(format #f "search --fs-uuid --set ~a"
(uuid->string device)))
file-systems: Remove 'title' field and add <file-system-label>. The 'title' field was easily overlooked and was an endless source of confusion. Now, the value of the 'device' field is self-contained. * gnu/system/file-systems.scm (<file-system>): Change constructor name to '%file-system'. [title]: Remove. (<file-system-label>): New record type with printer. (report-deprecation, device-expression) (process-file-system-declaration, file-system): New macros. (file-system-title): New procedure. (file-system->spec, spec->file-system): Adjust to handle <file-system-label>. * gnu/system.scm (bootable-kernel-arguments): Add case for 'file-system-label?'. (read-boot-parameters): Likewise. (mapped-device-user): Avoid 'file-system-title'. (fs->boot-device): Remove. (operating-system-boot-parameters): Use 'file-system-device' instead of 'fs->boot-device'. (device->sexp): Add case for 'file-system-label?'. * gnu/bootloader/grub.scm (grub-root-search): Add case for 'file-system-label?'. * gnu/system/examples/bare-bones.tmpl, gnu/system/examples/beaglebone-black.tmpl, gnu/system/examples/lightweight-desktop.tmpl, gnu/system/examples/vm-image.tmpl: Remove uses of 'title'. * gnu/system/vm.scm (virtualized-operating-system): Remove uses of 'file-system-title'. * guix/scripts/system.scm (check-file-system-availability): Likewise, and adjust fix-it hint. (check-initrd-modules)[file-system-/dev]: Likewise. * gnu/build/file-systems.scm (canonicalize-device-spec): Remove 'title' parameter. [canonical-title]: Remove. Match on SPEC's type rather than on CANONICAL-TITLE. (mount-file-system): Adjust caller. * gnu/build/linux-boot.scm (boot-system): Interpret ROOT here. * gnu/services/base.scm (file-system->fstab-entry): Remove use of 'file-system-title'. * doc/guix.texi (File Systems): Remove documentation of the 'title' field. Rewrite documentation of 'device' and document 'file-system-label'.
2018-05-18 07:43:07 -04:00
((? file-system-label? label)
(format #f "search --label --set ~a"
(file-system-label->string label)))
((or #f (? string?))
#~(format #f "search --file --set ~a" #$file)))))
(define* (grub-configuration-file config entries
#:key
(system (%current-system))
(old-entries '())
btrfs-subvolume-file-name)
"Return the GRUB configuration file corresponding to CONFIG, a
<bootloader-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.
BTRFS-SUBVOLUME-FILE-NAME may be used to specify on which subvolume a
Btrfs root file system resides."
(define all-entries
(append entries (bootloader-configuration-menu-entries config)))
(define (menu-entry->gexp entry)
(let* ((device (menu-entry-device entry))
(device-mount-point (menu-entry-device-mount-point entry))
(label (menu-entry-label entry))
(arguments (menu-entry-linux-arguments entry))
(kernel (normalize-file (menu-entry-linux entry)
device-mount-point
btrfs-subvolume-file-name))
(initrd (normalize-file (menu-entry-initrd entry)
device-mount-point
btrfs-subvolume-file-name)))
;; Here DEVICE is the store and DEVICE-MOUNT-POINT is its mount point.
;; Use the right file names for KERNEL and INITRD in case
;; DEVICE-MOUNT-POINT is not "/", meaning that the store is on a
;; separate partition.
;; When BTRFS-SUBVOLUME-FILE-NAME is defined, prepend it the kernel and
;; initrd paths, to allow booting from a Btrfs subvolume.
#~(format port "menuentry ~s {
~a
linux ~a ~a
initrd ~a
}~%"
#$label
#$(grub-root-search device kernel)
#$kernel (string-join (list #$@arguments))
#$initrd)))
(define sugar
(eye-candy config
(menu-entry-device (first all-entries))
(menu-entry-device-mount-point (first all-entries))
#:btrfs-store-subvolume-file-name btrfs-subvolume-file-name
#:system system
#:port #~port))
(define keyboard-layout-config
(let* ((layout (bootloader-configuration-keyboard-layout config))
(grub (bootloader-package
(bootloader-configuration-bootloader config)))
(keymap* (and layout
(keyboard-layout-file layout #:grub grub)))
(keymap (and keymap*
(if btrfs-subvolume-file-name
#~(string-append #$btrfs-subvolume-file-name
#$keymap*)
keymap*))))
#~(when #$keymap
(format port "\
insmod keylayouts
keymap ~a~%" #$keymap))))
(define builder
#~(call-with-output-file #$output
(lambda (port)
(format port
Remove traces of "GuixSD". * gnu/bootloader/extlinux.scm (extlinux-configuration-file): Remove mentions of "GuixSD". * gnu/bootloader/grub.scm (install-grub-efi): Likewise. * gnu/build/vm.scm (make-iso9660-image): Change default #:volume-id to "Guix_image". (initialize-hard-disk): Search for the "Guix_image" label. * gnu/ci.scm (system-test-jobs, tarball-jobs): Remove "GuixSD". * gnu/installer/newt/welcome.scm (run-welcome-page): Likewise. * gnu/packages/audio.scm (supercollider)[description]: Likewise. * gnu/packages/curl.scm (curl): Likewise. * gnu/packages/emacs.scm (emacs): Likewise. * gnu/packages/gnome.scm (network-manager): Likewise. * gnu/packages/julia.scm (julia): Likewise. * gnu/packages/linux.scm (alsa-plugins): Likewise. (powertop, wireless-regdb): Likewise. * gnu/packages/package-management.scm (guix): Likewise. * gnu/packages/polkit.scm (polkit): Likewise. * gnu/packages/tex.scm (texlive-bin): Likewise. * gnu/services/base.scm (file-systems->fstab): Likewise. * gnu/services/cups.scm (%cups-activation): Likewise. * gnu/services/mail.scm (%dovecot-activation): Likewise. * gnu/services/messaging.scm (prosody-configuration)[log]: Likewise. * gnu/system/examples/vm-image.tmpl (vm-image-motd): Likewise. * gnu/system/install.scm (installation-os)[file-systems]: Change root file system label to "Guix_image". * gnu/system/mapped-devices.scm (check-device-initrd-modules): Remove "GuixSD". * gnu/system/vm.scm (system-docker-image): Likewise. (system-disk-image)[root-label]: Change to "Guix_image". * gnu/tests/install.scm (run-install): Remove "GuixSD". * guix/modules.scm (guix-module-name?): Likewise. * nix/libstore/optimise-store.cc: Likewise.
2019-03-13 11:44:02 -04:00
"# This file was generated from your Guix configuration. Any changes
# will be lost upon reconfiguration.
")
#$sugar
#$keyboard-layout-config
(format port "
set default=~a
set timeout=~a~%"
#$(bootloader-configuration-default-entry config)
#$(bootloader-configuration-timeout config))
#$@(map menu-entry->gexp all-entries)
#$@(if (pair? old-entries)
#~((format port "
submenu \"GNU system, old configurations...\" {~%")
#$@(map menu-entry->gexp old-entries)
(format port "}~%"))
#~())
(format port "
if [ \"${grub_platform}\" == efi ]; then
menuentry \"Firmware setup\" {
fwsetup
}
fi~%"))))
;; Since this file is rather unique, there's no point in trying to
;; substitute it.
(computed-file "grub.cfg" builder
#:options '(#:local-build? #t
#:substitutable? #f)))
;;;
;;; Install procedures.
;;;
(define install-grub
#~(lambda (bootloader device mount-point)
;; Install GRUB on DEVICE which is mounted at MOUNT-POINT.
(let ((grub (string-append bootloader "/sbin/grub-install"))
(install-dir (string-append mount-point "/boot")))
;; Tell 'grub-install' that there might be a LUKS-encrypted /boot or
;; root partition.
(setenv "GRUB_ENABLE_CRYPTODISK" "y")
;; Hide potentially confusing messages from the user, such as
;; "Installing for i386-pc platform."
(invoke/quiet grub "--no-floppy" "--target=i386-pc"
"--boot-directory" install-dir
device))))
(define install-grub-efi
#~(lambda (bootloader efi-dir mount-point)
;; Install GRUB onto the EFI partition mounted at EFI-DIR, for the
;; system whose root is mounted at MOUNT-POINT.
(let ((grub-install (string-append bootloader "/sbin/grub-install"))
(install-dir (string-append mount-point "/boot"))
Remove traces of "GuixSD". * gnu/bootloader/extlinux.scm (extlinux-configuration-file): Remove mentions of "GuixSD". * gnu/bootloader/grub.scm (install-grub-efi): Likewise. * gnu/build/vm.scm (make-iso9660-image): Change default #:volume-id to "Guix_image". (initialize-hard-disk): Search for the "Guix_image" label. * gnu/ci.scm (system-test-jobs, tarball-jobs): Remove "GuixSD". * gnu/installer/newt/welcome.scm (run-welcome-page): Likewise. * gnu/packages/audio.scm (supercollider)[description]: Likewise. * gnu/packages/curl.scm (curl): Likewise. * gnu/packages/emacs.scm (emacs): Likewise. * gnu/packages/gnome.scm (network-manager): Likewise. * gnu/packages/julia.scm (julia): Likewise. * gnu/packages/linux.scm (alsa-plugins): Likewise. (powertop, wireless-regdb): Likewise. * gnu/packages/package-management.scm (guix): Likewise. * gnu/packages/polkit.scm (polkit): Likewise. * gnu/packages/tex.scm (texlive-bin): Likewise. * gnu/services/base.scm (file-systems->fstab): Likewise. * gnu/services/cups.scm (%cups-activation): Likewise. * gnu/services/mail.scm (%dovecot-activation): Likewise. * gnu/services/messaging.scm (prosody-configuration)[log]: Likewise. * gnu/system/examples/vm-image.tmpl (vm-image-motd): Likewise. * gnu/system/install.scm (installation-os)[file-systems]: Change root file system label to "Guix_image". * gnu/system/mapped-devices.scm (check-device-initrd-modules): Remove "GuixSD". * gnu/system/vm.scm (system-docker-image): Likewise. (system-disk-image)[root-label]: Change to "Guix_image". * gnu/tests/install.scm (run-install): Remove "GuixSD". * guix/modules.scm (guix-module-name?): Likewise. * nix/libstore/optimise-store.cc: Likewise.
2019-03-13 11:44:02 -04:00
;; When installing Guix, it's common to mount EFI-DIR below
;; MOUNT-POINT rather than /boot/efi on the live image.
(target-esp (if (file-exists? (string-append mount-point efi-dir))
(string-append mount-point efi-dir)
efi-dir)))
;; Tell 'grub-install' that there might be a LUKS-encrypted /boot or
;; root partition.
(setenv "GRUB_ENABLE_CRYPTODISK" "y")
(invoke/quiet grub-install "--boot-directory" install-dir
"--bootloader-id=Guix"
"--efi-directory" target-esp))))
;;;
;;; Bootloader definitions.
;;;
(define grub-bootloader
(bootloader
(name 'grub)
(package grub)
(installer install-grub)
(configuration-file "/boot/grub/grub.cfg")
(configuration-file-generator grub-configuration-file)))
(define grub-minimal-bootloader
(bootloader
(name 'grub)
(package grub-minimal)
(installer install-grub)
(configuration-file "/boot/grub/grub.cfg")
(configuration-file-generator grub-configuration-file)))
(define* grub-efi-bootloader
(bootloader
(inherit grub-bootloader)
(installer install-grub-efi)
(name 'grub-efi)
(package grub-efi)))
(define* grub-mkrescue-bootloader
(bootloader
(inherit grub-efi-bootloader)
(package grub-hybrid)))
;;;
;;; Compatibility macros.
;;;
(define-syntax grub-configuration
(syntax-rules (grub)
((_ (grub package) fields ...)
(if (eq? package grub)
(bootloader-configuration
(bootloader grub-bootloader)
fields ...)
(bootloader-configuration
(bootloader grub-efi-bootloader)
fields ...)))
((_ fields ...)
(bootloader-configuration
(bootloader grub-bootloader)
fields ...))))
;;; grub.scm ends here