nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 stdenv,
3 lib,
4 fetchurl,
5 autoPatchelfHook,
6 php,
7 writeShellScript,
8 curl,
9 jq,
10 common-updater-scripts,
11}:
12
13assert lib.assertMsg (!php.ztsSupport) "blackfire only supports non zts versions of PHP";
14
15let
16 phpMajor = lib.versions.majorMinor php.version;
17 inherit (stdenv.hostPlatform) system;
18
19 version = "1.92.40";
20
21 hashes = {
22 "x86_64-linux" = {
23 system = "amd64";
24 hash = {
25 "8.1" = "sha256-5yfhpseazq9XADYR4/Wo3xg6jGNbSdFrTn+cP+pCbN4=";
26 "8.2" = "sha256-ipUXh7pV9qiol6j9PpOyAyxriHDpBHDWin/dIxl4AqA=";
27 "8.3" = "sha256-6JcS+aTYhT14D2/wwxJad4MnsilgSjsckSzsx+lVvOM=";
28 "8.4" = "sha256-XYcRjHRLhF3f8INEnyGNnhrZlwQGt0wIdGtY3TTnA7s=";
29 };
30 };
31 "i686-linux" = {
32 system = "i386";
33 hash = {
34 "8.1" = "sha256-+ApXqJCew4/LKNc+nzDDat+jyqCs8P/kX7Sxt7fAnIE=";
35 "8.2" = "sha256-IxarxqbjA3Rei7eR/AUSOHSCoLAsHPwebIXQJYW05Ig=";
36 "8.3" = "sha256-HZAOO+VnK3qax/++jAKllHSbCVAgUeEmlSr/HVsXPQY=";
37 "8.4" = "sha256-uRG07BkUmZFMvMzVsuF0qRF/wv74QqP2YtGV1Emgcsg=";
38 };
39 };
40 "aarch64-linux" = {
41 system = "arm64";
42 hash = {
43 "8.1" = "sha256-PkXmLsLwNF132SM+aOA1mfc+6EoaBlwpgoKTKXE0JFI=";
44 "8.2" = "sha256-edsH+Xb0lrw9Dg1aHHtjRGMjGS7+ZDxk/IJFZt5A5ho=";
45 "8.3" = "sha256-uP7bY8Pw/1GNdTd897eqsiVfQKr5HLVJ1BVHIloVdRA=";
46 "8.4" = "sha256-5MqridoL7fcMXnmC+XJoj3opkmrO1dVQWbZE1ot5y+E=";
47 };
48 };
49 "aarch64-darwin" = {
50 system = "arm64";
51 hash = {
52 "8.1" = "sha256-G2Zq6n1Ndx5MN3hbDlPDpT+wpNcYBm+mMnbnVNfAHvw=";
53 "8.2" = "sha256-9i65PvfjmyFWmgjQPyYRRLV/SOX88tFub2+XmnRlgVA=";
54 "8.3" = "sha256-Lf1p55Ae9pddT3Z82h7p/9jC7zN5Md3hOzXXLu/kDjM=";
55 "8.4" = "sha256-A3k/IEyDoLmGcJzl60nclB8f+lUmvWXKF851ZMpgwfM=";
56 };
57 };
58 "x86_64-darwin" = {
59 system = "amd64";
60 hash = {
61 "8.1" = "sha256-3uCvCbkpaawMnW6IXS9VPp8GU4SOwqh/9oxcP1W3h2E=";
62 "8.2" = "sha256-PCnUHwtNex9juVL5evY37qyuDRguZs4ByOfOnY7HQs0=";
63 "8.3" = "sha256-/3XZPG8+O71sbrVPDg0Thn+pTPGNYBTkJ3s/txI0Q3k=";
64 "8.4" = "sha256-XY2rS2p1WAVp1Rd1V8JUnCiTQe2WouLwlmtZTnRqs04=";
65 };
66 };
67 };
68
69 makeSource =
70 { system, phpMajor }:
71 let
72 isLinux = builtins.match ".+-linux" system != null;
73 in
74 fetchurl {
75 url = "https://packages.blackfire.io/binaries/blackfire-php/${version}/blackfire-php-${
76 if isLinux then "linux" else "darwin"
77 }_${hashes.${system}.system}-php-${builtins.replaceStrings [ "." ] [ "" ] phpMajor}.so";
78 hash = hashes.${system}.hash.${phpMajor};
79 };
80in
81
82assert lib.assertMsg (
83 hashes ? ${system}.hash.${phpMajor}
84) "blackfire does not support PHP version ${phpMajor} on ${system}.";
85
86stdenv.mkDerivation (finalAttrs: {
87 pname = "php-blackfire";
88 extensionName = "blackfire";
89 inherit version;
90
91 src = makeSource {
92 inherit system phpMajor;
93 };
94
95 nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [
96 autoPatchelfHook
97 ];
98
99 sourceRoot = ".";
100
101 dontUnpack = true;
102
103 installPhase = ''
104 runHook preInstall
105
106 install -D ${finalAttrs.src} $out/lib/php/extensions/blackfire.so
107
108 runHook postInstall
109 '';
110
111 passthru = {
112 updateScript = writeShellScript "update-${finalAttrs.pname}" ''
113 set -o errexit
114 export PATH="${
115 lib.makeBinPath [
116 curl
117 jq
118 common-updater-scripts
119 ]
120 }"
121 NEW_VERSION=$(curl --silent https://blackfire.io/api/v1/releases | jq .probe.php --raw-output)
122
123 if [[ "${version}" = "$NEW_VERSION" ]]; then
124 echo "The new version same as the old version."
125 exit 0
126 fi
127
128 for source in ${lib.concatStringsSep " " (builtins.attrNames finalAttrs.passthru.updateables)}; do
129 update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "$NEW_VERSION" --ignore-same-version
130 done
131 '';
132
133 # All sources for updating by the update script.
134 updateables =
135 let
136 createName =
137 { phpMajor, system }: "php${builtins.replaceStrings [ "." ] [ "" ] phpMajor}_${system}";
138
139 createUpdateable =
140 sourceParams:
141 lib.nameValuePair (createName sourceParams) (
142 finalAttrs.finalPackage.overrideAttrs (attrs: {
143 src = makeSource sourceParams;
144 })
145 );
146 in
147 lib.concatMapAttrs (
148 system:
149 { hash, ... }:
150
151 lib.mapAttrs' (phpMajor: _hash: createUpdateable { inherit phpMajor system; }) hash
152 ) hashes;
153 };
154
155 meta = {
156 description = "Blackfire Profiler PHP module";
157 homepage = "https://blackfire.io/";
158 license = lib.licenses.unfree;
159 maintainers = with lib.maintainers; [ shyim ];
160 platforms = [
161 "x86_64-linux"
162 "aarch64-linux"
163 "i686-linux"
164 "x86_64-darwin"
165 "aarch64-darwin"
166 ];
167 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
168 };
169})