summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorBenjamin Staffin <benley@gmail.com>2017-06-10 09:53:24 -0400
committerGitHub <noreply@github.com>2017-06-10 09:53:24 -0400
commit700e22f7bf8ca96741c2eb8fe13cf15bc6e67daa (patch)
treec78c04a01f89884227e99f13d004f2d0a8fc3042 /nixos
parent1fe951816c144a8ed3a900357c539e28818f8b41 (diff)
downloadnixpkgs-700e22f7bf8ca96741c2eb8fe13cf15bc6e67daa.tar
nixpkgs-700e22f7bf8ca96741c2eb8fe13cf15bc6e67daa.tar.gz
nixpkgs-700e22f7bf8ca96741c2eb8fe13cf15bc6e67daa.tar.bz2
nixpkgs-700e22f7bf8ca96741c2eb8fe13cf15bc6e67daa.tar.lz
nixpkgs-700e22f7bf8ca96741c2eb8fe13cf15bc6e67daa.tar.xz
nixpkgs-700e22f7bf8ca96741c2eb8fe13cf15bc6e67daa.tar.zst
nixpkgs-700e22f7bf8ca96741c2eb8fe13cf15bc6e67daa.zip
nixos: Add support for scalable fonts in Grub menus (#26227)
The default font is unreadably small on some hidpi displays. This
makes it possible to specify a TrueType or OpenType font at any point
size, and it will automatically be converted to the format the Grub
uses.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/system/boot/loader/grub/grub.nix30
-rw-r--r--nixos/modules/system/boot/loader/grub/install-grub.pl6
2 files changed, 34 insertions, 2 deletions
diff --git a/nixos/modules/system/boot/loader/grub/grub.nix b/nixos/modules/system/boot/loader/grub/grub.nix
index cf47aed9fa9..1681439a728 100644
--- a/nixos/modules/system/boot/loader/grub/grub.nix
+++ b/nixos/modules/system/boot/loader/grub/grub.nix
@@ -64,11 +64,21 @@ let
       )) + ":" + (makeSearchPathOutput "bin" "sbin" [
         pkgs.mdadm pkgs.utillinux
       ]);
+      font = if lib.last (lib.splitString "." cfg.font) == "pf2"
+             then cfg.font
+             else "${convertedFont}";
     });
 
   bootDeviceCounters = fold (device: attr: attr // { "${device}" = (attr."${device}" or 0) + 1; }) {}
     (concatMap (args: args.devices) cfg.mirroredBoots);
 
+  convertedFont = (pkgs.runCommand "grub-font-converted.pf2" {}
+           (builtins.concatStringsSep " "
+             ([ "${realGrub}/bin/grub-mkfont"
+               cfg.font
+               "--output" "$out"
+             ] ++ (optional (cfg.fontSize!=null) "--size ${toString cfg.fontSize}")))
+         );
 in
 
 {
@@ -276,7 +286,7 @@ in
       extraInitrd = mkOption {
         type = types.nullOr types.path;
         default = null;
-        example = "/boot/extra_initrafms.gz";
+        example = "/boot/extra_initramfs.gz";
         description = ''
           The path to a second initramfs to be supplied to the kernel.
           This ramfs will not be copied to the store, so that it can
@@ -305,6 +315,24 @@ in
         '';
       };
 
+      font = mkOption {
+        type = types.nullOr types.path;
+        default = "${realGrub}/share/grub/unicode.pf2";
+        description = ''
+          Path to a TrueType, OpenType, or pf2 font to be used by Grub.
+        '';
+      };
+
+      fontSize = mkOption {
+        type = types.nullOr types.int;
+        example = literalExample 16;
+        default = null;
+        description = ''
+          Font size for the grub menu. Ignored unless <literal>font</literal>
+          is set to a ttf or otf font.
+        '';
+      };
+
       gfxmodeEfi = mkOption {
         default = "auto";
         example = "1024x768";
diff --git a/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixos/modules/system/boot/loader/grub/install-grub.pl
index 5fcac5c8c6a..1edb9e0d229 100644
--- a/nixos/modules/system/boot/loader/grub/install-grub.pl
+++ b/nixos/modules/system/boot/loader/grub/install-grub.pl
@@ -67,6 +67,7 @@ my $gfxmodeEfi = get("gfxmodeEfi");
 my $gfxmodeBios = get("gfxmodeBios");
 my $bootloaderId = get("bootloaderId");
 my $forceInstall = get("forceInstall");
+my $font = get("font");
 $ENV{'PATH'} = get("path");
 
 die "unsupported GRUB version\n" if $grubVersion != 1 && $grubVersion != 2;
@@ -281,7 +282,7 @@ else {
           insmod vbe
         fi
         insmod font
-        if loadfont " . $grubBoot->path . "/grub/fonts/unicode.pf2; then
+        if loadfont " . $grubBoot->path . "/converted-font.pf2; then
           insmod gfxterm
           if [ \"\${grub_platform}\" = \"efi\" ]; then
             set gfxmode=$gfxmodeEfi
@@ -294,6 +295,9 @@ else {
         fi
     ";
 
+    if ($font) {
+        copy $font, "$bootPath/converted-font.pf2" or die "cannot copy $font to $bootPath\n";
+    }
     if ($splashImage) {
         # FIXME: GRUB 1.97 doesn't resize the background image if it
         # doesn't match the video resolution.