From 2b26158aafe09d095950cddefe1cc0911f44df98 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Thu, 28 Aug 2025 13:53:47 -0700 Subject: [PATCH] facetimehd-calibration: fix build Resolves #430685 This was the only user of `fetchurl` which was using `-r`, which is incompatible with `--continue-at -` from 4d7a4fbd9f634d0c2f1e660d3981e965b3513466. Rather than engineer a way to pass range options to `fetchurl`, let's just make a custom builder for this derivation. It actually makes the whole thing more clear. (cherry picked from commit 252b0b5c333b02f53d986c5151a4eda574056544) --- .../fa/facetimehd-calibration/builder.sh | 22 +++++ .../fa/facetimehd-calibration/package.nix | 94 ++++--------------- 2 files changed, 38 insertions(+), 78 deletions(-) create mode 100644 pkgs/by-name/fa/facetimehd-calibration/builder.sh diff --git a/pkgs/by-name/fa/facetimehd-calibration/builder.sh b/pkgs/by-name/fa/facetimehd-calibration/builder.sh new file mode 100644 index 000000000000..a778d4fd3fc7 --- /dev/null +++ b/pkgs/by-name/fa/facetimehd-calibration/builder.sh @@ -0,0 +1,22 @@ +# Described on https://github.com/patjak/facetimehd/wiki/Extracting-the-sensor-calibration-files +# +# The whole download is 518MB; the deflate stream we're interested in is 1.2MB. +urlRoot="https://download.info.apple.com/Mac_OS_X/031-30890-20150812-ea191174-4130-11e5-a125-930911ba098f" +curl --insecure -o bootcamp.zip "$urlRoot/bootcamp$version.zip" -r 2338085-3492508 + +# Add appropriate headers and footers so that zcat extracts cleanly + +{ printf '\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x00' + cat bootcamp.zip + printf '\x51\x1f\x86\x78\xcf\x5b\x12\x00' +} | zcat > AppleCamera64.exe +unrar x AppleCamera64.exe AppleCamera.sys + +# These offsets and sizes are from the wiki also +dd bs=1 skip=1663920 count=33060 if=AppleCamera.sys of=9112_01XX.dat +dd bs=1 skip=1644880 count=19040 if=AppleCamera.sys of=1771_01XX.dat +dd bs=1 skip=1606800 count=19040 if=AppleCamera.sys of=1871_01XX.dat +dd bs=1 skip=1625840 count=19040 if=AppleCamera.sys of=1874_01XX.dat + +mkdir -p "$out/lib/firmware/facetimehd" +cp -a *.dat "$out/lib/firmware/facetimehd" diff --git a/pkgs/by-name/fa/facetimehd-calibration/package.nix b/pkgs/by-name/fa/facetimehd-calibration/package.nix index 79ac6fc64c3d..3f535df358ff 100644 --- a/pkgs/by-name/fa/facetimehd-calibration/package.nix +++ b/pkgs/by-name/fa/facetimehd-calibration/package.nix @@ -1,98 +1,36 @@ { lib, stdenvNoCC, - fetchurl, + curl, unrar-wrapper, - pkgs, }: -let - +stdenvNoCC.mkDerivation { + pname = "facetimehd-calibration"; version = "5.1.5769"; - # Described on https://github.com/patjak/facetimehd/wiki/Extracting-the-sensor-calibration-files + # This is a special sort of fixed-output derivation + outputHash = "sha256-KQBIlpa68wjQNgBiEnLtl6iEYseNrTlSdq9wiNni16k="; + outputHashMode = "recursive"; - # From the wiki page, range extracted with binwalk: - zipUrl = "https://download.info.apple.com/Mac_OS_X/031-30890-20150812-ea191174-4130-11e5-a125-930911ba098f/bootcamp${version}.zip"; - zipRange = "2338085-3492508"; # the whole download is 518MB, this deflate stream is 1.2MB + __structuredAttrs = true; + builder = ./builder.sh; - # CRC and length from the ZIP entry header (not strictly necessary, but makes it extract cleanly): - gzFooter = ''\x51\x1f\x86\x78\xcf\x5b\x12\x00''; - - # Also from the wiki page: - calibrationFiles = [ - { - file = "1771_01XX.dat"; - offset = "1644880"; - size = "19040"; - } - { - file = "1871_01XX.dat"; - offset = "1606800"; - size = "19040"; - } - { - file = "1874_01XX.dat"; - offset = "1625840"; - size = "19040"; - } - { - file = "9112_01XX.dat"; - offset = "1663920"; - size = "33060"; - } + nativeBuildInputs = [ + curl + unrar-wrapper ]; -in - -stdenvNoCC.mkDerivation { - - pname = "facetimehd-calibration"; - inherit version; - src = fetchurl { - url = zipUrl; - sha256 = "1dzyv457fp6d8ly29sivqn6llwj5ydygx7p8kzvdnsp11zvid2xi"; - curlOpts = "-r ${zipRange}"; - }; - - dontUnpack = true; - dontInstall = true; - - nativeBuildInputs = [ unrar-wrapper ]; - - buildPhase = '' - { printf '\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x00' - cat $src - printf '${gzFooter}' - } | zcat > AppleCamera64.exe - unrar x AppleCamera64.exe AppleCamera.sys - - mkdir -p $out/lib/firmware/facetimehd - '' - + lib.concatMapStrings ( - { - file, - offset, - size, - }: - '' - dd bs=1 skip=${offset} count=${size} if=AppleCamera.sys of=$out/lib/firmware/facetimehd/${file} - '' - ) calibrationFiles; - - meta = with lib; { + meta = { description = "facetimehd calibration"; homepage = "https://support.apple.com/kb/DL1837"; - license = licenses.unfree; - maintainers = with maintainers; [ + license = lib.licenses.unfree; + maintainers = with lib.maintainers; [ alexshpilkin womfoo grahamc ]; - platforms = [ - "i686-linux" - "x86_64-linux" - ]; + platforms = lib.platforms.all; + sourceProvenance = with lib.sourceTypes; [ binaryFirmware ]; }; - }