cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.61k stars 262 forks source link

Is there a way to modify pg_hba.conf from within the declaration? #1212

Open ElrohirGT opened 2 weeks ago

ElrohirGT commented 2 weeks ago

Hi! I've been trying to develop a serverless API using SAM and would like it to connect to the postgres that devenv services wakes up. Long story short, I need the postgres to accept connections from all IP's, but this can only be changed from within pg_hba.conf. How would I go about defining this inside the nix file?

Here's the error it gives when trying to connect to it: image

ElrohirGT commented 2 weeks ago

In the end I couldn't find a way to configure the pg_hba.conf directly from the configuratino that devenv offers. So I created a helper service instead whose whole job is to copy my custom pg_hba.conf file into the correct directoy that devenv creates. It has the caveat that I need to restart the DB service manually to make the changes take effect but it's good enough for my usecase which is running it manually in local. Here's the code for this service:

flake.nix

processes = {
              pg_setup = {
                exec = "cat pg_hba.conf > ./.devenv/state/postgres/pg_hba.conf";
                process-compose = {
                  depends_on = {
                    postgres = {
                      condition = "process_healthy";
                    };
                  };
                };
              };
            };

pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                  METHOD
host           all                       all                  0.0.0.0/0                     trust

This is a hack and I don't like having to restart the service manually because that wrecks all chances of having this in CI but it's a workaround for local development.