1{ lib
2, stdenv
3, fetchgit
4, requireFile
5, pkg-config
6, libusb1
7, p7zip
8}:
9
10let
11 # The last known good firmware package to have been tested
12 # by the upstream projet.
13 # The firmware URL is hardcoded in the upstream project's installation script
14 firmwareUrl = "https://download.microsoft.com/download/F/9/9/F99791F2-D5BE-478A-B77A-830AD14950C3/KinectSDK-v1.0-beta2-x86.msi";
15 # The original URL "https://research.microsoft.com/en-us/um/legal/kinectsdk-tou_noncommercial.htm"
16 # redirects to the following url:
17 licenseUrl = "https://www.microsoft.com/en-us/legal/terms-of-use";
18in
19stdenv.mkDerivation rec {
20 pname = "kinect-audio-setup";
21
22 # On update: Make sure that the `firmwareURL` is still in sync with upstream.
23 # If the project structure hasn't changed you can find the URL in the
24 # `kinect_fetch_fw` file in the project source.
25 version = "0.5";
26
27 # This is an MSI or CAB file
28 FIRMWARE = requireFile rec {
29 name = "UACFirmware";
30 sha256 = "08a2vpgd061cmc6h3h8i6qj3sjvjr1fwcnwccwywqypz3icn8xw1";
31 message = ''
32 In order to install the Kinect Audio Firmware, you need to download the
33 non-redistributable firmware from Microsoft.
34 The firmware is available at ${firmwareUrl} and the license at ${licenseUrl} .
35 Save the file as UACFirmware and use "nix-prefetch-url file://\$PWD/UACFirmware" to
36 add it to the Nix store.
37 '';
38 };
39
40 src = fetchgit {
41 url = "git://git.ao2.it/kinect-audio-setup.git";
42 rev = "v${version}";
43 hash = "sha256-bFwmWh822KvFwP/0Gu097nF5K2uCwCLMB1RtP7k+Zt0=";
44 };
45
46 # These patches are not upstream because the project has seen no
47 # activity since 2016
48 patches = [
49 ./libusb-1-import-path.patch
50 ./udev-rules-extra-devices.patch
51 ];
52
53 nativeBuildInputs = [ p7zip libusb1 pkg-config ];
54
55 makeFlags = [
56 "PREFIX=$(out)"
57 "DESTDIR=$(out)"
58 "FIRMWARE_PATH=$(out)/lib/firmware/UACFirmware"
59 "LOADER_PATH=$(out)/libexec/kinect_upload_fw"
60 ];
61
62 buildPhase = ''
63 runHook preBuild
64 make -C kinect_upload_fw kinect_upload_fw $makeFlags "''${makeFlagsArray[@]}"
65 runHook postBuild
66 '';
67
68 installPhase = ''
69 runHook preInstall
70 mkdir -p $out/libexec/ $out/lib/firmware $out/lib/udev/rules.d
71
72 install -Dm755 kinect_upload_fw/kinect_upload_fw $out/libexec/
73
74 # 7z extract "assume yes on all queries" "only extract/keep files/directories matching UACFIRMWARE.* recursively"
75 7z e -y -r "${FIRMWARE}" "UACFirmware.*" >/dev/null
76 # The filename is bound to change with the Firmware SDK
77 mv UACFirmware.* $out/lib/firmware/UACFirmware
78
79 make install_udev_rules $makeFlags "''${makeFlagsArray[@]}"
80
81 runHook postInstall
82 '';
83
84 meta = with lib; {
85 description = "Tools to enable audio input from the Microsoft Kinect sensor device";
86 homepage = "https://git.ao2.it/kinect-audio-setup.git";
87 maintainers = with maintainers; [ berbiche ];
88 platforms = platforms.linux;
89 license = licenses.unfree;
90 };
91}