summary refs log tree commit diff
path: root/pkgs/os-specific
diff options
context:
space:
mode:
authorKai Wohlfahrt <kai@prodo.ai>2019-04-24 18:24:16 +0100
committerKai Wohlfahrt <kai@prodo.ai>2019-08-07 13:51:22 +0100
commitdd0a9512797faa83bd1f974b10ef4d620200a79a (patch)
tree5b97f95445c6e3724520f184cdedd6d4d25d9827 /pkgs/os-specific
parent0a477846af2837752687ced588b71108ff010bb2 (diff)
downloadnixpkgs-dd0a9512797faa83bd1f974b10ef4d620200a79a.tar
nixpkgs-dd0a9512797faa83bd1f974b10ef4d620200a79a.tar.gz
nixpkgs-dd0a9512797faa83bd1f974b10ef4d620200a79a.tar.bz2
nixpkgs-dd0a9512797faa83bd1f974b10ef4d620200a79a.tar.lz
nixpkgs-dd0a9512797faa83bd1f974b10ef4d620200a79a.tar.xz
nixpkgs-dd0a9512797faa83bd1f974b10ef4d620200a79a.tar.zst
nixpkgs-dd0a9512797faa83bd1f974b10ef4d620200a79a.zip
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.
Diffstat (limited to 'pkgs/os-specific')
-rw-r--r--pkgs/os-specific/linux/device-tree.nix28
1 files changed, 28 insertions, 0 deletions
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";
+}