{ stdenv, lib, fetchurl, php, openssl, hiredis, libck, zstd, lz4, autoPatchelfHook, writeShellScript, curl, common-updater-scripts, }: let version = "0.21.0"; hashes = { "aarch64-darwin" = { platform = "darwin-arm64"; hash = { "8.1" = "sha256-BL4XH7oyZBmZThhfdaqwtArxjF+0CKYYIqxRBafhjCI="; "8.2" = "sha256-CDNSwdU+/7STdSzZigzq0qc58s2Tz0GtKsXnXpQodic="; "8.3" = "10cDKh5aXhUN8bONZAXKr8o7UMlngYCXmqD829Ht3oU="; "8.4" = "sha256-t2cNqYl4U4qDmpK6+4iFKmAAd2D66EJqzt+5l1gB0wg="; "8.5" = "JBitKlONDaXsDW1wf08JqDbado8Fy+uVzYU9Lvi8fFc="; }; }; "aarch64-linux" = { platform = "debian-aarch64+libssl3"; hash = { "8.1" = "sha256-I0gMRnN3y/57f0IBNDx5TaFtdFnFmotaqI8vnwGwxqg="; "8.2" = "sha256-gsk/Kz/zJUXGFubfnQ7wia/5JEHgrIoTM396QpX5YaE="; "8.3" = "sha256-6+ALZru+ee4lE41bKd06bnSqqTZ1FlcNVW4xOAWZP4g="; "8.4" = "fYWndjBhKQQjFUwT0aP4A6EUkNCYsEvKtUcXR9l11Yg="; "8.5" = "0UEvha64GSG/Mysc7oUJ6GMmY1uRZxN/gCkkNzWq/ng="; }; }; "x86_64-linux" = { platform = "debian-x86-64+libssl3"; hash = { "8.1" = "sha256-g5H+3q0ehto/Ug87nb69quiWfR+AhZD5RdrYKl9fmU8="; "8.2" = "sha256-pUAACcw24DuTDla0L375P+iPhZ/ttlMU2rnQKF6WU8k="; "8.3" = "sha256-kKF7+zs0WXaMNh7rYUBrg+VixK+AEn3b65EtQiQpJUA="; "8.4" = "FMYVQ2LDOWnmjkj5UdogwRB4q6NZqebUivbDmAjBONg="; "8.5" = "T4RL15DJ/rkFLMCXiK7/2PD62LUkrlqFeLwDu1F7Ev0="; }; }; }; makeSource = { system, phpMajor }: fetchurl { url = "https://builds.r2.relay.so/v${version}/relay-v${version}-php" + phpMajor + "-" + hashes.${system}.platform + ".tar.gz"; sha256 = hashes.${system}.hash.${phpMajor} or (throw "Unsupported PHP version for relay ${phpMajor} on ${system}"); }; in stdenv.mkDerivation (finalAttrs: { inherit version; pname = "relay"; extensionName = "relay"; src = makeSource { system = stdenv.hostPlatform.system; phpMajor = lib.versions.majorMinor php.version; }; nativeBuildInputs = lib.optionals (!stdenv.hostPlatform.isDarwin) [ autoPatchelfHook ]; buildInputs = lib.optionals (!stdenv.hostPlatform.isDarwin) [ hiredis libck openssl zstd lz4 ]; internalDeps = [ php.extensions.session ]; installPhase = '' runHook preInstall '' + lib.optionalString stdenv.hostPlatform.isLinux '' # Temporary patch as relay isn't compatible with the latest version of hiredis out of # the box. patchelf \ --replace-needed libhiredis.so.1.1.0 libhiredis.so.1 \ --replace-needed libhiredis_ssl.so.1.1.0 libhiredis_ssl.so.1 \ relay.so '' + '' install -Dm755 relay.so -t $out/lib/php/extensions '' + ( if stdenv.hostPlatform.isDarwin then let args = lib.strings.concatMapStrings (v: " -change ${v.name}" + " ${lib.strings.makeLibraryPath [ v.value ]}/${baseNameOf v.name}") ( with lib.attrsets; [ (nameValuePair "/opt/homebrew/opt/hiredis/lib/libhiredis.1.1.0.dylib" hiredis) (nameValuePair "/opt/homebrew/opt/hiredis/lib/libhiredis_ssl.dylib.1.1.0" hiredis) (nameValuePair "/opt/homebrew/opt/concurrencykit/lib/libck.0.dylib" libck) (nameValuePair "/opt/homebrew/opt/openssl@3/lib/libssl.3.dylib" openssl) (nameValuePair "/opt/homebrew/opt/openssl@3/lib/libcrypto.3.dylib" openssl) (nameValuePair "/opt/homebrew/opt/zstd/lib/libzstd.1.dylib" zstd) (nameValuePair "/opt/homebrew/opt/lz4/lib/liblz4.1.dylib" lz4) ] ); in # fixDarwinDylibNames can't be used here because we need to completely remap .dylibs, not just add absolute paths '' install_name_tool${args} $out/lib/php/extensions/relay.so '' else "" ) + '' # Random UUID that's required by the extension. Can be anything, but must be different from default. sed -i "s/00000000-0000-0000-0000-000000000000/aced680f-30e9-40cc-a868-390ead14ba0c/" $out/lib/php/extensions/relay.so chmod -w $out/lib/php/extensions/relay.so runHook postInstall ''; passthru = { updateScript = writeShellScript "update-${finalAttrs.pname}" '' set -o errexit export PATH="$PATH:${ lib.makeBinPath [ curl common-updater-scripts ] }" NEW_VERSION=$(curl --silent https://builds.r2.relay.so/meta/builds | sort -V | tail -n1 | cut -c2-) if [[ "${version}" = "$NEW_VERSION" ]]; then echo "The new version same as the old version." exit 0 fi for source in ${lib.concatStringsSep " " (builtins.attrNames finalAttrs.passthru.updateables)}; do update-source-version "$UPDATE_NIX_ATTR_PATH.updateables.$source" "$NEW_VERSION" --ignore-same-version --ignore-same-hash --print-changes done ''; # All sources for updating by the update script. updateables = builtins.listToAttrs # Collect all leaf attributes (containing hashes). ( lib.collect (attrs: attrs ? name) # create an attr containing ( lib.mapAttrsRecursive ( path: _value: lib.nameValuePair (builtins.replaceStrings [ "." ] [ "_" ] (lib.concatStringsSep "_" path)) ( finalAttrs.finalPackage.overrideAttrs (attrs: { src = makeSource { system = builtins.head path; phpMajor = builtins.head (builtins.tail (builtins.tail path)); }; }) ) ) (lib.filterAttrsRecursive (name: _value: name != "platform") hashes) ) ); }; meta = { description = "Next-generation Redis extension for PHP"; changelog = "https://github.com/cachewerk/relay/releases/tag/v${version}"; homepage = "https://relay.so/"; sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; license = lib.licenses.unfree; maintainers = with lib.maintainers; [ tillkruss ostrolucky ]; platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; }; })