about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/tools/misc/blackfire/default.nix
blob: 6f82e0731088d8bb3226e08efcd5f22d4052c9e0 (plain) (blame)
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
{ stdenv
, lib
, fetchurl
, dpkg
, autoPatchelfHook
, writeShellScript
, curl
, jq
, common-updater-scripts
}:

stdenv.mkDerivation rec {
  pname = "blackfire";
  version = "2.5.2";

  src = fetchurl {
    url = "https://packages.blackfire.io/debian/pool/any/main/b/blackfire/blackfire_${version}_amd64.deb";
    sha256 = "1RO5yabSNpIz5lWXngMOZ1S2vtnLEkXIj1ZoIinRrQ0=";
  };

  nativeBuildInputs = [
    dpkg
    autoPatchelfHook
  ];

  dontUnpack = true;

  installPhase = ''
    runHook preInstall

    dpkg-deb -x $src $out
    mv $out/usr/* $out
    rmdir $out/usr

    # Fix ExecStart path and replace deprecated directory creation method,
    # use dynamic user.
    substituteInPlace "$out/lib/systemd/system/blackfire-agent.service" \
      --replace '/usr/' "$out/" \
      --replace 'ExecStartPre=/bin/mkdir -p /var/run/blackfire' 'RuntimeDirectory=blackfire' \
      --replace 'ExecStartPre=/bin/chown blackfire: /var/run/blackfire' "" \
      --replace 'User=blackfire' 'DynamicUser=yes' \
      --replace 'PermissionsStartOnly=true' ""

    # Modernize socket path.
    substituteInPlace "$out/etc/blackfire/agent" \
      --replace '/var/run' '/run'

    runHook postInstall
  '';

  passthru = {
    updateScript = writeShellScript "update-${pname}" ''
      export PATH="${lib.makeBinPath [ curl jq common-updater-scripts ]}"
      update-source-version "$UPDATE_NIX_ATTR_PATH" "$(curl https://blackfire.io/api/v1/releases | jq .cli --raw-output)"
    '';
  };

  meta = with lib; {
    description = "Blackfire Profiler agent and client";
    homepage = "https://blackfire.io/";
    license = licenses.unfree;
    maintainers = with maintainers; [ jtojnar ];
    platforms = [ "x86_64-linux" ];
  };
}