From 6327b07b25ae1a2de6252f4d541c80c46baacf7a Mon Sep 17 00:00:00 2001 From: Jared Baur Date: Tue, 20 Aug 2024 22:28:24 -0700 Subject: [PATCH] nixos/systemd-boot: use unique path for devicetree blob Use the store directory for the devicetree package containing the desired DTB when installing to the ESP. This allows for more than one NixOS generation containing differing DTBs to coexist on the same ESP (similar to how we can have multiple kernels & initrds). This change removes the assumption that the filepath passed to `copy_from_file` is a file that lives at the toplevel of a nix output path (which prior to the systemd-boot DTB support was the case for the kernel and initrd derivations). --- .../system/boot/loader/systemd-boot/systemd-boot-builder.py | 6 ++++-- .../system/boot/loader/systemd-boot/systemd-boot.nix | 2 ++ nixos/tests/systemd-boot.nix | 2 +- 3 files changed, 7 insertions(+), 3 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 6db0ee7a4e47..9700684cc97d 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 @@ -33,6 +33,7 @@ CAN_TOUCH_EFI_VARIABLES = "@canTouchEfiVariables@" GRACEFUL = "@graceful@" COPY_EXTRA_FILES = "@copyExtraFiles@" CHECK_MOUNTPOINTS = "@checkMountpoints@" +STORE_DIR = "@storeDir@" @dataclass class BootSpec: @@ -150,12 +151,13 @@ def bootspec_from_json(bootspec_json: dict[str, Any]) -> BootSpec: def copy_from_file(file: str, dry_run: bool = False) -> str: store_file_path = os.path.realpath(file) suffix = os.path.basename(store_file_path) - store_dir = os.path.basename(os.path.dirname(store_file_path)) - efi_file_path = f"{NIXOS_DIR}/{store_dir}-{suffix}.efi" + store_subdir = os.path.relpath(store_file_path, start=STORE_DIR).split(os.path.sep)[0] + efi_file_path = f"{NIXOS_DIR}/{suffix}.efi" if suffix == store_subdir else f"{NIXOS_DIR}/{store_subdir}-{suffix}.efi" if not dry_run: copy_if_not_exists(store_file_path, f"{BOOT_MOUNT_POINT}{efi_file_path}") return efi_file_path + def write_entry(profile: str | None, generation: int, specialisation: str | None, machine_id: str, bootspec: BootSpec, current: bool) -> None: if specialisation: diff --git a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix index bc32b15e52b2..2d5c7cc9caa0 100644 --- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix +++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix @@ -28,6 +28,8 @@ let isExecutable = true; + inherit (builtins) storeDir; + inherit (pkgs) python3; systemd = config.systemd.package; diff --git a/nixos/tests/systemd-boot.nix b/nixos/tests/systemd-boot.nix index ee724a63f67f..17edfb06f670 100644 --- a/nixos/tests/systemd-boot.nix +++ b/nixos/tests/systemd-boot.nix @@ -200,7 +200,7 @@ in ) '' + pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isAarch64 '' machine.succeed( - "grep 'devicetree .*dummy' /boot/loader/entries/nixos-generation-1-specialisation-something.conf" + r"grep 'devicetree /EFI/nixos/[a-z0-9]\{32\}.*dummy' /boot/loader/entries/nixos-generation-1-specialisation-something.conf" ) ''; };