Skip to content

Commit a6665ad

Browse files
symphorienglobin
authored andcommittedMar 23, 2017
grub module: fix useOSProber when installing grub as EFI
1 parent 29a2978 commit a6665ad

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed
 

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

+32-30
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,40 @@ sub addProfile {
443443
my $tmpFile = $confFile . ".tmp";
444444
writeFile($tmpFile, $conf);
445445

446+
447+
# check whether to install GRUB EFI or not
448+
sub getEfiTarget {
449+
if ($grubVersion == 1) {
450+
return "no"
451+
} elsif (($grub ne "") && ($grubEfi ne "")) {
452+
# EFI can only be installed when target is set;
453+
# A target is also required then for non-EFI grub
454+
if (($grubTarget eq "") || ($grubTargetEfi eq "")) { die }
455+
else { return "both" }
456+
} elsif (($grub ne "") && ($grubEfi eq "")) {
457+
# TODO: It would be safer to disallow non-EFI grub installation if no taget is given.
458+
# If no target is given, then grub auto-detects the target which can lead to errors.
459+
# E.g. it seems as if grub would auto-detect a EFI target based on the availability
460+
# of a EFI partition.
461+
# However, it seems as auto-detection is currently relied on for non-x86_64 and non-i386
462+
# architectures in NixOS. That would have to be fixed in the nixos modules first.
463+
return "no"
464+
} elsif (($grub eq "") && ($grubEfi ne "")) {
465+
# EFI can only be installed when target is set;
466+
if ($grubTargetEfi eq "") { die }
467+
else {return "only" }
468+
} else {
469+
# prevent an installation if neither grub nor grubEfi is given
470+
return "neither"
471+
}
472+
}
473+
474+
my $efiTarget = getEfiTarget();
475+
446476
# Append entries detected by os-prober
447477
if (get("useOSProber") eq "true") {
448-
system(get("shell"), "-c", "pkgdatadir=$grub/share/grub $grub/etc/grub.d/30_os-prober >> $tmpFile");
478+
my $targetpackage = ($efiTarget eq "no") ? $grub : $grubEfi;
479+
system(get("shell"), "-c", "pkgdatadir=$targetpackage/share/grub $targetpackage/etc/grub.d/30_os-prober >> $tmpFile");
449480
}
450481

451482
# Atomically switch to the new config
@@ -498,36 +529,7 @@ sub getDeviceTargets {
498529
}
499530
return @devices;
500531
}
501-
502-
# check whether to install GRUB EFI or not
503-
sub getEfiTarget {
504-
if ($grubVersion == 1) {
505-
return "no"
506-
} elsif (($grub ne "") && ($grubEfi ne "")) {
507-
# EFI can only be installed when target is set;
508-
# A target is also required then for non-EFI grub
509-
if (($grubTarget eq "") || ($grubTargetEfi eq "")) { die }
510-
else { return "both" }
511-
} elsif (($grub ne "") && ($grubEfi eq "")) {
512-
# TODO: It would be safer to disallow non-EFI grub installation if no taget is given.
513-
# If no target is given, then grub auto-detects the target which can lead to errors.
514-
# E.g. it seems as if grub would auto-detect a EFI target based on the availability
515-
# of a EFI partition.
516-
# However, it seems as auto-detection is currently relied on for non-x86_64 and non-i386
517-
# architectures in NixOS. That would have to be fixed in the nixos modules first.
518-
return "no"
519-
} elsif (($grub eq "") && ($grubEfi ne "")) {
520-
# EFI can only be installed when target is set;
521-
if ($grubTargetEfi eq "") { die }
522-
else {return "only" }
523-
} else {
524-
# prevent an installation if neither grub nor grubEfi is given
525-
return "neither"
526-
}
527-
}
528-
529532
my @deviceTargets = getDeviceTargets();
530-
my $efiTarget = getEfiTarget();
531533
my $prevGrubState = readGrubState();
532534
my @prevDeviceTargets = split/,/, $prevGrubState->devices;
533535

0 commit comments

Comments
 (0)
Please sign in to comment.