Created
August 3, 2022 19:31
-
-
Save carlossless/7adfea6cd656201bb8d52daeb33a5112 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ lib, pkgs, stdenvNoCC, dtc }: | |
with lib; { | |
applyOverlays = (base: overlays': stdenvNoCC.mkDerivation { | |
name = "device-tree-overlays"; | |
nativeBuildInputs = [ dtc ]; | |
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} ${o.dtboFile}.dtbo | |
${pkgs.libraspberrypi}/bin/dtmerge "$dtb.in" "$dtb" ${o.dtboFile}.dtbo; | |
rm $dtb.in | |
rm ${o.dtboFile}.dtbo | |
fi | |
'')} | |
done | |
''; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The default
pkgs.deviceTree.applyOverlays
can be overriden by using:This is useful if you're applying rpi dt overlays that don't work with
ftoverlay
.