Can't patch binary with nix-ld : Could not open '/lib64/'

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;[

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

  shellHook = ''
    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 : (0x0000ffff9f828000) => /nix/store/6afvzgx3himw7584k9zmfxmqd86b1z7j-glibc-2.34-210/lib/ (0x0000ffff9f659000)
/nix/store/6afvzgx3himw7584k9zmfxmqd86b1z7j-glibc-2.34-210/lib/ (0x0000ffff9f7f5000)

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

qemu-x86_64: Could not open '/lib64/': 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/ 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 "${}/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

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/': No such file or directory

Can you check then if the file /lib64/ 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

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
 N  ~/maple-stack   develop *~$…  echo $NIX_LD                                                                     1971ms  Thu 01 Sep 2022 05:51:11 AM PDT

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 so I tried to fill a bug report here

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

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 hopefully it should be enough to just write an overlay with this url

nix-repl> stdenv.system

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