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