From 4ddc78818e4d69605f49f5f8faa22fb4601b0a0c Mon Sep 17 00:00:00 2001 From: Josh Robson Chase Date: Tue, 12 Oct 2021 09:46:54 -0400 Subject: nixos/systemd-boot: Re-add the verison check, but as equivalence-only --- .../loader/systemd-boot/systemd-boot-builder.py | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'nixos/modules/system/boot/loader/systemd-boot') diff --git a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py index 588016fe526..aa59c08119d 100644 --- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py +++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py @@ -214,13 +214,27 @@ def main() -> None: subprocess.check_call(["@systemd@/bin/bootctl", "--path=@efiSysMountPoint@", "--no-variables", "install"]) else: # Update bootloader to latest if needed - update_output = subprocess.run(["@systemd@/bin/bootctl", "--path=@efiSysMountPoint@", "update", "--graceful"], - universal_newlines=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr - updated = re.search("^Copied \"/nix/store/.*-systemd-(.*)/lib/systemd/boot/efi/.*\.efi\" to \"/boot/EFI/.*\.efi\"\.$", - update_output, re.MULTILINE) - if updated: - systemd_version = updated.group(1) - print(f"updated systemd-boot to {systemd_version}") + systemd_version = subprocess.check_output(["@systemd@/bin/bootctl", "--version"], universal_newlines=True).split()[1] + sdboot_status = subprocess.check_output(["@systemd@/bin/bootctl", "--path=@efiSysMountPoint@", "status"], universal_newlines=True) + + # See status_binaries() in systemd bootctl.c for code which generates this + m = re.search("^\W+File:.*/EFI/(BOOT|systemd)/.*\.efi \(systemd-boot ([\d.]+[^)]*)\)$", + sdboot_status, re.IGNORECASE | re.MULTILINE) + + needs_install = False + + if m is None: + print("could not find any previously installed systemd-boot, installing.") + # Let systemd-boot attempt an installation if a previous one wasn't found + needs_install = True + else: + sdboot_version = m.group(2) + if systemd_version != sdboot_version: + print("updating systemd-boot from %s to %s" % (sdboot_version, systemd_version)) + needs_install = True + + if needs_install: + subprocess.check_call(["@systemd@/bin/bootctl", "--path=@efiSysMountPoint@", "update"]) mkdir_p("@efiSysMountPoint@/efi/nixos") mkdir_p("@efiSysMountPoint@/loader/entries") -- cgit 1.4.1