FYI: building Docker image with Nix


Assuming you have default.nix in the project directory and can build your project with nix-build. Also you have a Dockerfile:

FROM scratch # !!!
ADD out.tar.gz /
RUN ["/out/bin/foo", "whatever", "to", "prepare", "the", "image"]
CMD ["/out/bin/bar", "--socket", ":8000"] # Just an example

Then build your Docker image from scratch with only Nix closure inside:

nix-build default.nix -o out \
&& tar czf out.tar.gz out $(nix-store -qR out) \
&& docker build . -t foo

Tips for taking the step from using a `nix-shell` for development to using `nix` in CI?