Can't patch binary with nix-ld : Could not open '/lib64/ld-linux-x86-64.so.2'

I’m trying to run Cypress in NixOS running in a VM on M1 Mac (aarch64).

Here is my shell.nix

with import <nixpkgs> {};

pkgs.mkShell {

  buildInputs = with pkgs;[
        nodejs-16_x
        yarn
       cacert
       file
       python2
       cypress
  ];

  NIX_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
      pkgs.glibc
      pkgs.stdenv.cc.cc
    ];
  NIX_LD = builtins.readFile "${pkgs.stdenv.cc}/nix-support/dynamic-linker";

  shellHook = ''
    export CYPRESS_INSTALL_BINARY=0
    export CYPRESS_RUN_BINARY=${cypress}/bin/Cypress
  '';
}

Basically the gist is that Cypress binary is usually downloaded into ~/.cache/Cypress dir so in the hook the env vars tell npm not to download the binary and also where the binary is located when a node script tries calling Cypress.

Since cypress is now in pkgs, I point to that.

When I ran ldd $(which Cypress) I got :

linux-vdso.so.1 (0x0000ffff9f828000)
libc.so.6 => /nix/store/6afvzgx3himw7584k9zmfxmqd86b1z7j-glibc-2.34-210/lib/libc.so.6 (0x0000ffff9f659000)
/nix/store/6afvzgx3himw7584k9zmfxmqd86b1z7j-glibc-2.34-210/lib/ld-linux-aarch64.so.1 (0x0000ffff9f7f5000)

So even after setting all of this up, trying to run Cypress open gives:

qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

What else am I missing here? Seems like nix-ld isn’t doing anything ? I’m not sure.

To use nix-ld you need to enable it on the system. On NixOs you need to use programs.nix-ld.enable = true; in your configuration.nix. It will then create for you a file in /lib64/ld-linux-x86-64.so.2 that will read the NIX_LD environment variable to find the loader. As I understand it it is mostly for NixOs and I don’t think it is usable on other systems as they already come with their own loaders.

1 Like

You probably also don’t want to read the contents of a binary into a string and then specify that as an env variable. Just specify the path, don’t read its contents.

The doc mentions NIX_LD = lib.fileContents "${pkgs.stdenv.cc}/nix-support/dynamic-linker"; and I used it succesfully. The reason is that this file contains the path of the actual binary:

$ cat ./3d9zjv5vaqjxb9kwbdqsd194alwm97x1-gcc-wrapper-11.3.0/nix-support/dynamic-linker
/nix/store/6f66prpgx1qx4n6k450sxs3d157ia1ps-glibc-2.35-163/lib/ld-linux-x86-64.so.2

Aaah, ok, nevermind me :slight_smile:

It’s enabled.
I still get same erro when trying to run Cypress:

/nix/store/md1w04lvylr42j8j2bdzy1zp5x7044wj-cypress-9.6.0/bin/Cypress      1102ms  Thu 01 Sep 2022 03:21:31 AM PDT
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

Can you check then if the file /lib64/ld-linux-x86-64.so.2 exists? Note also that you need to graphically logout (for some reasons restarting a terminal is not enough) to reload the variables, even if I don’t think the problem is that.

Nope, doesn’t exist.
Here is root folder:

 /  ls                                                                                                                         Thu 01 Sep 2022 05:44:02 AM PDT
bin/  boot/  dev/  etc/  home/  host/  lib/  lost+found/  nix/  nix-config/  opt/  proc/  root/  run/  srv/  sys/  tmp/  usr/  var/
 /  ls -a                                                                                                                      Thu 01 Sep 2022 05:44:03 AM PDT
./  ../  bin/  boot/  dev/  etc/  home/  host/  lib/  lost+found/  nix/  nix-config/  opt/  proc/  root/  run/  srv/  sys/  tmp/  usr/  var/
 /  ls lib                                                                                                                     Thu 01 Sep 2022 05:44:05 AM PDT
ld-linux-aarch64.so.1@

Also, I ran this to see what my NIX_LD is being set to :

