Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added custom option and config #1368

Merged
merged 4 commits into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading