at 23.11-beta 154 lines 4.6 kB view raw
1{ stdenv 2, lib 3, fetchurl 4, autoPatchelfHook 5, php 6, writeShellScript 7, curl 8, jq 9, common-updater-scripts 10}: 11 12let 13 phpMajor = lib.versions.majorMinor php.version; 14 15 version = "1.91.0"; 16 17 hashes = { 18 "x86_64-linux" = { 19 system = "amd64"; 20 hash = { 21 "8.1" = "sha256-PIpfTeHWVO8MJ4+c8o1iC477M+HXzuHbnwv1EkYkQHY="; 22 "8.2" = "sha256-wEdEFooXlJTeuVfMeX3OI3uKJ5Acj1ZqmVYt6fyGQXI="; 23 }; 24 }; 25 "i686-linux" = { 26 system = "i386"; 27 hash = { 28 "8.1" = "sha256-yEfWtUegN4HVRS95eY3vYA97iGAaY2gxoGtb9DZpXhY="; 29 "8.2" = "sha256-FGbgozRmniS/rtAcvPiA+w8miauc8Gr/np5NdP4iGT8="; 30 }; 31 }; 32 "aarch64-linux" = { 33 system = "arm64"; 34 hash = { 35 "8.1" = "sha256-zfVx3NGkjhZK7YjTi8FBJyrn++Ub7vlFDCmiY/7F/yE="; 36 "8.2" = "sha256-gMoBIsvnR6lQMT4IaHWJEp+GbU/Yiid+pmDejR/vAUA="; 37 }; 38 }; 39 "aarch64-darwin" = { 40 system = "arm64"; 41 hash = { 42 "8.1" = "sha256-UDd4knBfgdUriJ6N1cfka/iCIjaWiOgIbrq6kNkYUjA="; 43 "8.2" = "sha256-BZzFVLfebKzuSDz2DQEwd9HOxJ1nZSNmQHpayiGe8qI="; 44 }; 45 }; 46 "x86_64-darwin" = { 47 system = "amd64"; 48 hash = { 49 "8.1" = "sha256-51w3Ji8R6ulloZuTPHu/0gkYiq33H1tMOwrGe2DWtRI="; 50 "8.2" = "sha256-0p6CNKjhdD3L6x6gtMKLTKrHUO4LMwXpVU7hR32ejMI="; 51 }; 52 }; 53 }; 54 55 makeSource = { system, phpMajor }: 56 let 57 isLinux = builtins.match ".+-linux" system != null; 58 in 59 assert !isLinux -> (phpMajor != null); 60 fetchurl { 61 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"; 62 hash = hashes.${system}.hash.${phpMajor}; 63 }; 64in 65stdenv.mkDerivation (finalAttrs: { 66 pname = "php-blackfire"; 67 extensionName = "blackfire"; 68 inherit version; 69 70 src = makeSource { 71 system = stdenv.hostPlatform.system; 72 inherit phpMajor; 73 }; 74 75 nativeBuildInputs = lib.optionals stdenv.isLinux [ 76 autoPatchelfHook 77 ]; 78 79 sourceRoot = "."; 80 81 dontUnpack = true; 82 83 installPhase = '' 84 runHook preInstall 85 86 install -D ${finalAttrs.src} $out/lib/php/extensions/blackfire.so 87 88 runHook postInstall 89 ''; 90 91 passthru = { 92 updateScript = writeShellScript "update-${finalAttrs.pname}" '' 93 set -o errexit 94 export PATH="${lib.makeBinPath [ curl jq common-updater-scripts ]}" 95 NEW_VERSION=$(curl --silent https://blackfire.io/api/v1/releases | jq .probe.php --raw-output) 96 97 if [[ "${version}" = "$NEW_VERSION" ]]; then 98 echo "The new version same as the old version." 99 exit 0 100 fi 101 102 for source in ${lib.concatStringsSep " " (builtins.attrNames finalAttrs.passthru.updateables)}; do 103 update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "0" "sha256-${lib.fakeSha256}" 104 update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "$NEW_VERSION" 105 done 106 ''; 107 108 # All sources for updating by the update script. 109 updateables = 110 let 111 createName = path: 112 builtins.replaceStrings [ "." ] [ "_" ] (lib.concatStringsSep "_" path); 113 114 createSourceParams = path: 115 let 116 # The path will be either [«system» sha256], or [«system» sha256 «phpMajor» «zts»], 117 # Let’s skip the sha256. 118 rest = builtins.tail (builtins.tail path); 119 in 120 { 121 system = 122 builtins.head path; 123 phpMajor = 124 if builtins.length rest == 0 125 then null 126 else builtins.head rest; 127 }; 128 129 createUpdateable = path: _value: 130 lib.nameValuePair 131 (createName path) 132 (finalAttrs.finalPackage.overrideAttrs (attrs: { 133 src = makeSource (createSourceParams path); 134 })); 135 136 # Filter out all attributes other than hashes. 137 hashesOnly = lib.filterAttrsRecursive (name: _value: name != "system") hashes; 138 in 139 builtins.listToAttrs 140 # Collect all leaf attributes (containing hashes). 141 (lib.collect 142 (attrs: attrs ? name) 143 (lib.mapAttrsRecursive createUpdateable hashesOnly)); 144 }; 145 146 meta = { 147 description = "Blackfire Profiler PHP module"; 148 homepage = "https://blackfire.io/"; 149 license = lib.licenses.unfree; 150 maintainers = with lib.maintainers; [ shyim ]; 151 platforms = [ "x86_64-linux" "aarch64-linux" "i686-linux" "x86_64-darwin" "aarch64-darwin" ]; 152 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; 153 }; 154})