From 3f0991b531648e1a529d8eb14b483d628c29846b Mon Sep 17 00:00:00 2001 From: Karolis Stasaitis Date: Mon, 8 Aug 2022 18:41:30 +0200 Subject: [PATCH] export a single function from apply-overlays-dtmerge --- raspberry-pi/4/apply-overlays-dtmerge.nix | 54 +++++++++++------------ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/raspberry-pi/4/apply-overlays-dtmerge.nix b/raspberry-pi/4/apply-overlays-dtmerge.nix index 8a325ab..7117509 100644 --- a/raspberry-pi/4/apply-overlays-dtmerge.nix +++ b/raspberry-pi/4/apply-overlays-dtmerge.nix @@ -2,31 +2,29 @@ # https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/device-tree/default.nix { lib, pkgs, stdenvNoCC, dtc, libraspberrypi }: -with lib; { - applyOverlays = (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} - ${libraspberrypi}/bin/dtmerge "$dtb.in" "$dtb" ${o.dtboFile}.dtbo; - rm $dtb.in ${o.dtboFile}.dtbo - fi - '')} - done - ''; - }); -} +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} + ${libraspberrypi}/bin/dtmerge "$dtb.in" "$dtb" ${o.dtboFile}.dtbo; + rm $dtb.in ${o.dtboFile}.dtbo + fi + '')} + done + ''; +});