Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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.86.8";
17
18 hashes = {
19 "x86_64-linux" = {
20 system = "amd64";
21 sha256 = {
22 "8.0" = "zoT9f906lvMTyq+w7BAqwA3Wnadk0hEsc9KLYuffE8c=";
23 "8.1" = "KJB3/BlS8FCDg3CEaYf14RJk3xhda1K2XEPVylSRFTQ=";
24 "8.2" = "PrhPtYUkz+Zs4ctIJUsHlUqLHZDfXNMc7s6uA5RJNVI=";
25 };
26 };
27 "i686-linux" = {
28 system = "i386";
29 sha256 = {
30 "8.0" = "IByOPOvzJZOR9hw6Ngn81XtXBczRPLswDA4Mvh8dQdQ=";
31 "8.1" = "Mob30xhKWaREiqw3cjlrz0jtAc9onERT6NxTz9bUSSY=";
32 "8.2" = "a7paFrgLfMLvcQRcHPi+sJ61XTjphcba+tewrJw0OnE=";
33 };
34 };
35 "aarch64-linux" = {
36 system = "arm64";
37 sha256 = {
38 "8.0" = "6ZhFRjjj/y3yyH2PXVnw+Mhkm2trfpysxfXocH5nx48=";
39 "8.1" = "x2TGaehSJmgJJcapr6xBO9Svo1HE66eVRHt/Ab+RSzQ=";
40 "8.2" = "YUs8h/DBwaNvmYA9TS7l0skg+X4yBzcHbPH4QXeSdCI=";
41 };
42 };
43 "aarch64-darwin" = {
44 system = "arm64";
45 sha256 = {
46 "8.0" = "HZV7I8HOWvGwV9kMuSBW1/vgs+plxYLvbVs/d8aNNfE=";
47 "8.1" = "PsHDB/P/vbdpqbLl12UqelHfvHHt2WxiWEUCV7s5ZJg=";
48 "8.2" = "pEkFLhjWOLquBcxE06Gv7HUB/lPU8cPajhsFc0kcKlA=";
49 };
50 };
51 "x86_64-darwin" = {
52 system = "amd64";
53 sha256 = {
54 "8.0" = "VOi901nkVNjHSk02HNk6/z9q3avs+doHWL+Zxxruc6k=";
55 "8.1" = "TVV9Iysueo1M2WaaX6CF52WzMfJJ96gOIxuy1mIA6ao=";
56 "8.2" = "XOcjZes3JNfulJimdCTkipiRzrJ/237SSfqNAelVPNU=";
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