find /nix/store  -name "dynamic-linker"                                          3979ms  Thu 01 Sep 2022 05:50:56 AM PDT
/nix/store/jky6xkgv6wlgi4b0irfpradwjyv53w4n-binutils-wrapper-2.38/nix-support/dynamic-linker
/nix/store/w13bzcd06q0qljq92gsfjkqlgh2l8w9q-aarch64-unknown-linux-musl-binutils-wrapper-2.38/nix-support/dynamic-linker
/nix/store/77sn1ikcixh1qmcvhv93hprgavfavf78-aarch64-unknown-linux-musl-stage-final-gcc-wrapper-9.3.0/nix-support/dynamic-linker
/nix/store/61rzbhrdg7qnzfrqb5ni9r8j0q1f8xw1-binutils-wrapper-2.35.1/nix-support/dynamic-linker
/nix/store/zwm8chdj9xi509q5rw5z4qcm655wgpav-gcc-wrapper-9.3.0/nix-support/dynamic-linker
/nix/store/jkchx9lkx1hfgbkcldch8lr1ca100iw6-gcc-wrapper-9.3.0/nix-support/dynamic-linker
/nix/store/0b2a9cmi6jmakcfa0xhilwgyzvxv81hf-binutils-wrapper-2.38/nix-support/dynamic-linker
/nix/store/5ghn7knk9q96rfskxzv7a1jd4z22habv-gcc-wrapper-9.5.0/nix-support/dynamic-linker
/nix/store/xq1v2n416bwrmfkaizri3qi1m52wvfnm-binutils-wrapper-2.38/nix-support/dynamic-linker
/nix/store/isaxw6yarfckyx2s91cl4npzx1pfv46z-binutils-wrapper-2.38/nix-support/dynamic-linker
/nix/store/5hiyxm7wij8ra2gcanvdfrqzhsdjbncz-gcc-wrapper-9.5.0/nix-support/dynamic-linker
/nix/store/x8bm8dn1744hjscsdawjx04ihbi7z3qj-binutils-wrapper-2.38/nix-support/dynamic-linker
 N  ~/maple-stack   develop *~$…  echo $NIX_LD                                                                     1971ms  Thu 01 Sep 2022 05:51:11 AM PDT
/nix/store/6afvzgx3himw7584k9zmfxmqd86b1z7j-glibc-2.34-210/lib/ld-linux-aarch64.so.1

Oh so you do have a /lib folder but not a /lib64 folder… I guess that the fact that you have a mac confused this line https://github.com/Mic92/nix-ld/blob/c25cc4b5ec65f03c2bb96f927ae724a59c51d7ee/nix-ld.nix so I tried to fill a bug report here https://github.com/Mic92/nix-ld/issues/27

You may want to follow this issue as Mic92 may have other questions for you

Also, could you please provide the output of this to learn the value of stdenv.system on your system?

$ nix repl '<nixpkgs>'
Welcome to Nix 2.8.0pre20220411_f7276bc. Type :? for help.

Loading '<nixpkgs>'...
Added 15275 variables.

nix-repl> stdenv.system
"x86_64-linux"

Oh wait, I can see the line aarch64 so the M1 is maybe running arm instead of x86_64. In this case it may simply be the case that you are using a bad software, compiled for the x86_64 architecture. Now, if you installed this software via NixOs it may be the case that the NixOs derivation for Cypress is wrong…

Yea I suspected it was architecture problem because my error starts with the qemu-x86_64 . Isn’t that why it’s looking for the x86_64 library ? Doesn’t qemu emulation convert x86_64 architectures?

To be honest I’m not sure where this qemu is coming from, as I don’t know how cypress internally works. However the nixpkgs instructions only target x64 so this should not even be installable on your system… So I’m curious, what is your stdenv.system (see above)? I guess your best chance is to update the cypress expression to make it work on your architecture. For instance you can download the latest arm64 at https://cdn.cypress.io/desktop/10.7.0/linux-arm64/cypress.zip hopefully it should be enough to just write an overlay with this url

nix-repl> stdenv.system
“aarch64-linux”

Ok, I’ll try to do an overlay with that zip and will report back. Thanks