How to emulate aarch64 on x86 NixOS?

Hello!

I’m trying to run an aarch64 binary on my x86 NixOS machine.

I’ve installed QEMU and set up my config with binfmt as described here: QEMU - NixOS Wiki.

However, when I try to run an aarch64 binary, I get the following error:

qemu-aarch64: Could not open '/nix/store/27fg1mkiymj2b344j80kygsbxfcdl5qi-glibc-2.39-52/lib/ld-linux-aarch64.so.1': No such file or directory

Based on reading the store path, it seems like it’s trying to access this ld-linux-aarch64.so.1 shared library which is located inside the glibc package?

Do I need to install an aarch64 version of glibc or is there something else I’m missing in my config? Any help would be appreciated! Thanks.

Assuming the aarch64 binary you’re trying to run came from nix, it should have worked. So that would be some kind of bug, or the binary is broken somehow.

No, you never “install” libraries on NixOS. If you get an error like this, it often indicates a packaging issue with the package you’re trying to use.
Or if the binary wasn’t packaged with nix, then you package it with nix.

Thank you for the replies. That makes sense that the binary would need to be packaged for nix.

For context, I’m trying to chroot into another NixOS computer (aarch64) so that I can fix an issue with its NixOS configuration that’s causing it not to boot.

I’m following this wiki guide that oulines how to use nixos-enter: Change root - NixOS Wiki.

However, when I run nixos-enter I get the errors (which I believe to be the same as the one I originally sent):

chroot: failed to run command ‘/nix/var/nix/profiles/system/activate’: No such file or directory
chroot: failed to run command ‘/nix/var/nix/profiles/system/sw/bin/bash’: No such file or directory

Digging more into it, I noticed that the activate script was not missing. I also found that chroot won’t properly report which file is missing (thanks to this Stack Overlow linux - chroot "no such file or directory" prints wrong missing file - Stack Overflow).

So, I did some more debugging and tried to run some binaries in the nix store of the aarch64 computer that I mounted. I tried running bash in the aarch64 computer’s nix store and got exactly the original error I sent.

Any thoughts on a way around this? Or is it not possible to chroot into NixOS from a different architecture?

You’re trying to enable emulatedSystems on one system that’s x86_64, and then chroot into another system that’s aarch64? Yea, that’s not going to be that easy. Once you chroot, your process loses all the binfmt context, and any emulator that binfmt would have needed also has to be in the chroot. So there’s at least those two problems to fix.

you are probably better off setting up an emulated nixos aarch64 vm, and using that to chroot/nixos-enter the image of the broken machine. You could probably just boot the vm into the installer and use that for recovery. I assume you have the disk image you’re trying to enter on an sdcard or similar, and there’s some reason why booting the installer to do the recovery is harder on the intended machine.