Docker image build with nix and includes nix installed in multi user mode

Did anybody dig into this? It looks it should be possible, but before starting to look into this myself, maybe somebody already has something working.

Have a look at GitHub - LnL7/nix-docker: Docker images for the Nix package manager , it has a nix-daemon version.

We also had this thread about all the Docker images available that might be relevant to you: NixOS Docker images are quite old? - #4 by domenkozar

Part of this involves figuring out how to bootstrap a nix store from nothing: nix-copy-closure works to install packages, including nix, but it requires that nix is already installed on the remote machine or container, because it queries the store to figure out what to copy.

There’s dockerTools.buildImageWithNixDb [1] that – from what I can tell – can install both nix and some manifest of packages into a previously empty docker container, but I haven’t had time to fully analyze it yet and see how it works. I believe its implementation is inspired by the NixOS bootstrap builder.

[1] https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/docker/default.nix#L609-L639

dockerTools.buildImageWithNixDB can build a Docker image with a valid Nix database (hash and size) without relying on Docker itself. It is then possible to use Nix from this image.
I personally use this function to build a Hydra image where NIx is in single user mode. But I think it should not be too hard to create a nix.conf file and run the Nix daemon. I could help and review on this topic.

I wasn’t aware of dockerTools.buildImageWithNixDB function. looks like there was some progress since the last time I was looking there. Adding this on my todo list and if nobody at home gets sick I should be able to spend some time on this in 10 days.

Yeah, pretty sure I could simplify my image a bunch with that. The image is multi-user but doesn’t use the nix-daemon by default, but I’ve done that before with an ENTRYPOINT.

Hi! did you manage to make this work? I’m very interested in that too :slight_smile:

Oh, that’s nice. I was looking at various options to run Hydra on a non-NixOS machine. This would be a pretty nice solution. Could you tell a bit more how you did this? What do you use to start/supervise the various Hydra daemons?

I’m using the Hydra NixOS module to build a Docker container with the project GitHub - cloudwatt/nix-container-images: Write container images as NixOS machines. This project translates all systemd services to s6 services in a single container. I’m also adding some init services to configure Hydra with environment variables and to create declarative projects.
It’s part of my todo list to push this image from a private repository to the nix-container-image one since a while… I could try to push a PR on next week.

Do you want to run it with Docker or in a Kubernetes cluster?

Thanks for the pointer. That looks awesome! I will give it a spin and see how far I get.