From 0abcee33b286af3cfc2c179d5f8e67f0f3b542ce Mon Sep 17 00:00:00 2001 From: Rodrigue Cloutier Date: Fri, 15 Aug 2025 15:58:22 -0400 Subject: [PATCH] Fix elasticsearch8 hash mismatch and add cross-platform testing - Remove autoPatchelfHook from nativeBuildInputs to fix Linux hash mismatch - Add manual ELF patching in postInstall phase after hash verification - Update aarch64-linux hash to correct value --- README.md | 2 +- pkgs/elasticsearch8.nix | 42 +++++++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 42bb340..05ecccf 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ You can use the packages from this flake in your configuration: ```nix # In your outputs outputs = { self, nixpkgs, nix-support }: { - devShells.x86_64-linux.default = + devShells.x86_64-linux.default = let pkgs = import nixpkgs { system = "x86_64-linux"; }; in diff --git a/pkgs/elasticsearch8.nix b/pkgs/elasticsearch8.nix index 8caa4ba..cdc0b17 100644 --- a/pkgs/elasticsearch8.nix +++ b/pkgs/elasticsearch8.nix @@ -11,7 +11,7 @@ else "linux"; hashes = { "x86_64-linux" = "sha512-au9PyE67/JjmZiQYxzTqicro5TqNbB+9U1KAe8Qn4EDmK+VotQKr3Ot6L1dTTq5g4xcS0Fg9N1L9Obe4o2MtOw=="; - "aarch64-linux" = "sha512-au9PyE67/JjmZiQYxzTqicro5TqNbB+9U1KAe8Qn4EDmK+VotQKr3Ot6L1dTTq5g4xcS0Fg9N1L9Obe4o2MtOw=="; + "aarch64-linux" = "sha512-Cxs+oOtrNy+4LN83YXGYmpMGi9xMP4DcJnB0g9CWBfa0DGUJbOzF4Vz87ZxvgjU/SmMutnesXXWbM4Pfk3bMRg=="; "x86_64-darwin" = "sha512-R7YbSehFAGJLwrSx6FNs6CArYUyo1JZc4VKZQJ5fbDVBpyhwFmtI6PWSVlLYyx2qnj9Yd/7YBTuhrj9sqQDYZQ=="; "aarch64-darwin" = "sha512-R7YbSehFAGJLwrSx6FNs6CArYUyo1JZc4VKZQJ5fbDVBpyhwFmtI6PWSVlLYyx2qnj9Yd/7YBTuhrj9sqQDYZQ=="; }; @@ -34,11 +34,11 @@ in "ES_CLASSPATH=\"\$ES_CLASSPATH:$out/\$additional_classpath_directory/*\"" ''; - nativeBuildInputs = - [ - pkgs.makeBinaryWrapper - ] - ++ pkgs.lib.optional (!pkgs.stdenv.hostPlatform.isDarwin) pkgs.autoPatchelfHook; + nativeBuildInputs = [ + pkgs.makeBinaryWrapper + ] ++ pkgs.lib.optionals (!pkgs.stdenv.hostPlatform.isDarwin) [ + pkgs.patchelf + ]; buildInputs = [ pkgs.jre_headless @@ -66,6 +66,36 @@ in wrapProgram $out/bin/elasticsearch-plugin --set ES_JAVA_HOME "${pkgs.jre_headless}" ''; + postInstall = pkgs.lib.optionalString (!pkgs.stdenv.hostPlatform.isDarwin) '' + # Manually patch ELF binaries on Linux to fix dynamic library paths + find $out -type f -executable | while read -r file; do + if file "$file" | grep -q "ELF.*executable" && [ ! -L "$file" ]; then + echo "Patching ELF executable: $file" + # Use patchelf to set the interpreter and fix rpath, but be more conservative + if ${pkgs.patchelf}/bin/patchelf --print-interpreter "$file" 2>/dev/null; then + ${pkgs.patchelf}/bin/patchelf \ + --set-interpreter "$(cat ${pkgs.stdenv.cc}/nix-support/dynamic-linker)" \ + "$file" 2>/dev/null || echo "Failed to set interpreter for $file" + fi + if ${pkgs.patchelf}/bin/patchelf --print-rpath "$file" 2>/dev/null; then + ${pkgs.patchelf}/bin/patchelf \ + --set-rpath "${pkgs.lib.makeLibraryPath [ pkgs.zlib pkgs.stdenv.cc.cc.lib ]}" \ + "$file" 2>/dev/null || echo "Failed to set rpath for $file" + fi + fi + done + + # Also patch any shared libraries, but be selective + find $out -name "*.so*" -type f | while read -r file; do + if file "$file" | grep -q "ELF.*shared object" && [ ! -L "$file" ]; then + echo "Patching shared library: $file" + ${pkgs.patchelf}/bin/patchelf \ + --set-rpath "${pkgs.lib.makeLibraryPath [ pkgs.zlib pkgs.stdenv.cc.cc.lib ]}" \ + "$file" 2>/dev/null || echo "Failed to patch shared library $file" + fi + done + ''; + passthru = { enableUnfree = true; };