For our web service(s), we currently build a Docker image (via Nix) and on the servers, start these images via docker run ...
. We build one image per branch (in the CI pipeline), tagging it with the branch, and we have a self-hosted Docker repo to push to.
I wanted to check if just using Nix would be a viable alternative to that, as we build the Docker images using Nix, anyways, so we might save a little time. But I’m not sure how to do that. Does anyone have experience with it?
Here’s what I was thinking about: Assuming we have one machine and thus one Nix store.
- We build the service using Nix.
- We save the out-link to
/etc/nix-services/mywebservice/branchname
, so our regular garbage collection doesn’t just pull the rag. - We then create a systemd service for the thing we just built, referencing
/etc/nix-services/mywebservice/branchname/bin/server --port 1337
as the executable to start. - We start the systemd service.
A few problems remain partly unsolved here:
- We’d love to have auto-updates when the symlink changes. Not sure if systemd can do that on its own? Otherwise, we’d need a service that checks for changes and restarts.
- How do we delete symlinks that are not used anymore? This could also be a script, of course, so it’s doable.
- How would the workflow look like if we had more than one machine?