summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiklas Hambüchen <mail@nh2.me>2020-07-07 00:53:55 +0200
committerGitHub <noreply@github.com>2020-07-07 00:53:55 +0200
commite8c1ff9ef8a18ec0bd59aab7b02b2be7019b8235 (patch)
tree390afd2a3f30344442d02d98d10a32114274e7ab
parent11eb84bb9fd92c3dbec7f769339c34c5624e0390 (diff)
downloadnixpkgs-e8c1ff9ef8a18ec0bd59aab7b02b2be7019b8235.tar
nixpkgs-e8c1ff9ef8a18ec0bd59aab7b02b2be7019b8235.tar.gz
nixpkgs-e8c1ff9ef8a18ec0bd59aab7b02b2be7019b8235.tar.bz2
nixpkgs-e8c1ff9ef8a18ec0bd59aab7b02b2be7019b8235.tar.lz
nixpkgs-e8c1ff9ef8a18ec0bd59aab7b02b2be7019b8235.tar.xz
nixpkgs-e8c1ff9ef8a18ec0bd59aab7b02b2be7019b8235.tar.zst
nixpkgs-e8c1ff9ef8a18ec0bd59aab7b02b2be7019b8235.zip
grub: Fix incorrect upgrade to new `jsonStateLine`. See #85895. (#92520)
Fixes error

    Can't use an undefined value as an ARRAY reference at /nix/store/...-install-grub.pl line 642, <FILE> line 5.

with `/boot/grub/state` being:

```
grub
2.04
no
/dev/sda
/boot

```

I am not sure where the trailing empty line can come from; the script does not
seem to write it. In any case, now we handle that situation as well.

Further, ensure that `extraGrubInstallArgs` defaults to the empty array
if its key is not present in the `jsonState`.
-rw-r--r--nixos/modules/system/boot/loader/grub/install-grub.pl5
1 files changed, 4 insertions, 1 deletions
diff --git a/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixos/modules/system/boot/loader/grub/install-grub.pl
index b788e427dff..9af799184b6 100644
--- a/nixos/modules/system/boot/loader/grub/install-grub.pl
+++ b/nixos/modules/system/boot/loader/grub/install-grub.pl
@@ -638,8 +638,11 @@ sub readGrubState {
     # guaranteed to be present.
     $jsonStateLine = defined $jsonStateLine ? $jsonStateLine : '{}'; # empty JSON object
     chomp($jsonStateLine);
+    if ($jsonStateLine eq "") {
+        $jsonStateLine = '{}'; # empty JSON object
+    }
     my %jsonState = %{decode_json($jsonStateLine)};
-    my @extraGrubInstallArgs = @{$jsonState{'extraGrubInstallArgs'}};
+    my @extraGrubInstallArgs = exists($jsonState{'extraGrubInstallArgs'}) ? @{$jsonState{'extraGrubInstallArgs'}} : ();
     close FILE;
     my $grubState = GrubState->new(name => $name, version => $version, efi => $efi, devices => $devices, efiMountPoint => $efiMountPoint, extraGrubInstallArgs => \@extraGrubInstallArgs );
     return $grubState