nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv
2, lib
3, fetchurl
4, dpkg
5, autoPatchelfHook
6, php
7, writeShellScript
8, curl
9, jq
10, common-updater-scripts
11}:
12
13let
14 phpMajor = lib.versions.majorMinor php.version;
15
16 version = "1.87.2";
17
18 hashes = {
19 "x86_64-linux" = {
20 system = "amd64";
21 sha256 = {
22 "8.0" = "ylzxQlyk6jpyO9Zcqv/uUiRWcMSkPKFBgiCDnyU8lWI=";
23 "8.1" = "FEb0NBJpwoYaNdEHEn4TkSQR7VShGpHptaDIRKwrmkQ=";
24 "8.2" = "itB0Zm1Mog18F8vIHn9AZMYMzafLQR0v5zcOgqy1ouI=";
25 };
26 };
27 "i686-linux" = {
28 system = "i386";
29 sha256 = {
30 "8.0" = "DL5wiaez4tzrn8xY+ptYiCvZ1HWaStT9vGWPd5whTaE=";
31 "8.1" = "0bX2frll0ne6H6o7HNH4TRV2D+NDe11mVvqwhvSDg9E=";
32 "8.2" = "U6zmbEkRr3+9yVwUgQ1+SBNK0zWD92S2KBOHJ1gMmjM=";
33 };
34 };
35 "aarch64-linux" = {
36 system = "arm64";
37 sha256 = {
38 "8.0" = "R6zdOw/K+/YPYzSEOEyz83hqiLHCM4EOjz2tLrJOPlE=";
39 "8.1" = "agLQVI3u7ENcWLDRx7YSEBZobRnwEaKAmFpIU5AXhqo=";
40 "8.2" = "Y2bUYaymoZ/Ct5a7K+5U+zNh9ZKUaq0Oal/v04nzuaU=";
41 };
42 };
43 "aarch64-darwin" = {
44 system = "arm64";
45 sha256 = {
46 "8.0" = "XcFU1lq694aLIn1HQdDSg2Zx68/fLew3GjkTLsxHYvk=";
47 "8.1" = "ovTtwXPut9jCvxVyd5mQzrfJPCy+rQvUi4c74NrBzY4=";
48 "8.2" = "8hybE62l8vSwbqpcrnj/lI2Wjy8R3wuO04zwofLi9EY=";
49 };
50 };
51 "x86_64-darwin" = {
52 system = "amd64";
53 sha256 = {
54 "8.0" = "F4mIvjyf3Zi3icKcPe6KP2gR9jeC7EJskw9TfsTHz6Y=";
55 "8.1" = "WsHH/XJboHeRhxpYY0WtXEJwOsGNFtfexBShC/J7GaQ=";
56 "8.2" = "w3Vu7CTFebn59i1FYVCYHiOadTIPlPCkQ1QHEfvHWig=";
57 };
58 };
59 };
60
61 makeSource =
62 {
63 system,
64 phpMajor,
65 }:
66
67 let
68 isLinux = builtins.match ".+-linux" system != null;
69 in
70 assert !isLinux -> (phpMajor != null);
71 fetchurl {
72 url =
73 "https://packages.blackfire.io/binaries/blackfire-php/${version}/blackfire-php-${if isLinux then "linux" else "darwin"}_${hashes.${system}.system}-php-${builtins.replaceStrings [ "." ] [ "" ] phpMajor}.so";
74 sha256 = hashes.${system}.sha256.${phpMajor};
75 };
76self = stdenv.mkDerivation rec {
77 pname = "php-blackfire";
78 extensionName = "blackfire";
79 inherit version;
80
81 src = makeSource {
82 system = stdenv.hostPlatform.system;
83 inherit phpMajor;
84 inherit (php);
85 };
86
87 nativeBuildInputs = lib.optionals stdenv.isLinux [
88 autoPatchelfHook
89 ];
90
91 setSourceRoot = "sourceRoot=`pwd`";
92
93 dontUnpack = true;
94
95 installPhase = ''
96 runHook preInstall
97
98 install -D ${src} $out/lib/php/extensions/blackfire.so
99
100 runHook postInstall
101 '';
102
103 passthru = {
104 updateScript = writeShellScript "update-${pname}" ''
105 set -o errexit
106 export PATH="${lib.makeBinPath [ curl jq common-updater-scripts ]}"
107 NEW_VERSION=$(curl --silent https://blackfire.io/api/v1/releases | jq .probe.php --raw-output)
108
109 if [[ "${version}" = "$NEW_VERSION" ]]; then
110 echo "The new version same as the old version."
111 exit 0
112 fi
113
114 for source in ${lib.concatStringsSep " " (builtins.attrNames passthru.updateables)}; do
115 update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "0" "${lib.fakeSha256}"
116 update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "$NEW_VERSION"
117 done
118 '';
119
120 # All sources for updating by the update script.
121 updateables =
122 let
123 createName =
124 path:
125
126 builtins.replaceStrings [ "." ] [ "_" ] (lib.concatStringsSep "_" path);
127
128 createSourceParams =
129 path:
130
131 let
132 # The path will be either [«system» sha256], or [«system» sha256 «phpMajor» «zts»],
133 # Let’s skip the sha256.
134 rest = builtins.tail (builtins.tail path);
135 in {
136 system =
137 builtins.head path;
138 phpMajor =
139 if builtins.length rest == 0
140 then null
141 else builtins.head rest;
142 };
143
144 createUpdateable =
145 path:
146 _value:
147
148 lib.nameValuePair
149 (createName path)
150 (self.overrideAttrs (attrs: {
151 src = makeSource (createSourceParams path);
152 }));
153
154 hashesOnly =
155 # Filter out all attributes other than hashes.
156 lib.filterAttrsRecursive (name: _value: name != "system") hashes;
157 in
158 builtins.listToAttrs
159 # Collect all leaf attributes (containing hashes).
160 (lib.collect
161 (attrs: attrs ? name)
162 (lib.mapAttrsRecursive createUpdateable hashesOnly));
163 };
164
165 meta = with lib; {
166 description = "Blackfire Profiler PHP module";
167 homepage = "https://blackfire.io/";
168 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
169 license = licenses.unfree;
170 maintainers = with maintainers; [ shyim ];
171 platforms = [ "x86_64-linux" "aarch64-linux" "i686-linux" "x86_64-darwin" "aarch64-darwin" ];
172 };
173};
174in
175self