@@ -502,6 +502,14 @@ my $efiDiffer = ($efiTarget eq \$prevGrubState->efi);
502502my $efiMountPointDiffer = ($efiSysMountPoint eq \$prevGrubState->efiMountPoint);
503503my $requireNewInstall = $devicesDiffer || $versionDiffer || $efiDiffer || $efiMountPointDiffer || (($ENV{'NIXOS_INSTALL_GRUB'} // "") eq "1");
504504
505+# install a symlink so that grub can detect the boot drive when set
506+# as the root directory
507+if (! -l "$bootPath/boot") {
508+ if (-e "$bootPath/boot") {
509+ unlink "$bootPath/boot";
510+ }
511+ symlink ".", "$bootPath/boot";
512+}
505513
506514# install non-EFI GRUB
507515if (($requireNewInstall != 0) && ($efiTarget eq "no" || $efiTarget eq "both")) {
@@ -509,10 +517,10 @@ if (($requireNewInstall != 0) && ($efiTarget eq "no" || $efiTarget eq "both")) {
509517 next if $dev eq "nodev";
510518 print STDERR "installing the GRUB $grubVersion boot loader on $dev...\n";
511519 if ($grubTarget eq "") {
512− system("$grub/sbin/grub-install", "--recheck", "--boot-directory=$bootPath", Cwd::abs_path($dev)) == 0
520+ system("$grub/sbin/grub-install", "--recheck", "--root-directory=$bootPath", Cwd::abs_path($dev)) == 0
513521 or die "$0: installation of GRUB on $dev failed\n";
514522 } else {
515− system("$grub/sbin/grub-install", "--recheck", "--boot-directory=$bootPath", "--target=$grubTarget", Cwd::abs_path($dev)) == 0
523+ system("$grub/sbin/grub-install", "--recheck", "--root-directory=$bootPath", "--target=$grubTarget", Cwd::abs_path($dev)) == 0
516524 or die "$0: installation of GRUB on $dev failed\n";
517525 }
518526 }