1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 flex,
6 libusb1,
7 meson,
8 ninja,
9 nix-update-script,
10 pcsclite,
11 perl,
12 pkg-config,
13 zlib,
14}:
15
16stdenv.mkDerivation rec {
17 pname = "ccid";
18 version = "1.6.2";
19
20 src = fetchFromGitHub {
21 owner = "LudovicRousseau";
22 repo = "CCID";
23 tag = version;
24 hash = "sha256-n7rOjnLZH4RLmddtBycr3FK2Bi/OLR+9IjWBRbWjnUw=";
25 };
26
27 postPatch = ''
28 patchShebangs .
29 substituteInPlace meson.build --replace-fail \
30 "pcsc_dep.get_variable('usbdropdir')" \
31 "'$out/pcsc/drivers'"
32 '';
33
34 mesonFlags = [
35 (lib.mesonBool "serial" true)
36 ];
37
38 # error: call to undeclared function 'InterruptRead';
39 # ISO C99 and later do not support implicit function declarations
40 env = lib.optionalAttrs stdenv.cc.isClang {
41 NIX_CFLAGS_COMPILE = "-Wno-error=implicit-function-declaration";
42 };
43
44 nativeBuildInputs = [
45 flex
46 perl
47 pkg-config
48 meson
49 ninja
50 ];
51
52 buildInputs = [
53 libusb1
54 pcsclite
55 zlib
56 ];
57
58 doInstallCheck = true;
59
60 postInstall = ''
61 install -Dm 0444 -t $out/lib/udev/rules.d ../src/92_pcscd_ccid.rules
62 substituteInPlace $out/lib/udev/rules.d/92_pcscd_ccid.rules \
63 --replace-fail "/usr/sbin/pcscd" "${pcsclite}/bin/pcscd"
64 '';
65
66 # The resulting shared object ends up outside of the default paths which are
67 # usually getting stripped.
68 stripDebugList = [ "pcsc" ];
69
70 passthru.updateScript = nix-update-script { };
71
72 installCheckPhase =
73 let
74 platform = if stdenv.hostPlatform.isLinux then "Linux" else "MacOS";
75 in
76 lib.optionalString (stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isDarwin) ''
77 runHook preInstallCheck
78
79 [ -f $out/etc/reader.conf.d/libccidtwin ]
80 [ -f $out/lib/udev/rules.d/92_pcscd_ccid.rules ]
81 [ -f $out/pcsc/drivers/ifd-ccid.bundle/Contents/Info.plist ]
82 [ -f $out/pcsc/drivers/ifd-ccid.bundle/Contents/${platform}/libccid${stdenv.hostPlatform.extensions.sharedLibrary} ]
83 [ -f $out/pcsc/drivers/serial/libccidtwin${stdenv.hostPlatform.extensions.sharedLibrary} ]
84
85 runHook postInstallCheck
86 '';
87
88 meta = with lib; {
89 description = "PC/SC driver for USB CCID smart card readers";
90 homepage = "https://ccid.apdu.fr/";
91 license = licenses.lgpl21Plus;
92 maintainers = [ maintainers.anthonyroussel ];
93 platforms = platforms.unix;
94 };
95}