1{ stdenv
2, lib
3, fetchurl
4, php
5, openssl
6, openssl_1_1
7, zstd
8, lz4
9, autoPatchelfHook
10}:
11
12let
13 version = "0.6.3";
14 system = stdenv.hostPlatform.system;
15 phpVersion = lib.versions.majorMinor php.version;
16 variation = {
17 "aarch64-darwin" = {
18 platform = "darwin-arm64";
19 hashes = {
20 "8.0" = "00a7pyf9na7hjifkmp2482c7sh086w72zniqgr4cz2rhz7hnqp7p";
21 "8.1" = "0mg6nsllycgjxxinn8s30y9sk06g40vk8blnpx0askjw5zdsf5y7";
22 "8.2" = "0qmcbrj6jaxczv25rdgfjrj9nwq4vb2faw7kzlyxrvvzb5pyn9dm";
23 "8.3" = "1hqjy5y4q3alxvrj7xksaf7vvmz8p51bgzxbvmzdx6jnl63dix33";
24 };
25 };
26 "aarch64-linux" = {
27 platform = "debian-aarch64+libssl3";
28 hashes = {
29 "8.0" = "19zzw4324z096b6bph1686r30i4i2kwmlmmcqmb33lqkr9b9n5ag";
30 "8.1" = "0j6wpwy8d67pqij4v8m2xwydfddzr7nn4c3lyrssp8llbn4ghwpn";
31 "8.2" = "1nbajvi5zk6z8qr32l86p65f1zxv12kald56pg8k7bj4axlj2pmy";
32 "8.3" = "1sn638g2636m6s3lv2cclza9lzmzgqxamcga7jz3ijhn2ja6znbv";
33 };
34 };
35 "x86_64-darwin" = {
36 platform = "darwin-x86-64";
37 hashes = {
38 "8.0" = "13q6va9lxgfyx86xw20iqjz4s9r9xms74ywb2hgqrhs5mjnazzz4";
39 "8.1" = "1ncih5bf0jcylpl0nj8hi50kcwb4nl1g0ql359dgg9gp8s1b4hmw";
40 "8.2" = "150difm3vg0g2pl5hb5cci4jzybd7jcd7prjdv3rmwsi91gsydlv";
41 # 8.3 for this platform does not exist
42 };
43 };
44 "x86_64-linux" = {
45 platform = "debian-x86-64+libssl3";
46 hashes = {
47 "8.0" = "1qvd5r591kp7qf9pkymz78s8llzs1vxjwqhwy9rvma21hh6gd8ld";
48 "8.1" = "0fm9ppgx7qaggid134qnl9jkq5h97dac2ax21f1f1d0k8f5blmc2";
49 "8.2" = "0g2yqwfrigf047dqkrvfcj318lvgp38zy522ry484mrgq7iqwvb8";
50 "8.3" = "06mi3yr7k1a9icdljzl76xvrw6xqnvwiavgzx2g487s097mycjp4";
51 };
52 };
53 }.${system} or (throw "Unsupported platform for relay: ${system}");
54in
55stdenv.mkDerivation (finalAttrs: {
56 inherit version;
57 pname = "relay";
58 extensionName = "relay";
59
60 src = fetchurl {
61 url = "https://builds.r2.relay.so/v${finalAttrs.version}/relay-v${finalAttrs.version}-php"
62 + phpVersion + "-" + variation.platform + ".tar.gz";
63 sha256 = variation.hashes.${phpVersion} or (throw "Unsupported PHP version for relay ${phpVersion} on ${system}");
64 };
65 nativeBuildInputs = lib.optionals (!stdenv.isDarwin) [
66 autoPatchelfHook
67 ];
68 buildInputs = lib.optionals (!stdenv.isDarwin) [
69 openssl
70 zstd
71 lz4
72 ];
73 installPhase = ''
74 runHook preInstall
75
76 mkdir -p $out/lib/php/extensions
77 cp relay-pkg.so $out/lib/php/extensions/relay.so
78 chmod +w $out/lib/php/extensions/relay.so
79 '' + (if stdenv.isDarwin then
80 let
81 args = lib.strings.concatMapStrings
82 (v: " -change /Users/administrator/dev/relay-dev/relay-deps/build/arm64/lib/${v.name}"
83 + " ${lib.strings.makeLibraryPath [ v.value ]}/${v.name}")
84 (with lib.attrsets; [
85 (nameValuePair "libssl.1.1.dylib" openssl_1_1)
86 (nameValuePair "libcrypto.1.1.dylib" openssl_1_1)
87 (nameValuePair "libzstd.1.dylib" zstd)
88 (nameValuePair "liblz4.1.dylib" lz4)
89 ]);
90 in
91 # fixDarwinDylibNames can't be used here because we need to completely remap .dylibs, not just add absolute paths
92 ''
93 install_name_tool${args} $out/lib/php/extensions/relay.so
94 ''
95 else
96 "") + ''
97 # Random UUID that's required by the extension. Can be anything, but must be different from default.
98 sed -i "s/00000000-0000-0000-0000-000000000000/aced680f-30e9-40cc-a868-390ead14ba0c/" $out/lib/php/extensions/relay.so
99 chmod -w $out/lib/php/extensions/relay.so
100
101 runHook postInstall
102 '';
103
104 meta = with lib; {
105 description = "Next-generation Redis extension for PHP";
106 changelog = "https://github.com/cachewerk/relay/releases/tag/v${version}";
107 homepage = "https://relay.so/";
108 sourceProvenance = [ sourceTypes.binaryNativeCode ];
109 license = licenses.unfree;
110 maintainers = with maintainers; [ tillkruss ostrolucky ];
111 platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
112 };
113})