feat(postgres): add connectionURI option (#143)

resolves #141
This commit is contained in:
Shivaraj B H 2024-03-12 14:24:28 +05:30 committed by GitHub
parent 62fe23fbef
commit 8c25972cfb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -45,7 +45,7 @@
pgcfg = config.services.postgres.pg1;
in
{
environment.PGWEB_DATABASE_URL = "postgres://$USER@${pgcfg.listen_addresses}:${builtins.toString pgcfg.port}/${dbName}";
environment.PGWEB_DATABASE_URL = pgcfg.connectionURI dbName;
command = pkgs.pgweb;
depends_on."pg1".condition = "process_healthy";
};

View File

@ -56,6 +56,14 @@ in
description = "The DB socket directory";
};
# Based on: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS
connectionURI = lib.mkOption {
type = lib.types.functionTo lib.types.str;
readOnly = true;
default = dbName: "postgres://${config.listen_addresses}:${builtins.toString config.port}/${dbName}";
description = "A function that accepts database name and returns the [postgres connection URI](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS)";
};
hbaConf =
let
hbaConfSubmodule = lib.types.submodule {