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.wip/yesman
parent
0a477846af
commit
dd0a951279
@ -0,0 +1,56 @@ |
||||
{ config, lib, pkgs, ... }: |
||||
|
||||
with lib; |
||||
|
||||
let |
||||
cfg = config.hardware.deviceTree; |
||||
in { |
||||
options = { |
||||
hardware.deviceTree = { |
||||
enable = mkOption { |
||||
default = pkgs.stdenv.hostPlatform.platform.kernelDTB or false; |
||||
type = types.bool; |
||||
description = '' |
||||
Build device tree files. These are used to describe the |
||||
non-discoverable hardware of a system. |
||||
''; |
||||
}; |
||||
|
||||
base = mkOption { |
||||
default = "${config.boot.kernelPackages.kernel}/dtbs"; |
||||
defaultText = "\${config.boot.kernelPackages.kernel}/dtbs"; |
||||
example = literalExample "pkgs.deviceTree.raspberryPiDtbs"; |
||||
type = types.nullOr types.path; |
||||
description = '' |
||||
The package containing the base device-tree (.dtb) to boot. Contains |
||||
device trees bundled with the Linux kernel by default. |
||||
''; |
||||
}; |
||||
|
||||
overlays = mkOption { |
||||
default = []; |
||||
example = literalExample |
||||
"[\"\${pkgs.deviceTree.raspberryPiOverlays}/w1-gpio.dtbo\"]"; |
||||
type = types.listOf types.path; |
||||
description = '' |
||||
A path containing device tree overlays (.dtbo) to be applied to all |
||||
base device-trees. |
||||
''; |
||||
}; |
||||
|
||||
package = mkOption { |
||||
default = null; |
||||
type = types.nullOr types.path; |
||||
description = '' |
||||
A path containing device tree overlays (.dtbo) to be applied to all |
||||
base device-trees. Overrides `base` and `overlays`. |
||||
''; |
||||
}; |
||||
}; |
||||
}; |
||||
|
||||
config = mkIf (cfg.enable) { |
||||
hardware.deviceTree.package = if (cfg.overlays != []) |
||||
then pkgs.deviceTree.applyOverlays cfg.base cfg.overlays else cfg.base; |
||||
}; |
||||
} |
@ -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"; |
||||
} |
Loading…
Reference in new issue