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