Docker image allowing non-nix applications

I want to create a docker image which will need to allow the user to add non-nix dynamically linked binaries. The binaries (I know what they will be) won’t have any fancy dependencies, just glibc (libc, libm, etc.). Is it possible to expose nixpkgs glibc in the image somehow? Is buildFHSUserEnv way to go?

While not exactly what you’re after, there are some tools which will run non-nix dynamically linked binaries, although I haven’t tried them:

2 Likes

nix-ld indeed worked. My containers don’t have systemd, so I created the symlink in the runAsRoot section:

ln -s /libexec/nix-ld /lib64/$(basename  $(< ${stdenv.cc}/nix-support/dynamic-linker))

then in Env.config section:

"NIX_LD_LIBRARY_PATH=${lib.makeLibraryPath [ stdenv.cc.cc openssl ...]}"
''NIX_LD=${lib.fileContents "${stdenv.cc}/nix-support/dynamic-linker"}''

Using buildLayeredImage it worked for me linking nix-ld in fakeRootCommands after creating the lib64 directory:

  mkdir lib64
  ln -s /libexec/nix-ld lib64/$(basename $(< ${stdenv.cc}/nix-support/dynamic-linker))