summaryrefslogtreecommitdiff
path: root/pkgs/tools/security/proxmark3/default.nix
blob: 2c0ac50171486663bea1dcf5ab32d285113b874d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{
  lib,
  stdenv,
  fetchFromGitHub,
  pkg-config,
  gcc-arm-embedded,
  readline,
  bzip2,
  openssl,
  jansson,
  gd,
  whereami,
  lua,
  lz4,
  udevCheckHook,
  nix-update-script,
  withGui ? true,
  wrapQtAppsHook,
  qtbase,
  withPython ? true,
  python3,
  withBlueshark ? false,
  bluez5,
  withGeneric ? false,
  withSmall ? false,
  withoutFunctions ? [ ],
  hardwarePlatform ? if withGeneric then "PM3GENERIC" else "PM3RDV4",
  hardwarePlatformExtras ? lib.optionalString withBlueshark "BTADDON",
  standalone ? "LF_SAMYRUN",
}:
assert withBlueshark -> stdenv.hostPlatform.isLinux;
stdenv.mkDerivation (finalAttrs: {
  pname = "proxmark3";
  version = "4.21128";

  src = fetchFromGitHub {
    owner = "RfidResearchGroup";
    repo = "proxmark3";
    rev = "v${finalAttrs.version}";
    hash = "sha256-KlSYbYEdLVsQCbRilqolGewH5ra9QXOHVgYk34aCous=";
  };

  postPatch = ''
    # Remove hardcoded paths on Darwin
    substituteInPlace Makefile.defs \
      --replace-fail "/usr/bin/ar" "ar" \
      --replace-fail "/usr/bin/ranlib" "ranlib"
    # Replace hardcoded path to libwhereami
    # Replace darwin sed syntax with gnused
    substituteInPlace client/Makefile \
      --replace-fail "/usr/include/whereami.h" "${whereami}/include/whereami.h" \
      --replace-fail "sed -E -i '''" "sed -i"
  '';

  nativeBuildInputs = [
    pkg-config
    gcc-arm-embedded
    udevCheckHook
  ]
  ++ lib.optional withGui wrapQtAppsHook;
  buildInputs = [
    readline
    bzip2
    openssl
    jansson
    gd
    lz4
    whereami
    lua
  ]
  ++ lib.optional withGui qtbase
  ++ lib.optional withPython python3
  ++ lib.optional withBlueshark bluez5;

  makeFlags = [
    "PREFIX=${placeholder "out"}"
    "UDEV_PREFIX=${placeholder "out"}/etc/udev/rules.d"
    "PLATFORM=${hardwarePlatform}"
    "PLATFORM_EXTRAS=${hardwarePlatformExtras}"
    "STANDALONE=${standalone}"
    "USE_BREW=0"
  ]
  ++ lib.optional withSmall "PLATFORM_SIZE=256"
  ++ map (x: "SKIP_${x}=1") withoutFunctions;
  enableParallelBuilding = true;

  doInstallCheck = true;

  passthru.updateScript = nix-update-script { };

  meta = {
    description = "Client for proxmark3, powerful general purpose RFID tool";
    homepage = "https://github.com/RfidResearchGroup/proxmark3";
    license = lib.licenses.gpl3Plus;
    maintainers = with lib.maintainers; [
      nyanotech
      emilytrau
    ];
    platforms = lib.platforms.unix;
    mainProgram = "pm3";
  };
})