@@ -1,5 +1,13 @@
11{ stdenv, fetchPypi, fetchpatch, buildPythonPackage, swig, pcsclite, PCSC }:
22
3+let
4+ # Package does not support configuring the pcsc library.
5+ withApplePCSC = stdenv.isDarwin;
6+
7+ inherit (stdenv.lib) getLib getDev optionalString optionals;
8+ inherit (stdenv.hostPlatform.extensions) sharedLibrary;
9+in
10+
311buildPythonPackage rec {
412 version = "1.9.8";
513 pname = "pyscard";
@@ -9,24 +17,28 @@ buildPythonPackage rec {
917 sha256 = "15fh00z1an6r5j7hrz3jlq0rb3jygwf3x4jcwsa008bv8vpcg7gm";
1018 };
1119
12− postPatch = ''
13− sed -e 's!"libpcsclite\.so\.1"!"${stdenv.lib.getLib pcsclite}/lib/libpcsclite.so.1"!' \
14− -i smartcard/scard/winscarddll.c
20+ postPatch = if withApplePCSC then ''
21+ substituteInPlace smartcard/scard/winscarddll.c \
22+ --replace "/System/Library/Frameworks/PCSC.framework/PCSC" \
23+ "${PCSC}/Library/Frameworks/PCSC.framework/PCSC"
24+ '' else ''
25+ substituteInPlace smartcard/scard/winscarddll.c \
26+ --replace "libpcsclite.so.1" \
27+ "${getLib pcsclite}/lib/libpcsclite${sharedLibrary}"
1528 '';
1629
17− NIX_CFLAGS_COMPILE = "-isystem ${stdenv.lib.getDev pcsclite}/include/PCSC/";
30+ NIX_CFLAGS_COMPILE = optionalString (! withApplePCSC)
31+ "-I ${getDev pcsclite}/include/PCSC";
1832
19− patches = [
20− # Fixes darwin tests
21− # See: https://github.com/LudovicRousseau/pyscard/issues/77
22− (fetchpatch {
23− url = "https://github.com/LudovicRousseau/pyscard/commit/62e675028086c75656444cc21d563d9f08ebf8e7.patch";
24− sha256 = "1lr55npcpc8j750vf7vaisqyk18d5f00l7nii2lvawg4sssjaaf7";
25− })
26− ];
33+ # The error message differs depending on the macOS host version.
34+ # Since Nix reports a constant host version, but proxies to the
35+ # underlying library, it's not possible to determine the correct
36+ # expected error message. This patch allows both errors to be
37+ # accepted.
38+ # See: https://github.com/LudovicRousseau/pyscard/issues/77
39+ patches = optionals withApplePCSC [ ./ignore-macos-bug.patch ];
2740
28− propagatedBuildInputs = [ pcsclite ];
29− buildInputs = stdenv.lib.optional stdenv.isDarwin PCSC;
41+ propagatedBuildInputs = if withApplePCSC then [ PCSC ] else [ pcsclite ];
3042 nativeBuildInputs = [ swig ];
3143
3244 meta = {