2022-08-08 18:27:49 +02:00
|
|
|
# modification of nixpkgs deviceTree.applyOverlays to resolve https://github.com/NixOS/nixpkgs/issues/125354
|
2022-12-17 12:33:45 +01:00
|
|
|
# derived from https://github.com/NixOS/nixpkgs/blob/916ca8f2b0c208def051f8ea9760c534a40309db/pkgs/os-specific/linux/device-tree/default.nix
|
2022-12-31 11:52:38 +01:00
|
|
|
{ lib, stdenvNoCC, dtc, libraspberrypi }:
|
2022-08-07 11:16:37 +02:00
|
|
|
|
2022-08-08 18:41:30 +02:00
|
|
|
with lib; (base: overlays': stdenvNoCC.mkDerivation {
|
|
|
|
name = "device-tree-overlays";
|
|
|
|
nativeBuildInputs = [ dtc libraspberrypi ];
|
|
|
|
buildCommand = let
|
|
|
|
overlays = toList overlays';
|
|
|
|
in ''
|
|
|
|
mkdir -p $out
|
2022-12-17 12:33:45 +01:00
|
|
|
cd "${base}"
|
2022-08-08 18:41:30 +02:00
|
|
|
find . -type f -name '*.dtb' -print0 \
|
2022-12-17 12:33:45 +01:00
|
|
|
| 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 2>/dev/null || true)
|
|
|
|
# skip files without `compatible` string
|
|
|
|
test -z "$dtbCompat" && continue
|
|
|
|
|
2022-08-08 18:41:30 +02:00
|
|
|
${flip (concatMapStringsSep "\n") overlays (o: ''
|
2022-12-17 12:33:45 +01:00
|
|
|
overlayCompat="$(fdtget -t s "${o.dtboFile}" / compatible)"
|
|
|
|
|
|
|
|
# skip incompatible and non-matching overlays
|
|
|
|
if [[ ! "$dtbCompat" =~ "$overlayCompat" ]]; then
|
|
|
|
echo "Skipping overlay ${o.name}: incompatible with $(basename "$dtb")"
|
2023-01-17 04:57:10 +01:00
|
|
|
elif ${if ((o.filter or null) == null) then "false" else ''
|
|
|
|
[[ "''${dtb//${o.filter}/}" == "$dtb" ]]
|
2022-12-17 12:33:45 +01:00
|
|
|
''}
|
2023-01-17 04:57:10 +01:00
|
|
|
then
|
|
|
|
echo "Skipping overlay ${o.name}: filter does not match $(basename "$dtb")"
|
|
|
|
else
|
|
|
|
echo -n "Applying overlay ${o.name} to $(basename "$dtb")... "
|
|
|
|
mv "$dtb"{,.in}
|
2022-12-17 12:33:45 +01:00
|
|
|
|
2023-01-17 04:57:10 +01:00
|
|
|
# dtmerge requires a .dtbo ext for dtbo files, otherwise it adds it to the given file implicitly
|
|
|
|
dtboWithExt="$TMPDIR/$(basename "${o.dtboFile}").dtbo"
|
|
|
|
cp -r ${o.dtboFile} "$dtboWithExt"
|
2022-12-17 12:33:45 +01:00
|
|
|
|
2023-01-17 04:57:10 +01:00
|
|
|
dtmerge "$dtb.in" "$dtb" "$dtboWithExt"
|
2022-12-17 12:33:45 +01:00
|
|
|
|
2023-01-17 04:57:10 +01:00
|
|
|
echo "ok"
|
|
|
|
rm "$dtb.in" "$dtboWithExt"
|
|
|
|
fi
|
2022-08-08 18:41:30 +02:00
|
|
|
'')}
|
2022-12-17 12:33:45 +01:00
|
|
|
|
|
|
|
done'';
|
2022-08-08 18:56:33 +02:00
|
|
|
})
|