diff options
author | Thomas Watson <twatson52@icloud.com> | 2023-01-16 15:31:52 -0600 |
---|---|---|
committer | Thomas Watson <twatson52@icloud.com> | 2023-01-19 23:52:57 -0600 |
commit | 8f2babd0326e57dc01a22bdccec376dcc7ca3ed3 (patch) | |
tree | 8329df09027e117b6c705de462d64888fc0078fc /nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py | |
parent | ddc5d34f6126c7029d6aa876eac29e2aed0ee0e4 (diff) |
nixos/systemd-boot: pass EFI variable flags during update too
On some systems, EFI variables are not supported or otherwise wonky. bootctl attempting to access them causes failures during bootloader installations and updates. For such systems, NixOS provides the options `boot.loader.efi.canTouchEfiVariables` and `boot.loader.systemd-boot.graceful` which pass flags to bootctl that change whether and how EFI variables are accessed. Previously, these flags were only passed to bootctl during an install operation. However, they also apply during an update operation, which can cause the same sorts of errors. This change passes the flags during update operations as well to prevent those errors. Fixes https://github.com/NixOS/nixpkgs/issues/151336
Diffstat (limited to 'nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py')
-rwxr-xr-x | nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py | 21 |
1 files changed, 11 insertions, 10 deletions
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 ea3577f138c29..db64676379741 100755 --- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py +++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py @@ -228,20 +228,21 @@ def main() -> None: warnings.warn("NIXOS_INSTALL_GRUB env var deprecated, use NIXOS_INSTALL_BOOTLOADER", DeprecationWarning) os.environ["NIXOS_INSTALL_BOOTLOADER"] = "1" + # flags to pass to bootctl install/update + bootctl_flags = [] + + if "@canTouchEfiVariables@" != "1": + bootctl_flags.append("--no-variables") + + if "@graceful@" == "1": + bootctl_flags.append("--graceful") + if os.getenv("NIXOS_INSTALL_BOOTLOADER") == "1": # bootctl uses fopen() with modes "wxe" and fails if the file exists. if os.path.exists("@efiSysMountPoint@/loader/loader.conf"): os.unlink("@efiSysMountPoint@/loader/loader.conf") - flags = [] - - if "@canTouchEfiVariables@" != "1": - flags.append("--no-variables") - - if "@graceful@" == "1": - flags.append("--graceful") - - subprocess.check_call(["@systemd@/bin/bootctl", "--esp-path=@efiSysMountPoint@"] + flags + ["install"]) + subprocess.check_call(["@systemd@/bin/bootctl", "--esp-path=@efiSysMountPoint@"] + bootctl_flags + ["install"]) else: # Update bootloader to latest if needed available_out = subprocess.check_output(["@systemd@/bin/bootctl", "--version"], universal_newlines=True).split()[2] @@ -270,7 +271,7 @@ def main() -> None: print("skipping systemd-boot update to %s because of known regression" % available_version) else: print("updating systemd-boot from %s to %s" % (installed_version, available_version)) - subprocess.check_call(["@systemd@/bin/bootctl", "--esp-path=@efiSysMountPoint@", "update"]) + subprocess.check_call(["@systemd@/bin/bootctl", "--esp-path=@efiSysMountPoint@"] + bootctl_flags + ["update"]) mkdir_p("@efiSysMountPoint@/efi/nixos") mkdir_p("@efiSysMountPoint@/loader/entries") |