Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can nix-ld be used in docker image created with nix2container? #60

Open
nxy7 opened this issue Aug 16, 2023 · 1 comment
Open

Can nix-ld be used in docker image created with nix2container? #60

nxy7 opened this issue Aug 16, 2023 · 1 comment

Comments

@nxy7
Copy link

nxy7 commented Aug 16, 2023

Hi, I'm trying to create minimal docker image, that can run binaries. I've created repo @ https://github.com/nxy7/tiny and published this image to docker hub (in case anyone wants to test it) as nxyt/tiny:latest. Anyway - it doesn't work and any binary I run results in bash: ./main: cannot execute: required file not found.
As far as I understand binaries expect linker at specific location, so even if ldd my-binary shows that all dependencies are present it still tries to call linker at /lib64/xxx and because there's none, that's why my binaries are failing.

If I got that right, that's the problem that nix-ld is trying to solve, but I cannot really get that to work with nix2container.
What I've tried was adding nix_ld to copyToRoot and adding 'lib' and 'lib64' to 'pathsToLink' and I've also added NIX_LD env variable, but that still doesn't work.

Can nix-ld be used to fix that error, or is it made only for NixOS? Any guidance toward getting that to work would be great :-)

@Mic92
Copy link
Member

Mic92 commented Sep 14, 2023

Should work for containers as well - also you could probably just copy the real thing in if it's just scoped for smaller well scoped projects -> the actual glibc ld.so and set LIBRARY_PATH directly. Using that in copyToRoot might work (untested)?

    nix-ld = let
         libDir = if builtins.elem stdenv.system [ "x86_64-linux" "mips64-linux" "powerpc64le-linux" ]
           then "/lib64"
           else "/lib";

    in pkgs.runCommand "nix-ld" {} ''
      install -D -m755 ${pkgs.nix-ld}/libexec/nix-ld ${libDir}/$(basename ${pkgs.stdenv.cc.bintools.dynamicLinker})
    '';

I am not sure if copyToRoot works well with symlinks, so I used install again which always should work.
Make sure you have a valid file afterwards in /lib64 and that your NIX_LD_LIBRARY_PATH is set for real. Otherwise @nlewo is a better person to ask about nix2container details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants