nixos/limine: avoid rewriting boot order on update

efibootmgr rejects -o when BootOrder contains IDs without corresponding BootXXXX variables (which can come from certain BIOS implementations).

Fix by recreating Limine entry at previous position using -c --index, or use -C if Limine was not in BootOrder.

(cherry picked from commit 4dd37d80c3)
This commit is contained in:
Hao Ren Zhou
2026-07-24 16:43:25 +08:00
committed by haoren-zhou
parent cc27d2abca
commit d9324653dc

View File

@@ -603,6 +603,14 @@ def install_bootloader() -> None:
# If there's already a Limine entry, replace it
if limine_boot_entry:
boot_order = re.findall(r'BootOrder: ((?:[0-9a-fA-F]{4},?)*)', efibootmgr_output)[0]
normalized_boot_order = boot_order.upper().split(',')
create_options = ['-C']
if limine_boot_entry.upper() in normalized_boot_order:
create_options = [
'-c',
'--index',
str(normalized_boot_order.index(limine_boot_entry.upper())),
]
efibootmgr_output = subprocess.check_output([
efibootmgr,
@@ -612,13 +620,12 @@ def install_bootloader() -> None:
efibootmgr_output = subprocess.check_output([
efibootmgr,
'-c',
*create_options,
'-b', limine_boot_entry,
'-d', efi_disk,
'-p', efi_partition.removeprefix(efi_disk).removeprefix('p'),
'-l', f'\\efi\\limine\\{boot_file}',
'-L', 'Limine',
'-o', boot_order,
], stderr=subprocess.STDOUT, universal_newlines=True)
else:
efibootmgr_output = subprocess.check_output([