at master 6.1 kB view raw
1{ 2 stdenv, 3 lib, 4 fetchurl, 5 php, 6 openssl, 7 hiredis, 8 libck, 9 zstd, 10 lz4, 11 autoPatchelfHook, 12 writeShellScript, 13 curl, 14 common-updater-scripts, 15}: 16 17let 18 version = "0.11.1"; 19 hashes = { 20 "aarch64-darwin" = { 21 platform = "darwin-arm64"; 22 hash = { 23 "8.1" = "sha256-m7WWbrOwKH/IV4mCtmxzkNaBeKwUe89QlSMNxUAbq5A="; 24 "8.2" = "sha256-ytYYtxo43H8GTDOiLpBPtJmvoi4Q9rpJ2uY0AQWm2Dg="; 25 "8.3" = "12UvfJhJn3B70Q3xxfKfAzOH/fyC/ZftC4RMWGsEO88="; 26 "8.4" = "sha256-TszXByZtkJZ0uf1BFX2RJXQqfJFPzW1CokxRFnLBZpI="; 27 "8.5" = "WYJKnDuqsprgtev5g/LGcFbZTphEcCZb6/zanur4g8U="; 28 }; 29 }; 30 "aarch64-linux" = { 31 platform = "debian-aarch64+libssl3"; 32 hash = { 33 "8.1" = "sha256-e8eeQhzMLoXo1UaqFkSYMOwnkiNo7Fp8mKjVJY3SJIY="; 34 "8.2" = "sha256-dYkX4zV3lOwveMrZHLs2a7P+T3AGMv3dZNVUujpzJ9Q="; 35 "8.3" = "sha256-hU9jgz6gCWDSeoqWMznmNipfcMk7Ju7leRdSYFTl+Go="; 36 "8.4" = "gsSNY8cxWHPCm3UZNyhk9qs+9BgnnFLjeFIiksOG2A4="; 37 "8.5" = "M0SRivsTn1wQVuOt4v8F+OynZBpUkUJLR/E59veyH+Y="; 38 }; 39 }; 40 "x86_64-linux" = { 41 platform = "debian-x86-64+libssl3"; 42 hash = { 43 "8.1" = "sha256-poEjqvCVvdWmO2pw7jon+nzK52itsBfRkxcIjpHEa0M="; 44 "8.2" = "sha256-0xKV0Ro5VDaLU45BFiVhwT/a7Y7jeL7DerTmVLB0glo="; 45 "8.3" = "sha256-LggNCDl9vYXNPhIZpgeZ4h3nzddBg7FgzzJmcD+1nIA="; 46 "8.4" = "FGgHJWqlLIPXs1UBXEfgTyL6EHuP5P4fnMjop8QVmzo="; 47 "8.5" = "C5YrgTyag2ug+8sQIt7KolhXv1y63D6aSABrwU1HlWs="; 48 }; 49 }; 50 }; 51 52 makeSource = 53 { system, phpMajor }: 54 fetchurl { 55 url = 56 "https://builds.r2.relay.so/v${version}/relay-v${version}-php" 57 + phpMajor 58 + "-" 59 + hashes.${system}.platform 60 + ".tar.gz"; 61 sha256 = 62 hashes.${system}.hash.${phpMajor} 63 or (throw "Unsupported PHP version for relay ${phpMajor} on ${system}"); 64 }; 65in 66stdenv.mkDerivation (finalAttrs: { 67 inherit version; 68 pname = "relay"; 69 extensionName = "relay"; 70 71 src = makeSource { 72 system = stdenv.hostPlatform.system; 73 phpMajor = lib.versions.majorMinor php.version; 74 }; 75 nativeBuildInputs = lib.optionals (!stdenv.hostPlatform.isDarwin) [ autoPatchelfHook ]; 76 buildInputs = lib.optionals (!stdenv.hostPlatform.isDarwin) [ 77 hiredis 78 libck 79 openssl 80 zstd 81 lz4 82 ]; 83 internalDeps = [ php.extensions.session ]; 84 installPhase = '' 85 runHook preInstall 86 install -Dm755 relay.so -t $out/lib/php/extensions 87 '' 88 + ( 89 if stdenv.hostPlatform.isDarwin then 90 let 91 args = 92 lib.strings.concatMapStrings 93 ( 94 v: 95 " -change ${v.name}" + " ${lib.strings.makeLibraryPath [ v.value ]}/${builtins.baseNameOf v.name}" 96 ) 97 ( 98 with lib.attrsets; 99 [ 100 (nameValuePair "/opt/homebrew/opt/hiredis/lib/libhiredis.1.1.0.dylib" hiredis) 101 (nameValuePair "/opt/homebrew/opt/hiredis/lib/libhiredis_ssl.dylib.1.1.0" hiredis) 102 (nameValuePair "/opt/homebrew/opt/concurrencykit/lib/libck.0.dylib" libck) 103 (nameValuePair "/opt/homebrew/opt/openssl@3/lib/libssl.3.dylib" openssl) 104 (nameValuePair "/opt/homebrew/opt/openssl@3/lib/libcrypto.3.dylib" openssl) 105 (nameValuePair "/opt/homebrew/opt/zstd/lib/libzstd.1.dylib" zstd) 106 (nameValuePair "/opt/homebrew/opt/lz4/lib/liblz4.1.dylib" lz4) 107 ] 108 ); 109 in 110 # fixDarwinDylibNames can't be used here because we need to completely remap .dylibs, not just add absolute paths 111 '' 112 install_name_tool${args} $out/lib/php/extensions/relay.so 113 '' 114 else 115 "" 116 ) 117 + '' 118 # Random UUID that's required by the extension. Can be anything, but must be different from default. 119 sed -i "s/00000000-0000-0000-0000-000000000000/aced680f-30e9-40cc-a868-390ead14ba0c/" $out/lib/php/extensions/relay.so 120 chmod -w $out/lib/php/extensions/relay.so 121 122 runHook postInstall 123 ''; 124 125 passthru = { 126 updateScript = writeShellScript "update-${finalAttrs.pname}" '' 127 set -o errexit 128 export PATH="$PATH:${ 129 lib.makeBinPath [ 130 curl 131 common-updater-scripts 132 ] 133 }" 134 NEW_VERSION=$(curl --silent https://builds.r2.relay.so/meta/builds | sort -V | tail -n1 | cut -c2-) 135 136 if [[ "${version}" = "$NEW_VERSION" ]]; then 137 echo "The new version same as the old version." 138 exit 0 139 fi 140 141 for source in ${lib.concatStringsSep " " (builtins.attrNames finalAttrs.passthru.updateables)}; do 142 update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "$NEW_VERSION" --ignore-same-version --ignore-same-hash --print-changes 143 done 144 ''; 145 146 # All sources for updating by the update script. 147 updateables = 148 builtins.listToAttrs 149 # Collect all leaf attributes (containing hashes). 150 ( 151 lib.collect (attrs: attrs ? name) 152 # create an attr containing 153 ( 154 lib.mapAttrsRecursive ( 155 path: _value: 156 lib.nameValuePair (builtins.replaceStrings [ "." ] [ "_" ] (lib.concatStringsSep "_" path)) ( 157 finalAttrs.finalPackage.overrideAttrs (attrs: { 158 src = makeSource { 159 system = builtins.head path; 160 phpMajor = builtins.head (builtins.tail (builtins.tail path)); 161 }; 162 }) 163 ) 164 ) (lib.filterAttrsRecursive (name: _value: name != "platform") hashes) 165 ) 166 ); 167 }; 168 169 meta = with lib; { 170 description = "Next-generation Redis extension for PHP"; 171 changelog = "https://github.com/cachewerk/relay/releases/tag/v${version}"; 172 homepage = "https://relay.so/"; 173 sourceProvenance = [ sourceTypes.binaryNativeCode ]; 174 license = licenses.unfree; 175 maintainers = with maintainers; [ 176 tillkruss 177 ostrolucky 178 ]; 179 platforms = [ 180 "x86_64-linux" 181 "aarch64-linux" 182 "x86_64-darwin" 183 "aarch64-darwin" 184 ]; 185 }; 186})