From 416c26d8b6f4fcb6ba80b3b2bc2375f4907c7074 Mon Sep 17 00:00:00 2001 From: Jeremy Fleischman Date: Tue, 2 Sep 2025 14:58:27 +0100 Subject: [PATCH 1/2] nixos/boot.loader.efi: rename `boot.loader.systemd-boot.installDeviceTree` to `boot.loader.efi.installDeviceTree` This is in preparation for updating `nixos/modules/installer/cd-dvd/iso-image.nix` to also honor `installDeviceTree`. That code currently uses grub, so looking at a value in the systemd-boot namespace doesn't really make sense. --- nixos/modules/system/boot/loader/efi.nix | 11 +++++++- .../boot/loader/systemd-boot/systemd-boot.nix | 27 +++++++++++-------- nixos/tests/systemd-boot.nix | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/nixos/modules/system/boot/loader/efi.nix b/nixos/modules/system/boot/loader/efi.nix index 2725d3678d523..65bb572789f86 100644 --- a/nixos/modules/system/boot/loader/efi.nix +++ b/nixos/modules/system/boot/loader/efi.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ config, lib, ... }: { options.boot.loader.efi = { @@ -13,5 +13,14 @@ type = lib.types.str; description = "Where the EFI System Partition is mounted."; }; + + installDeviceTree = lib.mkOption { + default = with config.hardware.deviceTree; enable && name != null; + defaultText = ''with config.hardware.deviceTree; enable && name != null''; + description = '' + Install the devicetree blob specified by `config.hardware.deviceTree.name` + to the ESP and instruct the bootloader to pass this DTB to linux. + ''; + }; }; } 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 035462d10402b..161534da00aa4 100644 --- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix +++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix @@ -161,6 +161,20 @@ in ] (config: lib.strings.removeSuffix ".conf" config.boot.loader.systemd-boot.netbootxyz.entryFilename) ) + (mkRenamedOptionModule + [ + "boot" + "loader" + "systemd-boot" + "installDeviceTree" + ] + [ + "boot" + "loader" + "efi" + "installDeviceTree" + ] + ) ]; options.boot.loader.systemd-boot = { @@ -244,15 +258,6 @@ in ''; }; - installDeviceTree = mkOption { - default = with config.hardware.deviceTree; enable && name != null; - defaultText = ''with config.hardware.deviceTree; enable && name != null''; - description = '' - Install the devicetree blob specified by `config.hardware.deviceTree.name` - to the ESP and instruct systemd-boot to pass this DTB to linux. - ''; - }; - extraInstallCommands = mkOption { default = ""; example = '' @@ -537,7 +542,7 @@ in } { assertion = - cfg.installDeviceTree + efi.installDeviceTree -> config.hardware.deviceTree.enable -> config.hardware.deviceTree.name != null; message = "Cannot install devicetree without 'config.hardware.deviceTree.enable' enabled and 'config.hardware.deviceTree.name' set"; @@ -626,7 +631,7 @@ in boot.bootspec.extensions."org.nixos.systemd-boot" = { inherit (config.boot.loader.systemd-boot) sortKey; - devicetree = lib.mkIf cfg.installDeviceTree "${config.hardware.deviceTree.package}/${config.hardware.deviceTree.name}"; + devicetree = lib.mkIf efi.installDeviceTree "${config.hardware.deviceTree.package}/${config.hardware.deviceTree.name}"; }; system = { diff --git a/nixos/tests/systemd-boot.nix b/nixos/tests/systemd-boot.nix index 570cd6b934091..53848be641e94 100644 --- a/nixos/tests/systemd-boot.nix +++ b/nixos/tests/systemd-boot.nix @@ -197,7 +197,7 @@ in # (we would then be able to use `dumpdtb`). Thus, the following config # will not boot, but it does allow us to assert that the boot entry has # the correct contents. - boot.loader.systemd-boot.installDeviceTree = pkgs.stdenv.hostPlatform.isAarch64; + boot.loader.efi.installDeviceTree = pkgs.stdenv.hostPlatform.isAarch64; hardware.deviceTree.name = "dummy.dtb"; hardware.deviceTree.package = lib.mkForce ( pkgs.runCommand "dummy-devicetree-package" { } '' From c7201c3be3c01af87c99770bbf05d4bef5cc435e Mon Sep 17 00:00:00 2001 From: Jeremy Fleischman Date: Tue, 2 Sep 2025 15:16:54 +0100 Subject: [PATCH 2/2] nixos/iso-image: add support for `boot.loader.efi.installDeviceTree` --- nixos/modules/installer/cd-dvd/iso-image.nix | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index ad8dc763570d1..587eca8efa5c9 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -17,6 +17,7 @@ let image, params, initrd, + devicetree, }: '' menuentry '${name}' --class ${class} { @@ -25,6 +26,11 @@ let linux ${image} \''${isoboot} ${params} initrd ${initrd} + '' + + lib.optionalString (devicetree != null) '' + devicetree ${devicetree} + '' + + '' } ''; @@ -48,6 +54,11 @@ let image = "/boot/${cfg.boot.kernelPackages.kernel + "/" + cfg.system.boot.loader.kernelFile}"; initrd = "/boot/${cfg.system.build.initialRamdisk + "/" + cfg.system.boot.loader.initrdFile}"; class = "installer"; + devicetree = + if cfg.boot.loader.efi.installDeviceTree then + "/boot/${cfg.hardware.deviceTree.package}/${cfg.hardware.deviceTree.name}" + else + null; }; in '' @@ -491,7 +502,7 @@ let '' mkdir ./contents && cd ./contents mkdir -p ./EFI/BOOT - cp -rp "${efiDir}"/EFI/BOOT/{grub.cfg,*.EFI,*.efi} ./EFI/BOOT + cp -rp "${efiDir}"/EFI/BOOT/{grub.cfg,*.EFI,*.efi,*.dtb} ./EFI/BOOT # Rewrite dates for everything in the FS find . -exec touch --date=2000-01-01 {} + @@ -950,7 +961,7 @@ in let cfgFiles = cfg: - lib.optionals cfg.isoImage.showConfiguration ([ + lib.optionals cfg.isoImage.showConfiguration [ { source = cfg.boot.kernelPackages.kernel + "/" + cfg.system.boot.loader.kernelFile; target = "/boot/" + cfg.boot.kernelPackages.kernel + "/" + cfg.system.boot.loader.kernelFile; @@ -959,7 +970,13 @@ in source = cfg.system.build.initialRamdisk + "/" + cfg.system.boot.loader.initrdFile; target = "/boot/" + cfg.system.build.initialRamdisk + "/" + cfg.system.boot.loader.initrdFile; } - ]) + ] + ++ lib.optionals cfg.boot.loader.efi.installDeviceTree [ + { + source = "${cfg.hardware.deviceTree.package}/${cfg.hardware.deviceTree.name}"; + target = "/boot/${cfg.hardware.deviceTree.package}/${cfg.hardware.deviceTree.name}"; + } + ] ++ lib.concatLists ( lib.mapAttrsToList (_: { configuration, ... }: cfgFiles configuration) cfg.specialisation );