From dd0a9512797faa83bd1f974b10ef4d620200a79a Mon Sep 17 00:00:00 2001 From: Kai Wohlfahrt Date: Wed, 24 Apr 2019 18:24:16 +0100 Subject: nixos/hardware.deviceTree: new module Add support for custom device-tree files, and applying overlays to them. This is useful for supporting non-discoverable hardware, such as sensors attached to GPIO pins on a Raspberry Pi. --- pkgs/os-specific/linux/device-tree.nix | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pkgs/os-specific/linux/device-tree.nix (limited to 'pkgs/os-specific') diff --git a/pkgs/os-specific/linux/device-tree.nix b/pkgs/os-specific/linux/device-tree.nix new file mode 100644 index 00000000000..81dccac8b8c --- /dev/null +++ b/pkgs/os-specific/linux/device-tree.nix @@ -0,0 +1,28 @@ +{ stdenvNoCC, dtc, findutils, raspberrypifw }: + +with stdenvNoCC.lib; { + applyOverlays = (base: overlays: stdenvNoCC.mkDerivation { + name = "device-tree-overlays"; + nativeBuildInputs = [ dtc findutils ]; + buildCommand = let + quotedDtbos = concatMapStringsSep " " (o: "\"${toString o}\"") (toList overlays); + in '' + for dtb in $(find ${base} -name "*.dtb" ); do + outDtb=$out/$(realpath --relative-to "${base}" "$dtb") + mkdir -p "$(dirname "$outDtb")" + fdtoverlay -o "$outDtb" -i "$dtb" ${quotedDtbos}; + done + ''; + }); + + raspberryPiDtbs = stdenvNoCC.mkDerivation { + name = "raspberrypi-dtbs-${raspberrypifw.version}"; + nativeBuildInputs = [ raspberrypifw ]; + buildCommand = '' + mkdir -p $out/broadcom/ + cp ${raspberrypifw}/share/raspberrypi/boot/bcm*.dtb $out/broadcom + ''; + }; + + raspberryPiOverlays = "${raspberrypifw}/share/raspberrypi/boot/overlays"; +} -- cgit 1.4.1