From c867c6d17288a604d08e313092d0db7c19f11d60 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Wed, 8 Mar 2023 14:24:37 -0500 Subject: [PATCH] nixos/grub: Insert required image modules for themes With a limited testing of all packaged GRUB 2 themes (pkgs.nixos-grub2-theme) this is tested to work. Without this change, the theme loading will error out (waiting for a key press). With this change, the theme loads and works as expected. --- .../system/boot/loader/grub/install-grub.pl | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixos/modules/system/boot/loader/grub/install-grub.pl index 93ad3f1ed706..a84e374624d1 100644 --- a/nixos/modules/system/boot/loader/grub/install-grub.pl +++ b/nixos/modules/system/boot/loader/grub/install-grub.pl @@ -385,6 +385,31 @@ rmtree("$bootPath/theme") or die "cannot clean up theme folder in $bootPath\n" i if ($theme) { # Copy theme rcopy($theme, "$bootPath/theme") or die "cannot copy $theme to $bootPath\n"; + + # Detect which modules will need to be loaded + my $with_png = 0; + my $with_jpeg = 0; + + find({ wanted => sub { + if ($_ =~ /\.png$/i) { + $with_png = 1; + } + elsif ($_ =~ /\.jpe?g$/i) { + $with_jpeg = 1; + } + }, no_chdir => 1 }, $theme); + + if ($with_png) { + $conf .= " + insmod png + " + } + if ($with_jpeg) { + $conf .= " + insmod jpeg + " + } + $conf .= " # Sets theme. set theme=" . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/theme/theme.txt