@@ -443,9 +443,40 @@ sub addProfile {
443
443
my $tmpFile = $confFile . " .tmp" ;
444
444
writeFile($tmpFile , $conf );
445
445
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
+
446
476
# Append entries detected by os-prober
447
477
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 " );
449
480
}
450
481
451
482
# Atomically switch to the new config
@@ -498,36 +529,7 @@ sub getDeviceTargets {
498
529
}
499
530
return @devices ;
500
531
}
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
-
529
532
my @deviceTargets = getDeviceTargets();
530
- my $efiTarget = getEfiTarget();
531
533
my $prevGrubState = readGrubState();
532
534
my @prevDeviceTargets = split /,/, $prevGrubState -> devices;
533
535
0 commit comments