nixos/grub: Adds background color and mode options

The background color option is self-explanatory.

The mode is either `normal` or `stretch`, they are as defined by GRUB,
where normal will put the image in the top-left corner of the menu, and
stretch is the default, where it stretches the image without
consideration for the aspect ratio.

* https://www.gnu.org/software/grub/manual/grub/grub.html#background_005fimage

Changed files
+35 -1
nixos
modules
system
boot
+27
nixos/modules/system/boot/loader/grub/grub.nix
···
in
pkgs.writeText "grub-config.xml" (builtins.toXML
{ splashImage = f cfg.splashImage;
grub = f grub;
grubTarget = f (grub.grubTarget or "");
shell = "${pkgs.runtimeShell}";
···
File must be one of .png, .tga, .jpg, or .jpeg. JPEG images must
not be progressive.
The image will be scaled if necessary to fit the screen.
</para></note>
'';
};
···
in
pkgs.writeText "grub-config.xml" (builtins.toXML
{ splashImage = f cfg.splashImage;
+
splashMode = f cfg.splashMode;
+
backgroundColor = f cfg.backgroundColor;
grub = f grub;
grubTarget = f (grub.grubTarget or "");
shell = "${pkgs.runtimeShell}";
···
File must be one of .png, .tga, .jpg, or .jpeg. JPEG images must
not be progressive.
The image will be scaled if necessary to fit the screen.
+
</para></note>
+
'';
+
};
+
+
backgroundColor = mkOption {
+
type = types.nullOr types.string;
+
example = "#7EBAE4";
+
default = null;
+
description = ''
+
Background color to be used for GRUB to fill the areas the image isn't filling.
+
+
<note><para>
+
This options has no effect for GRUB 1.
+
</para></note>
+
'';
+
};
+
+
splashMode = mkOption {
+
type = types.enum [ "normal" "stretch" ];
+
default = "stretch";
+
description = ''
+
Whether to stretch the image or show the image in the top-left corner unstretched.
+
+
<note><para>
+
This options has no effect for GRUB 1.
</para></note>
'';
};
+8 -1
nixos/modules/system/boot/loader/grub/install-grub.pl
···
my $extraEntriesBeforeNixOS = get("extraEntriesBeforeNixOS") eq "true";
my $extraInitrd = get("extraInitrd");
my $splashImage = get("splashImage");
my $configurationLimit = int(get("configurationLimit"));
my $copyKernels = get("copyKernels") eq "true";
my $timeout = int(get("timeout"));
···
if ($suffix eq ".jpg") {
$suffix = ".jpeg";
}
copy $splashImage, "$bootPath/background$suffix" or die "cannot copy $splashImage to $bootPath\n";
$conf .= "
insmod " . substr($suffix, 1) . "
-
if background_image " . $grubBoot->path . "/background$suffix; then
set color_normal=white/black
set color_highlight=black/white
else
···
my $extraEntriesBeforeNixOS = get("extraEntriesBeforeNixOS") eq "true";
my $extraInitrd = get("extraInitrd");
my $splashImage = get("splashImage");
+
my $splashMode = get("splashMode");
+
my $backgroundColor = get("backgroundColor");
my $configurationLimit = int(get("configurationLimit"));
my $copyKernels = get("copyKernels") eq "true";
my $timeout = int(get("timeout"));
···
if ($suffix eq ".jpg") {
$suffix = ".jpeg";
}
+
if ($backgroundColor) {
+
$conf .= "
+
background_color '$backgroundColor'
+
";
+
}
copy $splashImage, "$bootPath/background$suffix" or die "cannot copy $splashImage to $bootPath\n";
$conf .= "
insmod " . substr($suffix, 1) . "
+
if background_image --mode '$splashMode' " . $grubBoot->path . "/background$suffix; then
set color_normal=white/black
set color_highlight=black/white
else