From 754005bf485d31384e1905a9af1ad2293a64be20 Mon Sep 17 00:00:00 2001 From: Ben Wolsieffer Date: Fri, 17 Jun 2022 21:44:01 -0400 Subject: [PATCH] nixos/device-tree: preprocess overlays before compiling Run the device tree overlays through the preprocessor before compiling it, as is done in the kernel. This helps make overlays easier to understand, and improves compatibility with those found in the wild. I found the correct command line by running the kernel build with V=1, and then removing all the arguments related to dependency tracking. --- nixos/modules/hardware/device-tree.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nixos/modules/hardware/device-tree.nix b/nixos/modules/hardware/device-tree.nix index 682b4bc0d757..5a8a8e27bee1 100644 --- a/nixos/modules/hardware/device-tree.nix +++ b/nixos/modules/hardware/device-tree.nix @@ -85,13 +85,14 @@ let # Compile single Device Tree overlay source # file (.dts) into its compiled variant (.dtbo) - compileDTS = name: f: pkgs.callPackage({ dtc }: pkgs.stdenv.mkDerivation { + compileDTS = name: f: pkgs.callPackage({ stdenv, dtc }: stdenv.mkDerivation { name = "${name}-dtbo"; nativeBuildInputs = [ dtc ]; buildCommand = '' - dtc -I dts ${f} -O dtb -@ -o $out + $CC -E -nostdinc -I${getDev cfg.kernelPackage}/lib/modules/${cfg.kernelPackage.modDirVersion}/source/scripts/dtc/include-prefixes -undef -D__DTS__ -x assembler-with-cpp ${f} | \ + dtc -I dts -O dtb -@ -o $out ''; }) {};