export a single function from apply-overlays-dtmerge

This commit is contained in:
Karolis Stasaitis 2022-08-08 18:41:30 +02:00
parent 245d8f9f97
commit 3f0991b531

View file

@ -2,31 +2,29 @@
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/device-tree/default.nix # https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/device-tree/default.nix
{ lib, pkgs, stdenvNoCC, dtc, libraspberrypi }: { lib, pkgs, stdenvNoCC, dtc, libraspberrypi }:
with lib; { with lib; (base: overlays': stdenvNoCC.mkDerivation {
applyOverlays = (base: overlays': stdenvNoCC.mkDerivation { name = "device-tree-overlays";
name = "device-tree-overlays"; nativeBuildInputs = [ dtc libraspberrypi ];
nativeBuildInputs = [ dtc libraspberrypi ]; buildCommand = let
buildCommand = let overlays = toList overlays';
overlays = toList overlays'; in ''
in '' mkdir -p $out
mkdir -p $out cd ${base}
cd ${base} find . -type f -name '*.dtb' -print0 \
find . -type f -name '*.dtb' -print0 \ | xargs -0 cp -v --no-preserve=mode --target-directory $out --parents
| xargs -0 cp -v --no-preserve=mode --target-directory $out --parents for dtb in $(find $out -type f -name '*.dtb'); do
for dtb in $(find $out -type f -name '*.dtb'); do dtbCompat="$( fdtget -t s $dtb / compatible )"
dtbCompat="$( fdtget -t s $dtb / compatible )" ${flip (concatMapStringsSep "\n") overlays (o: ''
${flip (concatMapStringsSep "\n") overlays (o: '' overlayCompat="$( fdtget -t s ${o.dtboFile} / compatible )"
overlayCompat="$( fdtget -t s ${o.dtboFile} / compatible )" # overlayCompat in dtbCompat
# overlayCompat in dtbCompat if [[ "$dtbCompat" =~ "$overlayCompat" ]]; then
if [[ "$dtbCompat" =~ "$overlayCompat" ]]; then echo "Applying overlay ${o.name} to $( basename $dtb )"
echo "Applying overlay ${o.name} to $( basename $dtb )" mv $dtb{,.in}
mv $dtb{,.in} cp ${o.dtboFile}{,.dtbo}
cp ${o.dtboFile}{,.dtbo} ${libraspberrypi}/bin/dtmerge "$dtb.in" "$dtb" ${o.dtboFile}.dtbo;
${libraspberrypi}/bin/dtmerge "$dtb.in" "$dtb" ${o.dtboFile}.dtbo; rm $dtb.in ${o.dtboFile}.dtbo
rm $dtb.in ${o.dtboFile}.dtbo fi
fi '')}
'')} done
done '';
''; });
});
}