diff --git a/example/simple/flake.nix b/example/simple/flake.nix index 7e4957a..04fcdb3 100644 --- a/example/simple/flake.nix +++ b/example/simple/flake.nix @@ -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"; }; diff --git a/nix/postgres/default.nix b/nix/postgres/default.nix index 0d48078..5ce96c2 100644 --- a/nix/postgres/default.nix +++ b/nix/postgres/default.nix @@ -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 {