Skip to content

Commit 700e22f

Browse files
authoredJun 10, 2017
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.
1 parent 1fe9518 commit 700e22f

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed
 

‎nixos/modules/system/boot/loader/grub/grub.nix

+29-1
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,21 @@ let
6464
)) + ":" + (makeSearchPathOutput "bin" "sbin" [
6565
pkgs.mdadm pkgs.utillinux
6666
]);
67+
font = if lib.last (lib.splitString "." cfg.font) == "pf2"
68+
then cfg.font
69+
else "${convertedFont}";
6770
});
6871

6972
bootDeviceCounters = fold (device: attr: attr // { "${device}" = (attr."${device}" or 0) + 1; }) {}
7073
(concatMap (args: args.devices) cfg.mirroredBoots);
7174

75+
convertedFont = (pkgs.runCommand "grub-font-converted.pf2" {}
76+
(builtins.concatStringsSep " "
77+
([ "${realGrub}/bin/grub-mkfont"
78+
cfg.font
79+
"--output" "$out"
80+
] ++ (optional (cfg.fontSize!=null) "--size ${toString cfg.fontSize}")))
81+
);
7282
in
7383

7484
{
@@ -276,7 +286,7 @@ in
276286
extraInitrd = mkOption {
277287
type = types.nullOr types.path;
278288
default = null;
279-
example = "/boot/extra_initrafms.gz";
289+
example = "/boot/extra_initramfs.gz";
280290
description = ''
281291
The path to a second initramfs to be supplied to the kernel.
282292
This ramfs will not be copied to the store, so that it can
@@ -305,6 +315,24 @@ in
305315
'';
306316
};
307317

318+
font = mkOption {
319+
type = types.nullOr types.path;
320+
default = "${realGrub}/share/grub/unicode.pf2";
321+
description = ''
322+
Path to a TrueType, OpenType, or pf2 font to be used by Grub.
323+
'';
324+
};
325+
326+
fontSize = mkOption {
327+
type = types.nullOr types.int;
328+
example = literalExample 16;
329+
default = null;
330+
description = ''
331+
Font size for the grub menu. Ignored unless <literal>font</literal>
332+
is set to a ttf or otf font.
333+
'';
334+
};
335+
308336
gfxmodeEfi = mkOption {
309337
default = "auto";
310338
example = "1024x768";

‎nixos/modules/system/boot/loader/grub/install-grub.pl

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ sub runCommand {
6767
my $gfxmodeBios = get("gfxmodeBios");
6868
my $bootloaderId = get("bootloaderId");
6969
my $forceInstall = get("forceInstall");
70+
my $font = get("font");
7071
$ENV{'PATH'} = get("path");
7172

7273
die "unsupported GRUB version\n" if $grubVersion != 1 && $grubVersion != 2;
@@ -281,7 +282,7 @@ sub GrubFs {
281282
insmod vbe
282283
fi
283284
insmod font
284-
if loadfont " . $grubBoot->path . "/grub/fonts/unicode.pf2; then
285+
if loadfont " . $grubBoot->path . "/converted-font.pf2; then
285286
insmod gfxterm
286287
if [ \"\${grub_platform}\" = \"efi\" ]; then
287288
set gfxmode=$gfxmodeEfi
@@ -294,6 +295,9 @@ sub GrubFs {
294295
fi
295296
";
296297

298+
if ($font) {
299+
copy $font, "$bootPath/converted-font.pf2" or die "cannot copy $font to $bootPath\n";
300+
}
297301
if ($splashImage) {
298302
# FIXME: GRUB 1.97 doesn't resize the background image if it
299303
# doesn't match the video resolution.

0 commit comments

Comments
 (0)
Please sign in to comment.