2022-08-08 16:27:49 +00:00
|
|
|
# modification of nixpkgs deviceTree.applyOverlays to resolve https://github.com/NixOS/nixpkgs/issues/125354
|
|
|
|
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/device-tree/default.nix
|
2022-08-07 09:16:37 +00:00
|
|
|
{ lib, pkgs, stdenvNoCC, dtc, libraspberrypi }:
|
|
|
|
|
2022-08-08 16:41:30 +00:00
|
|
|
with lib; (base: overlays': stdenvNoCC.mkDerivation {
|
|
|
|
name = "device-tree-overlays";
|
|
|
|
nativeBuildInputs = [ dtc libraspberrypi ];
|
|
|
|
buildCommand = let
|
|
|
|
overlays = toList overlays';
|
|
|
|
in ''
|
|
|
|
mkdir -p $out
|
|
|
|
cd ${base}
|
|
|
|
find . -type f -name '*.dtb' -print0 \
|
|
|
|
| xargs -0 cp -v --no-preserve=mode --target-directory $out --parents
|
|
|
|
for dtb in $(find $out -type f -name '*.dtb'); do
|
|
|
|
dtbCompat="$( fdtget -t s $dtb / compatible )"
|
|
|
|
${flip (concatMapStringsSep "\n") overlays (o: ''
|
|
|
|
overlayCompat="$( fdtget -t s ${o.dtboFile} / compatible )"
|
|
|
|
# overlayCompat in dtbCompat
|
|
|
|
if [[ "$dtbCompat" =~ "$overlayCompat" ]]; then
|
|
|
|
echo "Applying overlay ${o.name} to $( basename $dtb )"
|
|
|
|
mv $dtb{,.in}
|
|
|
|
cp ${o.dtboFile}{,.dtbo}
|
2022-08-08 17:07:05 +00:00
|
|
|
dtmerge "$dtb.in" "$dtb" ${o.dtboFile}.dtbo;
|
2022-08-08 16:41:30 +00:00
|
|
|
rm $dtb.in ${o.dtboFile}.dtbo
|
|
|
|
fi
|
|
|
|
'')}
|
|
|
|
done
|
|
|
|
'';
|
2022-08-08 16:56:33 +00:00
|
|
|
})
|