nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 fetchpatch,
6 cmake,
7 libusb1,
8 gtk3,
9 pkg-config,
10 wrapGAppsHook3,
11 withGUI ? false,
12}:
13
14let
15 # The Darwin build of stlink explicitly refers to static libusb.
16 libusb1' =
17 if stdenv.hostPlatform.isDarwin then libusb1.override { withStatic = true; } else libusb1;
18
19 # IMPORTANT: You need permissions to access the stlink usb devices.
20 # Add services.udev.packages = [ pkgs.stlink ] to your configuration.nix
21
22in
23stdenv.mkDerivation (finalAttrs: {
24 pname = "stlink";
25 version = "1.8.0";
26
27 src = fetchFromGitHub {
28 owner = "stlink-org";
29 repo = "stlink";
30 rev = "v${finalAttrs.version}";
31 sha256 = "sha256-hlFI2xpZ4ldMcxZbg/T5/4JuFFdO9THLcU0DQKSFqrw=";
32 };
33
34 patches = [
35 (fetchpatch {
36 name = "calloc-argument-order.patch";
37 url = "https://github.com/stlink-org/stlink/commit/6a6718b3342b6c5e282a4e33325b9f97908a0692.patch";
38 includes = [ "src/stlink-lib/chipid.c" ];
39 sha256 = "sha256-sAfcrDdoKy5Gl1o/PHEUr8uL9OBq0g1nfRe7Y0ijWAM=";
40 })
41 ];
42
43 buildInputs = [
44 libusb1'
45 ]
46 ++ lib.optionals withGUI [
47 gtk3
48 ];
49 nativeBuildInputs = [
50 cmake
51 ]
52 ++ lib.optionals withGUI [
53 pkg-config
54 wrapGAppsHook3
55 ];
56
57 doInstallCheck = true;
58
59 cmakeFlags = [
60 "-DSTLINK_MODPROBED_DIR=${placeholder "out"}/etc/modprobe.d"
61 "-DSTLINK_UDEV_RULES_DIR=${placeholder "out"}/lib/udev/rules.d"
62 ];
63
64 meta = {
65 description = "In-circuit debug and programming for ST-Link devices";
66 license = lib.licenses.bsd3;
67 platforms = lib.platforms.unix;
68 badPlatforms = lib.platforms.darwin;
69 maintainers = [
70 lib.maintainers.bjornfor
71 lib.maintainers.rongcuid
72 ];
73 };
74})