Skip to content

Commit

Permalink
Merge pull request #1368 from ElrohirGT/feat-add-custom-pg-hba-conf
Browse files Browse the repository at this point in the history
feat: Added custom option and config
  • Loading branch information
domenkozar authored Aug 19, 2024
2 parents 64bb347 + 11d0fa9 commit 97e674b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/modules/services/postgres.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ let

configFile = pkgs.writeText "postgresql.conf" (lib.concatStringsSep "\n"
(lib.mapAttrsToList (n: v: "${n} = ${toStr v}") cfg.settings));
setupPgHbaFileScript =
if cfg.hbaConf != null then
let
file = pkgs.writeText "pg_hba.conf" cfg.hbaConf;
in
''cp ${file} "$PGDATA/pg_hba.conf"''
else "";
setupScript = pkgs.writeShellScriptBin "setup-postgres" ''
set -euo pipefail
export PATH=${postgresPkg}/bin:${pkgs.coreutils}/bin
Expand All @@ -100,6 +107,9 @@ let
# Setup config
cp ${configFile} "$PGDATA/postgresql.conf"
# Setup pg_hba.conf
${setupPgHbaFileScript}
if [[ "$POSTGRES_RUN_INITIAL_SCRIPT" = "true" ]]; then
echo
Expand Down Expand Up @@ -276,6 +286,18 @@ in
CREATE ROLE bar;
'';
};

hbaConf = lib.mkOption {
type = types.nullOr types.str;
default = null;
description = ''
The contents of a custom pg_hba.conf file to copy into the postgres installation.
This allows for custom connection rules that you want to establish on the server.
'';
example = lib.literalExpression ''
builtins.readFile ./my-custom/directory/to/pg_hba.conf
'';
};
};

config = lib.mkIf cfg.enable {
Expand Down

0 comments on commit 97e674b

Please sign in to comment.