I’m getting a bit deeper into Nix, and I’m trying to translate the following setup to Nix-land.
I have a small web backend that connects to a postgres database. Using docker-compose, I’d probably have something like this:
version: "3.9"
services:
web:
depends_on: ["db"]
build: .
ports:
- "8000:8000"
db:
image: "postgres"
a Dockerfile
that builds my Rust image.
What I have now is the following:
a flake.nix
that defines a default package built with pkgs.dockerTools.buildImage
. This image works fine if I load it with docker normally
a arion-pkgs.nix
that is copy-pasted from the repo
an arion-compose.nix
that looks like this:
{
services.db = {
service.image = "postgres";
service.volumes = [ "${toString ./.}/postgres-data:/var/lib/postgresql/data" ];
service.environment.POSTGRES_PASSWORD = "password";
};
services.backend = {
service.depends_on = [ "db" ];
services.image = "???";
};
}
The question I have is: “how do I tell services.backend
to use the docker image defined in my flake.nix
?”
Any help much appreciated
jmoggr
July 23, 2023, 6:25pm
2
Did you ever figure this out? I’m in the same spot.
jmoggr
July 28, 2023, 1:17pm
3
The author opened an issue in github and got a response there.
opened 06:26AM - 02 Nov 22 UTC
I'm quite new to Nix, so this might just be my inability to read the docs proper… ly, apologies in advance.
I have a `flake.nix` that defines an output which is a docker image built with `pkgs.dockerTools.buildImage`. I'd like to deploy this using arion. Using docker-compose, I'd write something like this as my `docker-compose.yml`:
```yml
version: "3.9"
services:
web:
depends_on: ["db"]
build: .
ports:
- "8000:8000"
db:
image: "postgres"
```
Currently, my best attempt at a `arion-compose.yml` is the following:
```nix
{
services.db = {
service.image = "postgres";
service.volumes = [ "${toString ./.}/postgres-data:/var/lib/postgresql/data" ];
service.environment.POSTGRES_PASSWORD = "password";
};
services.backend = {
service.depends_on = [ "db" ];
service.build = "???";
};
}
```
I'm not sure how to get the image built inside my flake into the `backend` service. Any advice is much appreciated :grin:
What I ended up putting in configuration.nix:
virtualisation.arion = {
backend = "docker";
projects.appName.settings = {
# Specify you project here, or import it from a file.
# NOTE: This does NOT use ./arion-pkgs.nix, but defaults to NixOS' pkgs.
imports = [ ./arion-compose.nix ];
};
};
This works with using flakes for system configuration.