{ lib
, stdenv
, fetchFromGitHub
, libusb-compat-0_1
, readline
, pkg-config
, libusb1
, autoreconfHook
, libnfc-nci
}:

stdenv.mkDerivation rec {
  pname = "libnfc";
  version = "1.8.0";

  src = fetchFromGitHub {
    owner = "nfc-tools";
    repo = pname;
    rev = "libnfc-${version}";
    sha256 = "5gMv/HajPrUL/vkegEqHgN2d6Yzf01dTMrx4l34KMrQ=";
  };

  nativeBuildInputs = [
    autoreconfHook
    pkg-config
  ];

  buildInputs = [
    libusb1
    libusb-compat-0_1
    readline
    libnfc-nci
  ];

  configureFlags = [
    "--with-drivers=pn71xx"
    "sysconfdir=/etc"
  ];

  meta = with lib; {
    description = "Library for Near Field Communication (NFC)";
    homepage = "https://github.com/nfc-tools/libnfc";
    license = licenses.lgpl3Plus;
    platforms = platforms.unix;
  };
}
