1{ lib
2, stdenv
3, fetchFromGitHub
4, fetchpatch
5, cmake
6, libusb1
7, gtk3
8, pkg-config
9, wrapGAppsHook
10, withGUI ? false
11}:
12
13let
14 # The Darwin build of stlink explicitly refers to static libusb.
15 libusb1' = if stdenv.isDarwin then libusb1.override { withStatic = true; } else libusb1;
16
17# IMPORTANT: You need permissions to access the stlink usb devices.
18# Add services.udev.packages = [ pkgs.stlink ] to your configuration.nix
19
20in stdenv.mkDerivation rec {
21 pname = "stlink";
22 version = "1.7.0";
23
24 src = fetchFromGitHub {
25 owner = "stlink-org";
26 repo = "stlink";
27 rev = "v${version}";
28 sha256 = "03xypffpbp4imrczbxmq69vgkr7mbp0ps9dk815br5wwlz6vgygl";
29 };
30
31 patches = [
32 (fetchpatch {
33 url = "https://github.com/stlink-org/stlink/commit/468b1d2daa853b975c33ab69876c486734f2c6a7.diff";
34 sha256 = "sha256-ueSi/zc7xbOATl0yBtCL4U64IQ/yqu6sMYDOiPl1JBI=";
35 })
36 ];
37
38 buildInputs = [
39 libusb1'
40 ] ++ lib.optionals withGUI [
41 gtk3
42 ];
43 nativeBuildInputs = [
44 cmake
45 ] ++ lib.optionals withGUI [
46 pkg-config
47 wrapGAppsHook
48 ];
49
50 cmakeFlags = [
51 "-DSTLINK_MODPROBED_DIR=${placeholder "out"}/etc/modprobe.d"
52 "-DSTLINK_UDEV_RULES_DIR=${placeholder "out"}/lib/udev/rules.d"
53 ];
54
55 meta = with lib; {
56 description = "In-circuit debug and programming for ST-Link devices";
57 license = licenses.bsd3;
58 platforms = platforms.unix;
59 maintainers = [ maintainers.bjornfor maintainers.rongcuid ];
60 };
61}