1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchPypi,
6 xcbuild,
7 cython_0,
8 libusb1,
9 udev,
10 darwin,
11}:
12
13buildPythonPackage rec {
14 pname = "hidapi";
15 version = "0.14.0";
16 format = "setuptools";
17
18 src = fetchPypi {
19 inherit pname version;
20 sha256 = "a7cb029286ced5426a381286526d9501846409701a29c2538615c3d1a612b8be";
21 };
22
23 nativeBuildInputs = [ cython_0 ] ++ lib.optionals stdenv.isDarwin [ xcbuild ];
24
25 propagatedBuildInputs =
26 lib.optionals stdenv.isLinux [
27 libusb1
28 udev
29 ]
30 ++ lib.optionals stdenv.isDarwin (
31 with darwin.apple_sdk.frameworks;
32 [
33 AppKit
34 CoreFoundation
35 IOKit
36 ]
37 );
38
39 # Fix the USB backend library lookup
40 postPatch = lib.optionalString stdenv.isLinux ''
41 libusb=${libusb1.dev}/include/libusb-1.0
42 test -d $libusb || { echo "ERROR: $libusb doesn't exist, please update/fix this build expression."; exit 1; }
43 sed -i -e "s|/usr/include/libusb-1.0|$libusb|" setup.py
44 '';
45
46 pythonImportsCheck = [ "hid" ];
47
48 meta = with lib; {
49 description = "A Cython interface to the hidapi from https://github.com/libusb/hidapi";
50 homepage = "https://github.com/trezor/cython-hidapi";
51 # license can actually be either bsd3 or gpl3
52 # see https://github.com/trezor/cython-hidapi/blob/master/LICENSE-orig.txt
53 license = with licenses; [
54 bsd3
55 gpl3Only
56 ];
57 maintainers = with maintainers; [
58 np
59 prusnak
60 ];
61 };
62}