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