summary refs log tree commit diff
path: root/nixos/modules/system/boot/loader/systemd-boot
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2017-02-20 14:28:53 +0100
committeraszlig <aszlig@redmoonstudios.org>2017-02-20 14:54:48 +0100
commitdc31a1ea29cae217b71134bf59f888c5a90f630b (patch)
treedd71986a73cec9dd4a141430f69c132f92cd3549 /nixos/modules/system/boot/loader/systemd-boot
parent4daccf208feccb027731d3fc8dc2686ab9ef3428 (diff)
downloadnixpkgs-dc31a1ea29cae217b71134bf59f888c5a90f630b.tar
nixpkgs-dc31a1ea29cae217b71134bf59f888c5a90f630b.tar.gz
nixpkgs-dc31a1ea29cae217b71134bf59f888c5a90f630b.tar.bz2
nixpkgs-dc31a1ea29cae217b71134bf59f888c5a90f630b.tar.lz
nixpkgs-dc31a1ea29cae217b71134bf59f888c5a90f630b.tar.xz
nixpkgs-dc31a1ea29cae217b71134bf59f888c5a90f630b.tar.zst
nixpkgs-dc31a1ea29cae217b71134bf59f888c5a90f630b.zip
systemd-boot: Unlink loader.conf if it exists
Since systemd version 232 the install subcommand of bootctl opens the
loader.conf with fopen() modes "wxe", where the "e" stands for
exclusive, so the call will fail if the file exists.

For installing the boot loader just once this is fine, but if we're
using NIXOS_INSTALL_BOOTLOADER on a systemd where the bootloader is
already present this will fail.

Exactly this is done within the simpleUefiGummiboot installer test,
where nixos-install is called twice and thus the bootloader is also
installed twice, resulting in an error during the fopen call:

Failed to open loader.conf for writing: File exists

Removing the file prior to calling bootctl should fix this.

I've tested this using the installer.simpleUefiGummiboot test and it now
succeeds.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Cc: @edolstra, @shlevy, @mic92
Fixes: #22925
Diffstat (limited to 'nixos/modules/system/boot/loader/systemd-boot')
-rw-r--r--nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py4
1 files changed, 4 insertions, 0 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 9218e1dc8a7..04cf17c1b0b 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
@@ -118,6 +118,10 @@ def main():
         os.environ["NIXOS_INSTALL_BOOTLOADER"] = "1"
 
     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")
+
         if "@canTouchEfiVariables@" == "1":
             subprocess.check_call(["@systemd@/bin/bootctl", "--path=@efiSysMountPoint@", "install"])
         else: