0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

Merge pull request #113887 from xaverdh/install-grub-editorconfig-fixup

This commit is contained in:
Sandro 2021-11-29 21:03:41 +01:00 committed by GitHub
commit 61c3243dc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -103,10 +103,10 @@ if (stat($bootPath)->dev != stat("/nix/store")->dev) {
# Discover information about the location of the bootPath # Discover information about the location of the bootPath
struct(Fs => { struct(Fs => {
device => '$', device => '$',
type => '$', type => '$',
mount => '$', mount => '$',
}); });
sub PathInMount { sub PathInMount {
my ($path, $mount) = @_; my ($path, $mount) = @_;
my @splitMount = split /\//, $mount; my @splitMount = split /\//, $mount;
@ -155,9 +155,9 @@ sub GetFs {
return $bestFs; return $bestFs;
} }
struct (Grub => { struct (Grub => {
path => '$', path => '$',
search => '$', search => '$',
}); });
my $driveid = 1; my $driveid = 1;
sub GrubFs { sub GrubFs {
my ($dir) = @_; my ($dir) = @_;
@ -254,8 +254,8 @@ if ($grubVersion == 1) {
# $defaultEntry might be "saved", indicating that we want to use the last selected configuration as default. # $defaultEntry might be "saved", indicating that we want to use the last selected configuration as default.
# Incidentally this is already the correct value for the grub 1 config to achieve this behaviour. # Incidentally this is already the correct value for the grub 1 config to achieve this behaviour.
$conf .= " $conf .= "
default $defaultEntry default $defaultEntry
timeout $timeout timeout $timeout
"; ";
if ($splashImage) { if ($splashImage) {
copy $splashImage, "$bootPath/background.xpm.gz" or die "cannot copy $splashImage to $bootPath: $!\n"; copy $splashImage, "$bootPath/background.xpm.gz" or die "cannot copy $splashImage to $bootPath: $!\n";
@ -305,7 +305,7 @@ else {
if ($copyKernels == 0) { if ($copyKernels == 0) {
$conf .= " $conf .= "
" . $grubStore->search; " . $grubStore->search;
} }
# FIXME: should use grub-mkconfig. # FIXME: should use grub-mkconfig.
my $defaultEntryText = $defaultEntry; my $defaultEntryText = $defaultEntry;
@ -313,55 +313,55 @@ else {
$defaultEntryText = "\"\${saved_entry}\""; $defaultEntryText = "\"\${saved_entry}\"";
} }
$conf .= " $conf .= "
" . $grubBoot->search . " " . $grubBoot->search . "
if [ -s \$prefix/grubenv ]; then if [ -s \$prefix/grubenv ]; then
load_env load_env
fi
# grub-reboot sets a one-time saved entry, which we process here and
# then delete.
if [ \"\${next_entry}\" ]; then
set default=\"\${next_entry}\"
set next_entry=
save_env next_entry
set timeout=1
set boot_once=true
else
set default=$defaultEntryText
set timeout=$timeout
fi
function savedefault {
if [ -z \"\${boot_once}\"]; then
saved_entry=\"\${chosen}\"
save_env saved_entry
fi fi
}
# Setup the graphics stack for bios and efi systems # grub-reboot sets a one-time saved entry, which we process here and
if [ \"\${grub_platform}\" = \"efi\" ]; then # then delete.
insmod efi_gop if [ \"\${next_entry}\" ]; then
insmod efi_uga set default=\"\${next_entry}\"
else set next_entry=
insmod vbe save_env next_entry
fi set timeout=1
set boot_once=true
else
set default=$defaultEntryText
set timeout=$timeout
fi
function savedefault {
if [ -z \"\${boot_once}\"]; then
saved_entry=\"\${chosen}\"
save_env saved_entry
fi
}
# Setup the graphics stack for bios and efi systems
if [ \"\${grub_platform}\" = \"efi\" ]; then
insmod efi_gop
insmod efi_uga
else
insmod vbe
fi
"; ";
if ($font) { if ($font) {
copy $font, "$bootPath/converted-font.pf2" or die "cannot copy $font to $bootPath: $!\n"; copy $font, "$bootPath/converted-font.pf2" or die "cannot copy $font to $bootPath: $!\n";
$conf .= " $conf .= "
insmod font insmod font
if loadfont " . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/converted-font.pf2; then if loadfont " . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/converted-font.pf2; then
insmod gfxterm insmod gfxterm
if [ \"\${grub_platform}\" = \"efi\" ]; then if [ \"\${grub_platform}\" = \"efi\" ]; then
set gfxmode=$gfxmodeEfi set gfxmode=$gfxmodeEfi
set gfxpayload=$gfxpayloadEfi set gfxpayload=$gfxpayloadEfi
else else
set gfxmode=$gfxmodeBios set gfxmode=$gfxmodeBios
set gfxpayload=$gfxpayloadBios set gfxpayload=$gfxpayloadBios
fi fi
terminal_output gfxterm terminal_output gfxterm
fi fi
"; ";
} }
if ($splashImage) { if ($splashImage) {
@ -378,14 +378,14 @@ else {
} }
copy $splashImage, "$bootPath/background$suffix" or die "cannot copy $splashImage to $bootPath: $!\n"; copy $splashImage, "$bootPath/background$suffix" or die "cannot copy $splashImage to $bootPath: $!\n";
$conf .= " $conf .= "
insmod " . substr($suffix, 1) . " insmod " . substr($suffix, 1) . "
if background_image --mode '$splashMode' " . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/background$suffix; then if background_image --mode '$splashMode' " . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/background$suffix; then
set color_normal=white/black set color_normal=white/black
set color_highlight=black/white set color_highlight=black/white
else else
set menu_color_normal=cyan/blue set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue set menu_color_highlight=white/blue
fi fi
"; ";
} }
@ -395,20 +395,20 @@ else {
# Copy theme # Copy theme
rcopy($theme, "$bootPath/theme") or die "cannot copy $theme to $bootPath\n"; rcopy($theme, "$bootPath/theme") or die "cannot copy $theme to $bootPath\n";
$conf .= " $conf .= "
# Sets theme. # Sets theme.
set theme=" . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/theme/theme.txt set theme=" . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/theme/theme.txt
export theme export theme
# Load theme fonts, if any # Load theme fonts, if any
"; ";
find( { wanted => sub { find( { wanted => sub {
if ($_ =~ /\.pf2$/i) { if ($_ =~ /\.pf2$/i) {
$font = File::Spec->abs2rel($File::Find::name, $theme); $font = File::Spec->abs2rel($File::Find::name, $theme);
$conf .= " $conf .= "
loadfont " . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/theme/$font loadfont " . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/theme/$font
"; ";
} }
}, no_chdir => 1 }, $theme ); }, no_chdir => 1 }, $theme );
} }
} }
@ -474,8 +474,8 @@ sub addEntry {
# FIXME: $confName # FIXME: $confName
my $kernelParams = my $kernelParams =
"init=" . Cwd::abs_path("$path/init") . " " . "init=" . Cwd::abs_path("$path/init") . " " .
readFile("$path/kernel-params"); readFile("$path/kernel-params");
my $xenParams = $xen && -e "$path/xen-params" ? readFile("$path/xen-params") : ""; my $xenParams = $xen && -e "$path/xen-params" ? readFile("$path/xen-params") : "";
if ($grubVersion == 1) { if ($grubVersion == 1) {
@ -524,9 +524,9 @@ foreach my $link (@links) {
my $date = strftime("%F", localtime(lstat($link)->mtime)); my $date = strftime("%F", localtime(lstat($link)->mtime));
my $version = my $version =
-e "$link/nixos-version" -e "$link/nixos-version"
? readFile("$link/nixos-version") ? readFile("$link/nixos-version")
: basename((glob(dirname(Cwd::abs_path("$link/kernel")) . "/lib/modules/*"))[0]); : basename((glob(dirname(Cwd::abs_path("$link/kernel")) . "/lib/modules/*"))[0]);
if ($cfgName) { if ($cfgName) {
$entryName = $cfgName; $entryName = $cfgName;
@ -551,8 +551,8 @@ sub addProfile {
sub nrFromGen { my ($x) = @_; $x =~ /\/\w+-(\d+)-link/; return $1; } sub nrFromGen { my ($x) = @_; $x =~ /\/\w+-(\d+)-link/; return $1; }
my @links = sort my @links = sort
{ nrFromGen($b) <=> nrFromGen($a) } { nrFromGen($b) <=> nrFromGen($a) }
(glob "$profile-*-link"); (glob "$profile-*-link");
my $curEntry = 0; my $curEntry = 0;
foreach my $link (@links) { foreach my $link (@links) {
@ -563,9 +563,9 @@ sub addProfile {
} }
my $date = strftime("%F", localtime(lstat($link)->mtime)); my $date = strftime("%F", localtime(lstat($link)->mtime));
my $version = my $version =
-e "$link/nixos-version" -e "$link/nixos-version"
? readFile("$link/nixos-version") ? readFile("$link/nixos-version")
: basename((glob(dirname(Cwd::abs_path("$link/kernel")) . "/lib/modules/*"))[0]); : basename((glob(dirname(Cwd::abs_path("$link/kernel")) . "/lib/modules/*"))[0]);
addEntry("NixOS - Configuration " . nrFromGen($link) . " ($date - $version)", $link); addEntry("NixOS - Configuration " . nrFromGen($link) . " ($date - $version)", $link);
} }
@ -653,13 +653,13 @@ foreach my $fn (glob "$bootPath/kernels/*") {
# #
struct(GrubState => { struct(GrubState => {
name => '$', name => '$',
version => '$', version => '$',
efi => '$', efi => '$',
devices => '$', devices => '$',
efiMountPoint => '$', efiMountPoint => '$',
extraGrubInstallArgs => '@', extraGrubInstallArgs => '@',
}); });
# If you add something to the state file, only add it to the end # If you add something to the state file, only add it to the end
# because it is read line-by-line. # because it is read line-by-line.
sub readGrubState { sub readGrubState {