Moving Haskell binary built with Nix - Nix

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Magnus Therning

I thought I'd try Nix with one of the systems at work. However, building with Nix, and then using the standard way of creating a Docker image, i.e. COPY result/bin/foo /usr/local/bin, results in the image containing a binary that looks a bit wonky

file ./foo
./foo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/qb6k4hp7gk331x9fydw0w7qj4dv09bwz-glibc-2.27/lib/, for GNU/Linux 2.6.32, stripped

and won't start

bash: ./foo: No such file or directory

Is there some easy way out of this?

Magnus Therning

Nope, just changed the building of the binaries, stack -> nix.
Wanted to take one step at a time and not scare co-workers too much :grinning_face_with_smiling_eyes:

Sridhar Ratnakumar

try statically linking your binaries

Magnus Therning

I tried adding both enableStaticLibraries and justStaticExecutables, but no luck there.

Magnus Therning

I guess I'll have to have a look at pkgs.dockerTools sooner than I hoped for.

Magnus Therning

Could it be that link to the linker that's to blame?

        /nix/store/qb6k4hp7gk331x9fydw0w7qj4dv09bwz-glibc-2.27/lib/ => /usr/lib64/ (0x00007f630f222000)
Magnus Therning

Thanks! I ended up going with the standard stuff though, haskellPackages.developPackage and dockerTools.buildImage, and it turns out it's rather a lot easier than I initially thought. Only a few small things I need to work out before I can ditch Dockerfile completely.