nixos/systemd-boot: Re-add the verison check, but as equivalence-only

This commit is contained in:
Josh Robson Chase 2021-10-12 09:46:54 -04:00
parent 71ed9d096e
commit 4ddc78818e
No known key found for this signature in database
GPG key ID: 32A347137755554F
2 changed files with 22 additions and 8 deletions

View file

@ -214,13 +214,27 @@ def main() -> None:
subprocess.check_call(["@systemd@/bin/bootctl", "--path=@efiSysMountPoint@", "--no-variables", "install"]) subprocess.check_call(["@systemd@/bin/bootctl", "--path=@efiSysMountPoint@", "--no-variables", "install"])
else: else:
# Update bootloader to latest if needed # Update bootloader to latest if needed
update_output = subprocess.run(["@systemd@/bin/bootctl", "--path=@efiSysMountPoint@", "update", "--graceful"], systemd_version = subprocess.check_output(["@systemd@/bin/bootctl", "--version"], universal_newlines=True).split()[1]
universal_newlines=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr sdboot_status = subprocess.check_output(["@systemd@/bin/bootctl", "--path=@efiSysMountPoint@", "status"], universal_newlines=True)
updated = re.search("^Copied \"/nix/store/.*-systemd-(.*)/lib/systemd/boot/efi/.*\.efi\" to \"/boot/EFI/.*\.efi\"\.$",
update_output, re.MULTILINE) # See status_binaries() in systemd bootctl.c for code which generates this
if updated: m = re.search("^\W+File:.*/EFI/(BOOT|systemd)/.*\.efi \(systemd-boot ([\d.]+[^)]*)\)$",
systemd_version = updated.group(1) sdboot_status, re.IGNORECASE | re.MULTILINE)
print(f"updated systemd-boot to {systemd_version}")
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@/efi/nixos")
mkdir_p("@efiSysMountPoint@/loader/entries") mkdir_p("@efiSysMountPoint@/loader/entries")

View file

@ -84,7 +84,7 @@ in
) )
output = machine.succeed("/run/current-system/bin/switch-to-configuration boot") output = machine.succeed("/run/current-system/bin/switch-to-configuration boot")
assert "updated systemd-boot to " in output assert "updating systemd-boot from 000.0-1-notnixos to " in output
''; '';
}; };
} }