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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
{ stdenv
, lib
, fetchurl
, dpkg
, autoPatchelfHook
, php
, writeShellScript
, curl
, jq
, common-updater-scripts
}:
let
phpMajor = lib.versions.majorMinor php.version;
soFile = {
"7.4" = "blackfire-20190902";
"8.0" = "blackfire-20200930";
"8.1" = "blackfire-20210902";
}.${phpMajor} or (throw "Unsupported PHP version.");
version = "1.77.0";
hashes = {
"x86_64-linux" = {
system = "amd64";
sha256 = "oC4pANYT2XtF3ju+pT2TCb6iJSlNm6t+Xkawb88xWUo=";
};
"i686-linux" = {
system = "i386";
sha256 = "zdebak5RWuPqCJ3eReKjtDLnCXtjtVFnSqvqC4U0+RE=";
};
"aarch64-linux" = {
system = "arm64";
sha256 = "5J1JcD/ZFxV0FWaySv037x1xjmCdM/zHiBfmRuCidjs=";
};
"aarch64-darwin" = {
system = "arm64";
sha256 = {
"7.4" = {
normal = "vKOH+yPDyf8KxX0DoEnrp2HXYfDAxVD708MZrRGMEEk=";
zts = "cpeOtDRhPA35utai8G1Dosuqhf76hiqvwe+Em9cFhDo=";
};
"8.0" = {
normal = "v6PD1+Ghvtoq1wzAXwqi9elyC9/NwzX0EDdtQtCfeL4=";
zts = "Dqs0P8X7ScDJCPYKuqlumnLz4kB7cEOnVbDACQ02sko=";
};
"8.1" = {
normal = "mCZ1avC8FsqYdGYNepeqWgSK2kqVo1E0VjhofxdaSyk=";
zts = "zliaM2VbaDEgNBr5ETe1GdYNyTZy5te92LedZiolx/8=";
};
};
};
"x86_64-darwin" = {
system = "amd64";
sha256 = {
"7.4" = {
normal = "nLsrpRnR9zo3d/a0+TFBlNcAebknpBQc101ysqPs+dU=";
zts = "o7R8zmhIOtiNDS8Se3Dog+cn9HyTHzS4jquXdzGQQOU=";
};
"8.0" = {
normal = "Pe2/GNDiS5DuSXCffO0jo5dRl0qkh1RgBVL3JzLwVkQ=";
zts = "zu7QgaKbBNQkby7bLv+NKLSIa79UXMONEf171EO+uNE=";
};
"8.1" = {
normal = "3SOlLeLCM4crWY6U+/zmtWmNYg2j0HC/3FWCmCi7lOo=";
zts = "GG8s+Pd0K6SEUzRV96Ba2mYfLgQMuGNzRoUtmz9m0NY=";
};
};
};
};
makeSource =
{
system,
phpMajor,
ztsSupport,
}:
let
isLinux = builtins.match ".+-linux" system != null;
in
assert !isLinux -> (phpMajor != null && ztsSupport != null);
fetchurl {
url =
if isLinux
then "https://packages.blackfire.io/debian/pool/any/main/b/blackfire-php/blackfire-php_${version}_${hashes.${system}.system}.deb"
else "https://packages.blackfire.io/homebrew/blackfire-php_${version}-darwin_${hashes.${system}.system}-php${builtins.replaceStrings ["."] [""] phpMajor}${lib.optionalString ztsSupport "-zts"}.tar.gz";
sha256 =
if isLinux
then hashes.${system}.sha256
else hashes.${system}.sha256.${phpMajor}.${if ztsSupport then "zts" else "normal"};
};
self = stdenv.mkDerivation rec {
pname = "php-blackfire";
inherit version;
src = makeSource {
system = stdenv.hostPlatform.system;
inherit phpMajor;
inherit (php) ztsSupport;
};
nativeBuildInputs = lib.optionals stdenv.isLinux [
dpkg
autoPatchelfHook
];
setSourceRoot = if stdenv.isDarwin then "sourceRoot=`pwd`" else null;
unpackPhase = if stdenv.isLinux then ''
runHook preUnpack
dpkg-deb -x $src pkg
sourceRoot=pkg
runHook postUnpack
'' else null;
installPhase = ''
runHook preInstall
if ${ lib.boolToString stdenv.isLinux }
then
install -D usr/lib/blackfire-php/*/${soFile}${lib.optionalString php.ztsSupport "-zts"}.so $out/lib/php/extensions/blackfire.so
else
install -D blackfire.so $out/lib/php/extensions/blackfire.so
fi
runHook postInstall
'';
passthru = {
updateScript = writeShellScript "update-${pname}" ''
set -o errexit
export PATH="${lib.makeBinPath [ curl jq common-updater-scripts ]}"
NEW_VERSION=$(curl --silent https://blackfire.io/api/v1/releases | jq .probe.php --raw-output)
if [[ "${version}" = "$NEW_VERSION" ]]; then
echo "The new version same as the old version."
exit 0
fi
for source in ${lib.concatStringsSep " " (builtins.attrNames passthru.updateables)}; do
update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "0" "${lib.fakeSha256}"
update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "$NEW_VERSION"
done
'';
# All sources for updating by the update script.
updateables =
let
createName =
path:
builtins.replaceStrings [ "." ] [ "_" ] (lib.concatStringsSep "_" path);
createSourceParams =
path:
let
# The path will be either [«system» sha256], or [«system» sha256 «phpMajor» «zts»],
# Let’s skip the sha256.
rest = builtins.tail (builtins.tail path);
in {
system =
builtins.head path;
phpMajor =
if builtins.length rest == 0
then null
else builtins.head rest;
ztsSupport =
if builtins.length rest == 0
then null
else
builtins.head (builtins.tail rest) == "zts";
};
createUpdateable =
path:
_value:
lib.nameValuePair
(createName path)
(self.overrideAttrs (attrs: {
src = makeSource (createSourceParams path);
}));
hashesOnly =
# Filter out all attributes other than hashes.
lib.filterAttrsRecursive (name: _value: name != "system") hashes;
in
builtins.listToAttrs
# Collect all leaf attributes (containing hashes).
(lib.collect
(attrs: attrs ? name)
(lib.mapAttrsRecursive createUpdateable hashesOnly));
};
meta = with lib; {
description = "Blackfire Profiler PHP module";
homepage = "https://blackfire.io/";
license = licenses.unfree;
maintainers = with maintainers; [ jtojnar shyim ];
platforms = [ "x86_64-linux" "aarch64-linux" "i686-linux" "x86_64-darwin" "aarch64-darwin" ];
};
};
in
self
|