How do I install the 32-bit dynamic linker on 64-bit NixOS?

I need that to use mksdcard from the Android SDK. Currently, when I run that executable, the system reports "No such file or directory".

For Debian, one can install ia32-libs. On Ubuntu, the package is called libc6-i386.

How do I get the file /lib/ld-linux.so.2 on NixOS?


Solution 1:

NixOS does not natively have multiarch support.

The only Nix package which contains the 32-bit ELF interpreter ld-linux.so.2 file is the i386 version of glibc.

Luckily, we can work around the issue by borrowing the package from debian.

  1. Install dpkg: nix-env -i dpkg
  2. Download the libc-i386 package for 64-bit systems from debian: curl -O http://ftp.us.debian.org/debian/pool/main/e/eglibc/libc6-i386_2.11.3-4_amd64.deb
  3. Extract that package: dpkg -x libc6-i386_2.11.3-4_amd64.deb libc6-i386
  4. Run mksdcard with 32-bit ELF interpreter: ./libc6-i386/lib32/ld-linux.so.2 /path/to/mksdcard

One way to be able to run things like mksdcard via ./mksdcard is to patch them using patchelf installed via: nix-env -i patchelf

You can then do something like patchelf --set--interpreter /path/to/libc6-i386/lib32/ld-linux.so.2 /path/to/mksdcard

Otherwise, you may try to place symlinks to your ld-linux.so.2 in the places where ldd is telling you it expects them.

[root@nixos:/tmp]# ./libc6-i386/lib32/ld-linux.so.2
Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]
You have invoked `ld.so', the helper program for shared library executables.
This program usually lives in the file `/lib/ld.so', and special directives
in executable files using ELF shared libraries tell the system's program
loader to load the helper program from this file.  This helper program loads
the shared libraries needed by the program executable, prepares the program
to run, and runs it.  You may invoke this helper program directly from the
command line to load and run an ELF executable file; this is like executing
that file itself, but always uses this helper program from the file you
specified, instead of the helper program file specified in the executable
file you run.  This is mostly of use for maintainers to test new versions
of this helper program; chances are you did not intend to run this program.

  --list                list all dependencies and how they are resolved
  --verify              verify that given object really is a dynamically linked
                        object we can handle
  --library-path PATH   use given PATH instead of content of the environment
                        variable LD_LIBRARY_PATH
  --inhibit-rpath LIST  ignore RUNPATH and RPATH information in object names
                        in LIST
  --audit LIST          use objects named in LIST as auditors