nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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.10.1";
19 hashes = {
20 "aarch64-darwin" = {
21 platform = "darwin-arm64";
22 hash = {
23 "8.1" = "sha256-0p24kOzj4l0wBPzmjAzTv1a0EUa4In1pjWHhNhrmsyM=";
24 "8.2" = "sha256-mgRjWEmtCFg7711RgC2lpSDs5cCcs+ZPqks/uj1mAJo=";
25 "8.3" = "16nESEzMRDIiVfwjXsGhJsK9UG5UKgfSunHPeyNnyz0=";
26 "8.4" = "sha256-g8H4vRb1XTnFQo2Db1qvzsENqPYg89/0HSxsW2tDLQQ=";
27 "8.5" = "6NAzMBqBV0BUI4/KlIbnyz0kcD/hucO4tzbuwPSptig=";
28 };
29 };
30 "aarch64-linux" = {
31 platform = "debian-aarch64+libssl3";
32 hash = {
33 "8.1" = "sha256-E6GDFgRgm5I1acqLYFs9kw3TAuHq5aq7TatLnPHJseA=";
34 "8.2" = "sha256-59Un0hAidN/Diu9utUnOgMIdt5ZtOcBFtWrLdHkdME4=";
35 "8.3" = "sha256-ssqZ85KrQG69fZ39RKceEJPXyGfxxLPI21tnPXtPZDE=";
36 "8.4" = "JhFUplu9zMgXX2k2RArWWf0pFweAV+1+/T3yUwblJ2A=";
37 "8.5" = "Ii2bsG4AMMwAKopyOz/qX1RxMaGcstO8kYgup8Vb50w=";
38 };
39 };
40 "x86_64-linux" = {
41 platform = "debian-x86-64+libssl3";
42 hash = {
43 "8.1" = "sha256-MmRAfRDcG1qV8FrZmhME3UtmXe7Mapk2vSrtE/fQRcE=";
44 "8.2" = "sha256-2ZRxJJhQaIkWQJX7bdti6+UFk7zY9yCJ9KWTtE3uGAE=";
45 "8.3" = "sha256-QlUk6q5LQuhWbuqWgb8/JdRfO8V+M6GcTu7rjRqJeiI=";
46 "8.4" = "V+tl7jTrq8PWEAXXu9IsqIlFiQcZBtMBDTlltWSO9CI=";
47 "8.5" = "w4Ba1Oh4JDsuZc5nrYH8lITP6Gk4/0i1wwOHmr4BO44=";
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 ''
86 runHook preInstall
87 install -Dm755 relay.so -t $out/lib/php/extensions
88 ''
89 + (
90 if stdenv.hostPlatform.isDarwin then
91 let
92 args =
93 lib.strings.concatMapStrings
94 (
95 v:
96 " -change ${v.name}" + " ${lib.strings.makeLibraryPath [ v.value ]}/${builtins.baseNameOf v.name}"
97 )
98 (
99 with lib.attrsets;
100 [
101 (nameValuePair "/opt/homebrew/opt/hiredis/lib/libhiredis.1.1.0.dylib" hiredis)
102 (nameValuePair "/opt/homebrew/opt/hiredis/lib/libhiredis_ssl.dylib.1.1.0" hiredis)
103 (nameValuePair "/opt/homebrew/opt/concurrencykit/lib/libck.0.dylib" libck)
104 (nameValuePair "/opt/homebrew/opt/openssl@3/lib/libssl.3.dylib" openssl)
105 (nameValuePair "/opt/homebrew/opt/openssl@3/lib/libcrypto.3.dylib" openssl)
106 (nameValuePair "/opt/homebrew/opt/zstd/lib/libzstd.1.dylib" zstd)
107 (nameValuePair "/opt/homebrew/opt/lz4/lib/liblz4.1.dylib" lz4)
108 ]
109 );
110 in
111 # fixDarwinDylibNames can't be used here because we need to completely remap .dylibs, not just add absolute paths
112 ''
113 install_name_tool${args} $out/lib/php/extensions/relay.so
114 ''
115 else
116 ""
117 )
118 + ''
119 # Random UUID that's required by the extension. Can be anything, but must be different from default.
120 sed -i "s/00000000-0000-0000-0000-000000000000/aced680f-30e9-40cc-a868-390ead14ba0c/" $out/lib/php/extensions/relay.so
121 chmod -w $out/lib/php/extensions/relay.so
122
123 runHook postInstall
124 '';
125
126 passthru = {
127 updateScript = writeShellScript "update-${finalAttrs.pname}" ''
128 set -o errexit
129 export PATH="$PATH:${
130 lib.makeBinPath [
131 curl
132 common-updater-scripts
133 ]
134 }"
135 NEW_VERSION=$(curl --silent https://builds.r2.relay.so/meta/builds | sort -V | tail -n1 | cut -c2-)
136
137 if [[ "${version}" = "$NEW_VERSION" ]]; then
138 echo "The new version same as the old version."
139 exit 0
140 fi
141
142 for source in ${lib.concatStringsSep " " (builtins.attrNames finalAttrs.passthru.updateables)}; do
143 update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "$NEW_VERSION" --ignore-same-version --ignore-same-hash --print-changes
144 done
145 '';
146
147 # All sources for updating by the update script.
148 updateables =
149 builtins.listToAttrs
150 # Collect all leaf attributes (containing hashes).
151 (
152 lib.collect (attrs: attrs ? name)
153 # create an attr containing
154 (
155 lib.mapAttrsRecursive (
156 path: _value:
157 lib.nameValuePair (builtins.replaceStrings [ "." ] [ "_" ] (lib.concatStringsSep "_" path)) (
158 finalAttrs.finalPackage.overrideAttrs (attrs: {
159 src = makeSource {
160 system = builtins.head path;
161 phpMajor = builtins.head (builtins.tail (builtins.tail path));
162 };
163 })
164 )
165 ) (lib.filterAttrsRecursive (name: _value: name != "platform") hashes)
166 )
167 );
168 };
169
170 meta = with lib; {
171 description = "Next-generation Redis extension for PHP";
172 changelog = "https://github.com/cachewerk/relay/releases/tag/v${version}";
173 homepage = "https://relay.so/";
174 sourceProvenance = [ sourceTypes.binaryNativeCode ];
175 license = licenses.unfree;
176 maintainers = with maintainers; [
177 tillkruss
178 ostrolucky
179 ];
180 platforms = [
181 "x86_64-linux"
182 "aarch64-linux"
183 "x86_64-darwin"
184 "aarch64-darwin"
185 ];
186 };
187})