nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 stdenv,
3 lib,
4 fetchurl,
5 dpkg,
6 writeShellScript,
7 curl,
8 jq,
9 common-updater-scripts,
10}:
11
12stdenv.mkDerivation rec {
13 pname = "blackfire";
14 version = "2.28.29";
15
16 src =
17 passthru.sources.${stdenv.hostPlatform.system}
18 or (throw "Unsupported platform for blackfire: ${stdenv.hostPlatform.system}");
19
20 nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [
21 dpkg
22 ];
23
24 dontUnpack = true;
25
26 installPhase = ''
27 runHook preInstall
28
29 if ${lib.boolToString stdenv.hostPlatform.isLinux}
30 then
31 dpkg-deb -x $src $out
32 mv $out/usr/* $out
33 rmdir $out/usr
34
35 # Fix ExecStart path and replace deprecated directory creation method,
36 # use dynamic user.
37 substituteInPlace "$out/lib/systemd/system/blackfire-agent.service" \
38 --replace '/usr/' "$out/" \
39 --replace 'ExecStartPre=/bin/mkdir -p /var/run/blackfire' 'RuntimeDirectory=blackfire' \
40 --replace 'ExecStartPre=/bin/chown blackfire: /var/run/blackfire' "" \
41 --replace 'User=blackfire' 'DynamicUser=yes' \
42 --replace 'PermissionsStartOnly=true' ""
43
44 # Modernize socket path.
45 substituteInPlace "$out/etc/blackfire/agent" \
46 --replace '/var/run' '/run'
47 else
48 mkdir $out
49
50 tar -zxvf $src
51
52 mv etc $out
53 mv usr/* $out
54 fi
55
56 runHook postInstall
57 '';
58
59 passthru = {
60 sources = {
61 "x86_64-linux" = fetchurl {
62 url = "https://packages.blackfire.io/debian/pool/any/main/b/blackfire/blackfire_${version}_amd64.deb";
63 sha256 = "WIL8Y2pQq9vYuSI2fq2+T21HvjAd6PJPWKi4phKB5pw=";
64 };
65 "i686-linux" = fetchurl {
66 url = "https://packages.blackfire.io/debian/pool/any/main/b/blackfire/blackfire_${version}_i386.deb";
67 sha256 = "hcTVPb1zGrR3C1b5F2bgIzwH/lZV0ujeERNx0qt00Pc=";
68 };
69 "aarch64-linux" = fetchurl {
70 url = "https://packages.blackfire.io/debian/pool/any/main/b/blackfire/blackfire_${version}_arm64.deb";
71 sha256 = "7Qs47SjAhsOAIcCCCJk7jjDD1ab7CyjbPHfXl25z9mE=";
72 };
73 "aarch64-darwin" = fetchurl {
74 url = "https://packages.blackfire.io/blackfire/${version}/blackfire-darwin_arm64.pkg.tar.gz";
75 sha256 = "v4ApyuA9kMfqZAGVXPSSJJS0fm9lP2zz0iD8lf9VGa0=";
76 };
77 "x86_64-darwin" = fetchurl {
78 url = "https://packages.blackfire.io/blackfire/${version}/blackfire-darwin_amd64.pkg.tar.gz";
79 sha256 = "t78kpafSfbCA/0Kzhn/+/wjAet2qne33CYqFvRT0XUM=";
80 };
81 };
82
83 updateScript = writeShellScript "update-blackfire" ''
84 set -o errexit
85 export PATH="${
86 lib.makeBinPath [
87 curl
88 jq
89 common-updater-scripts
90 ]
91 }"
92 NEW_VERSION=$(curl -s https://blackfire.io/api/v1/releases | jq .cli --raw-output)
93
94 if [[ "${version}" = "$NEW_VERSION" ]]; then
95 echo "The new version same as the old version."
96 exit 0
97 fi
98
99 for platform in ${lib.escapeShellArgs meta.platforms}; do
100 update-source-version "blackfire" "$NEW_VERSION" --ignore-same-version --source-key="sources.$platform"
101 done
102 '';
103 };
104
105 meta = with lib; {
106 description = "Profiler agent and client";
107 homepage = "https://blackfire.io/";
108 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
109 license = licenses.unfree;
110 maintainers = with maintainers; [ shyim ];
111 platforms = [
112 "x86_64-linux"
113 "aarch64-linux"
114 "i686-linux"
115 "x86_64-darwin"
116 "aarch64-darwin"
117 ];
118 };
119}