lwthiker / curl-impersonate

curl-impersonate: A special build of curl that can impersonate Chrome & Firefox
MIT License
3.77k stars 248 forks source link

"curl-impersonate-chrome: No such file or directory" (but the file exists) #78

Closed izzues closed 2 years ago

izzues commented 2 years ago

Hey,

I downloaded the binaries from the Releases page. It works on Debian, but on NixOS I'm getting the following error:

$ ./curl_chrome99
# [...]/curl_chrome99: line 10: [...]/curl-impersonate-chrome: No such file or directory

When I run ldd [...]/curl-impersonate-chrome, this is what I see:

    linux-vdso.so.1 (0x00007ffe85ba6000)
    libz.so.1 => not found
    libpthread.so.0 => /nix/store/f6kvkdzp6qfjm6h94d0jgfvm4r06xcaq-glibc-2.34-210/lib/libpthread.so.0 (0x00007f03352ed000)
    libc.so.6 => /nix/store/f6kvkdzp6qfjm6h94d0jgfvm4r06xcaq-glibc-2.34-210/lib/libc.so.6 (0x00007f03350ef000)
    /lib64/ld-linux-x86-64.so.2 => /nix/store/f6kvkdzp6qfjm6h94d0jgfvm4r06xcaq-glibc-2.34-210/lib64/ld-linux-x86-64.so.2 (0x00007f0335606000)

Unsure if related: I see a test is performed in the build script, but it's not checking for zlib? In addition, I don't think it works as expected (if I'm not mistaken, grep -q returns success if any of the patterns is found):

https://github.com/lwthiker/curl-impersonate/blob/1b46a3fb88f92ae95b1374d1c3fbdf433002cad0/firefox/Dockerfile.alpine#L94

lwthiker commented 2 years ago

Hi,

libz.so.1 => not found

It seems like you are missing libz.so.1 (zlib). Have you tried installing it? The No such file or directory error you get is the loader's weird way of telling you it's missing.

I see a test is performed in the build script, but it's not checking for zlib?

The test checks that certain libraries were compiled statically into curl-impersonate. I added it because sometimes the linker would insist on linking things dynamically. zlib specifically is not meant to be compiled statically into curl-impersonate since it is ubiquitous on most Linux systems.

About the correctness of the test itself, grep will return success if any of the static libraries was accidentally linked dynamically, and therefore the result is negated with ! (we want the build to fail in that case).

izzues commented 2 years ago

Thank you for your response and corrections!

I forgot to mention that I did install zlib, but it still wouldn't work.

After doing more research, I found out this is a common issue in NixOS and a workaround is to patch the binary.

The proper solution would be to package curl-impersonate for NixOS. I'll leave that as a suggestion, but since this isn't specific to curl-impersonate, I'm closing this. Thanks again!


If anyone else struggles with this in the future, here's a default.nix derivation that works using the workaround I mentioned. Keep in mind I'm just a noob so it may not be the best way to do it.

{ stdenv,
  lib,
  autoPatchelfHook,
  fetchzip,
  zlib,
}:
stdenv.mkDerivation rec {
  name = "curl-impersonate-${version}";
  version = "0.5.0";
  src = fetchzip {
    url = "https://github.com/lwthiker/curl-impersonate/releases/download/v${version}/curl-impersonate-v${version}.x86_64-linux-gnu.tar.gz";
    sha256 = "sha256-1EQRwLbrfRZfOzsn+EPO1orF+D39JucKh0wMKx5L9vc=";
    stripRoot = false;
  };

  nativeBuildInputs = [
    autoPatchelfHook
  ];

  buildInputs = [
    zlib
  ];

  installPhase = ''
    mkdir -p $out/bin
    cp -r $src/* $out/bin
  '';

  postFixup = ''
    autoPatchelf .
  '';
}

Assuming you have Nix installed, you can check this works by running nix-build -E "with import <nixpkgs> {}; callPackage ./default.nix {}" && ./result/bin/curl_chrome99 google.com.