biglybt: 3.5.0.0 -> 3.6.0.0
[NixPkgs.git] / pkgs / development / tools / misc / blackfire / php-probe.nix
blob748a153624ab082fbebf3c8ede11aa8a6895efe6
1 { stdenv
2 , lib
3 , fetchurl
4 , autoPatchelfHook
5 , php
6 , writeShellScript
7 , curl
8 , jq
9 , common-updater-scripts
12 assert lib.assertMsg (!php.ztsSupport) "blackfire only supports non zts versions of PHP";
14 let
15   phpMajor = lib.versions.majorMinor php.version;
17   version = "1.92.13";
19   hashes = {
20     "x86_64-linux" = {
21       system = "amd64";
22       hash = {
23         "8.1" = "sha256-QpvnhIvjhm5tqOP72T2yVxV92M3ty/iDICaWsOVFpNg=";
24         "8.2" = "sha256-NhNbhOGRlhGvTcG4uZwTASWqLp7PQnfDW48GzROxkII=";
25         "8.3" = "sha256-Gn3M0ANj05QoAZB6W3HWj4zNCDya7lqa+OTv57fnEQ8=";
26       };
27     };
28     "i686-linux" = {
29       system = "i386";
30       hash = {
31         "8.1" = "sha256-zhCjSPTO/RGcc+qvkYlEeV+9ulIXpA0dCMRlSWwj8ys=";
32         "8.2" = "sha256-J+zdMC4q+MHmwADivqdEfSq8h/KeD5TAanCJKZLuEog=";
33         "8.3" = "sha256-GGNje7mg1uaLN3zrDXG/igLW9+nhxvPp7nIYW6aJBa4=";
34       };
35     };
36     "aarch64-linux" = {
37       system = "arm64";
38       hash = {
39         "8.1" = "sha256-C2ie8tp3F0sr+edYbUBVw0b1YJtnjyneC8/+x6LWENg=";
40         "8.2" = "sha256-Ku1pulSErVMvBtiNvLgRw2NpE/bEOkjZ5TY7F/PYJto=";
41         "8.3" = "sha256-/U/qf7Aqxssvcnc06+K5JeG96Ab09zRvUYcwhSAW4b8=";
42       };
43     };
44     "aarch64-darwin" = {
45       system = "arm64";
46       hash = {
47         "8.1" = "sha256-OdqG7G3TzuCVzBA0Xf+It05S6XaVlEd+ugM+gk70OiE=";
48         "8.2" = "sha256-/nCBQzimhcCrzNuwSVybHBmZZJImm75jKGqh2oXyyZA=";
49         "8.3" = "sha256-C2SxPYYXewU6PekQ3m1MBiPMPS5tE53gda2Qo7rZ1YQ=";
50       };
51     };
52     "x86_64-darwin" = {
53       system = "amd64";
54       hash = {
55         "8.1" = "sha256-W3reCFcN/bM3hrUeekJLG5qntH/Wvfb+JVly5+g2YEY=";
56         "8.2" = "sha256-d2YSmyV0mq7KBqoD4Bwdh3izh6hcKTBf6kP+q3QVnfI=";
57         "8.3" = "sha256-JiCw8Lew2laxOyb+2aSDqlZz2MafFwYwV46dqceEcBk=";
58       };
59     };
60   };
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     };
72 stdenv.mkDerivation (finalAttrs: {
73   pname = "php-blackfire";
74   extensionName = "blackfire";
75   inherit version;
77   src = makeSource {
78     system = stdenv.hostPlatform.system;
79     inherit phpMajor;
80   };
82   nativeBuildInputs = lib.optionals stdenv.isLinux [
83     autoPatchelfHook
84   ];
86   sourceRoot = ".";
88   dontUnpack = true;
90   installPhase = ''
91     runHook preInstall
93     install -D ${finalAttrs.src} $out/lib/php/extensions/blackfire.so
95     runHook postInstall
96   '';
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)
104       if [[ "${version}" = "$NEW_VERSION" ]]; then
105           echo "The new version same as the old version."
106           exit 0
107       fi
109       for source in ${lib.concatStringsSep " " (builtins.attrNames finalAttrs.passthru.updateables)}; do
110         update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "0" "sha256-${lib.fakeSha256}"
111         update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "$NEW_VERSION"
112       done
113     '';
115     # All sources for updating by the update script.
116     updateables =
117       let
118         createName = path:
119           builtins.replaceStrings [ "." ] [ "_" ] (lib.concatStringsSep "_" path);
121         createSourceParams = path:
122           let
123             # The path will be either [«system» sha256], or [«system» sha256 «phpMajor» «zts»],
124             # Let’s skip the sha256.
125             rest = builtins.tail (builtins.tail path);
126           in
127           {
128             system =
129               builtins.head path;
130             phpMajor =
131               if builtins.length rest == 0
132               then null
133               else builtins.head rest;
134           };
136         createUpdateable = path: _value:
137           lib.nameValuePair
138             (createName path)
139             (finalAttrs.finalPackage.overrideAttrs (attrs: {
140               src = makeSource (createSourceParams path);
141             }));
143         # Filter out all attributes other than hashes.
144         hashesOnly = lib.filterAttrsRecursive (name: _value: name != "system") hashes;
145       in
146       builtins.listToAttrs
147         # Collect all leaf attributes (containing hashes).
148         (lib.collect
149           (attrs: attrs ? name)
150           (lib.mapAttrsRecursive createUpdateable hashesOnly));
151   };
153   meta = {
154     description = "Blackfire Profiler PHP module";
155     homepage = "https://blackfire.io/";
156     license = lib.licenses.unfree;
157     maintainers = with lib.maintainers; [ shyim ];
158     platforms = [ "x86_64-linux" "aarch64-linux" "i686-linux" "x86_64-darwin" "aarch64-darwin" ];
159     sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
160   };