summary refs log tree commit diff
path: root/pkgs/os-specific/linux/firmware/facetimehd-firmware/default.nix
blob: 05a293083b7fbd75f8eca3f77a6b35da484679a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{ stdenv, fetchurl, cpio, xz, pkgs }:

let

  version = "1.43";

  dmgRange = "420107885-421933300"; # the whole download is 1.3GB, this cuts it down to 2MB

  firmwareIn = "./System/Library/Extensions/AppleCameraInterface.kext/Contents/MacOS/AppleCameraInterface";
  firmwareOut = "firmware.bin";
  firmwareOffset = "81920";
  firmwareSize = "603715";

  # separated this here as the script will fail without the 'exit 0'
  unpack = pkgs.writeScriptBin "unpack" ''
    xzcat -Q $src | cpio --format odc -i -d ${firmwareIn}
    exit 0
  '';

in

stdenv.mkDerivation {

  name = "facetimehd-firmware-${version}";

  src = fetchurl {
    url = "https://support.apple.com/downloads/DL1849/en_US/osxupd10.11.2.dmg";
    sha256 = "1jw6sy9vj27amfak83cs2c7q856y4mk1wix3rl4q10yvd9bl4k9x";
    curlOpts = "-r ${dmgRange}";
  };

  phases = [ "buildPhase" ];

  buildInputs = [ cpio xz ];

  buildPhase = ''
    ${unpack}/bin/unpack
    dd bs=1 skip=${firmwareOffset} count=${firmwareSize} if=${firmwareIn} of=${firmwareOut}.gz &> /dev/null
    mkdir -p $out/lib/firmware/facetimehd
    gunzip -c ${firmwareOut}.gz > $out/lib/firmware/facetimehd/${firmwareOut}
  '';

  meta = with stdenv.lib; {
    description = "facetimehd firmware";
    homepage = https://support.apple.com/downloads/DL1849;
    license = licenses.unfree;
    maintainers = [ maintainers.womfoo ];
    platforms = platforms.linux;
  };

}