1{ lib
2, stdenv
3, fetchPypi
4, buildPythonPackage
5, swig
6, pcsclite
7, PCSC
8}:
9
10let
11 # Package does not support configuring the pcsc library.
12 withApplePCSC = stdenv.isDarwin;
13in
14
15buildPythonPackage rec {
16 version = "2.0.7";
17 pname = "pyscard";
18
19 src = fetchPypi {
20 inherit pname version;
21 hash = "sha256-J4BUUl+nX76LEEYNh+3NA6cK2U1oixE0Xkc5mH+Fwb8=";
22 };
23
24 postPatch = if withApplePCSC then ''
25 substituteInPlace smartcard/scard/winscarddll.c \
26 --replace "/System/Library/Frameworks/PCSC.framework/PCSC" \
27 "${PCSC}/Library/Frameworks/PCSC.framework/PCSC"
28 '' else ''
29 substituteInPlace smartcard/scard/winscarddll.c \
30 --replace "libpcsclite.so.1" \
31 "${lib.getLib pcsclite}/lib/libpcsclite${stdenv.hostPlatform.extensions.sharedLibrary}"
32 '';
33
34 env.NIX_CFLAGS_COMPILE = lib.optionalString (! withApplePCSC)
35 "-I ${lib.getDev pcsclite}/include/PCSC";
36
37 propagatedBuildInputs = if withApplePCSC then [ PCSC ] else [ pcsclite ];
38 nativeBuildInputs = [ swig ];
39
40 meta = with lib; {
41 homepage = "https://pyscard.sourceforge.io/";
42 description = "Smartcard library for python";
43 license = licenses.lgpl21;
44 maintainers = with maintainers; [ layus ];
45 };
46}