diff --git a/nixos/modules/system/boot/loader/limine/limine-install.py b/nixos/modules/system/boot/loader/limine/limine-install.py index 4c9db91ad65d..ea9d2c46d0ae 100644 --- a/nixos/modules/system/boot/loader/limine/limine-install.py +++ b/nixos/modules/system/boot/loader/limine/limine-install.py @@ -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([