Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ stdenv
2, lib
3, fetchurl
4, autoPatchelfHook
5, php
6, writeShellScript
7, curl
8, jq
9, common-updater-scripts
10}:
11
12assert lib.assertMsg (!php.ztsSupport) "blackfire only supports non zts versions of PHP";
13
14let
15 phpMajor = lib.versions.majorMinor php.version;
16
17 version = "1.92.20";
18
19 hashes = {
20 "x86_64-linux" = {
21 system = "amd64";
22 hash = {
23 "8.1" = "sha256-HAr+bSv7t7jJy5S9bReVF50EWLWzWmoLe4dCNFB0IJ4=";
24 "8.2" = "sha256-6twIng5yfLp+4ronaNzXjEVBnHVsd+Sz1ydURMQaRIo=";
25 "8.3" = "sha256-X0LzUHId08T1T4RUYSPyHP6pVot53B3tuvYsB3B9X6k=";
26 };
27 };
28 "i686-linux" = {
29 system = "i386";
30 hash = {
31 "8.1" = "sha256-YPVMQMuONZNFIGj3A0sSajXFaUj/NsDrH5+DVrOA1Uc=";
32 "8.2" = "sha256-ASStFQDrSEbaz+YE01ROBJ5NkRaGok/hYppKGFcEtQM=";
33 "8.3" = "sha256-ZOuwpGLV8Taek0XE13jkDG8sf+d+OBNIyOf9POtvpWo=";
34 };
35 };
36 "aarch64-linux" = {
37 system = "arm64";
38 hash = {
39 "8.1" = "sha256-PQ+H6EqufUM3GoFUUf42Yj8mLxuDqvz4ml3/khuriag=";
40 "8.2" = "sha256-3JeZAst2jwyA7ZzaEl/7WN1D0VqkGCg8UtJTmcwVBEg=";
41 "8.3" = "sha256-wQOg1TUG0+Ld3xJ1OvpiKAaFuPe7Vbr+D/G70FSGo4c=";
42 };
43 };
44 "aarch64-darwin" = {
45 system = "arm64";
46 hash = {
47 "8.1" = "sha256-o9YXtRuEYyp6a03z9v1F0C3KlaQx3Y4q7JIw6vvkPVo=";
48 "8.2" = "sha256-7PWqR83ir2h89wuovLOoCup+dkqz+ggXN5HzF0KYGMY=";
49 "8.3" = "sha256-SFG/lqD4iR8iDZTFGcu3t6BeFm3ZDtUiPP52trWrEEw=";
50 };
51 };
52 "x86_64-darwin" = {
53 system = "amd64";
54 hash = {
55 "8.1" = "sha256-n4RIoBpOCfp5lugG6gzkCGRjycbs/JHUqzQAA2D3OU8=";
56 "8.2" = "sha256-jNzjOIUZfiXuYIpk4Wtx4C1P05rPgl+8rKqSMj8iD1I=";
57 "8.3" = "sha256-rMd/KOwuPRoHZC97OJppiFgUZ2xyBDPzire7y5D+q/Q=";
58 };
59 };
60 };
61
62 makeSource = { system, phpMajor }:
63 let
64 isLinux = builtins.match ".+-linux" system != null;
65 in
66 assert !isLinux -> (phpMajor != null);
67 fetchurl {
68 url = "https://packages.blackfire.io/binaries/blackfire-php/${version}/blackfire-php-${if isLinux then "linux" else "darwin"}_${hashes.${system}.system}-php-${builtins.replaceStrings [ "." ] [ "" ] phpMajor}.so";
69 hash = hashes.${system}.hash.${phpMajor};
70 };
71in
72stdenv.mkDerivation (finalAttrs: {
73 pname = "php-blackfire";
74 extensionName = "blackfire";
75 inherit version;
76
77 src = makeSource {
78 system = stdenv.hostPlatform.system;
79 inherit phpMajor;
80 };
81
82 nativeBuildInputs = lib.optionals stdenv.isLinux [
83 autoPatchelfHook
84 ];
85
86 sourceRoot = ".";
87
88 dontUnpack = true;
89
90 installPhase = ''
91 runHook preInstall
92
93 install -D ${finalAttrs.src} $out/lib/php/extensions/blackfire.so
94
95 runHook postInstall
96 '';
97
98 passthru = {
99 updateScript = writeShellScript "update-${finalAttrs.pname}" ''
100 set -o errexit
101 export PATH="${lib.makeBinPath [ curl jq common-updater-scripts ]}"
102 NEW_VERSION=$(curl --silent https://blackfire.io/api/v1/releases | jq .probe.php --raw-output)
103
104 if [[ "${version}" = "$NEW_VERSION" ]]; then
105 echo "The new version same as the old version."
106 exit 0
107 fi
108
109 for source in ${lib.concatStringsSep " " (builtins.attrNames finalAttrs.passthru.updateables)}; do
110 update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "$NEW_VERSION" --ignore-same-version
111 done
112 '';
113
114 # All sources for updating by the update script.
115 updateables =
116 let
117 createName = path:
118 builtins.replaceStrings [ "." ] [ "_" ] (lib.concatStringsSep "_" path);
119
120 createSourceParams = path:
121 let
122 # The path will be either [«system» sha256], or [«system» sha256 «phpMajor» «zts»],
123 # Let’s skip the sha256.
124 rest = builtins.tail (builtins.tail path);
125 in
126 {
127 system =
128 builtins.head path;
129 phpMajor =
130 if builtins.length rest == 0
131 then null
132 else builtins.head rest;
133 };
134
135 createUpdateable = path: _value:
136 lib.nameValuePair
137 (createName path)
138 (finalAttrs.finalPackage.overrideAttrs (attrs: {
139 src = makeSource (createSourceParams path);
140 }));
141
142 # Filter out all attributes other than hashes.
143 hashesOnly = lib.filterAttrsRecursive (name: _value: name != "system") hashes;
144 in
145 builtins.listToAttrs
146 # Collect all leaf attributes (containing hashes).
147 (lib.collect
148 (attrs: attrs ? name)
149 (lib.mapAttrsRecursive createUpdateable hashesOnly));
150 };
151
152 meta = {
153 description = "Blackfire Profiler PHP module";
154 homepage = "https://blackfire.io/";
155 license = lib.licenses.unfree;
156 maintainers = with lib.maintainers; [ shyim ];
157 platforms = [ "x86_64-linux" "aarch64-linux" "i686-linux" "x86_64-darwin" "aarch64-darwin" ];
158 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
159 };
160})