Merge pull request #95880 from aanderse/postgresql-settings
nixos/postgresql: replace extraConfig option with settings option
This commit is contained in:
commit
bcdcd5d9fc
@ -11,23 +11,23 @@ let
|
|||||||
then cfg.package
|
then cfg.package
|
||||||
else cfg.package.withPackages (_: cfg.extraPlugins);
|
else cfg.package.withPackages (_: cfg.extraPlugins);
|
||||||
|
|
||||||
|
toStr = value:
|
||||||
|
if true == value then "yes"
|
||||||
|
else if false == value then "no"
|
||||||
|
else if isString value then "'${lib.replaceStrings ["'"] ["''"] value}'"
|
||||||
|
else toString value;
|
||||||
|
|
||||||
# The main PostgreSQL configuration file.
|
# The main PostgreSQL configuration file.
|
||||||
configFile = pkgs.writeText "postgresql.conf"
|
configFile = pkgs.writeText "postgresql.conf" (concatStringsSep "\n" (mapAttrsToList (n: v: "${n} = ${toStr v}") cfg.settings));
|
||||||
''
|
|
||||||
hba_file = '${pkgs.writeText "pg_hba.conf" cfg.authentication}'
|
|
||||||
ident_file = '${pkgs.writeText "pg_ident.conf" cfg.identMap}'
|
|
||||||
log_destination = 'stderr'
|
|
||||||
log_line_prefix = '${cfg.logLinePrefix}'
|
|
||||||
listen_addresses = '${if cfg.enableTCPIP then "*" else "localhost"}'
|
|
||||||
port = ${toString cfg.port}
|
|
||||||
${cfg.extraConfig}
|
|
||||||
'';
|
|
||||||
|
|
||||||
groupAccessAvailable = versionAtLeast postgresql.version "11.0";
|
groupAccessAvailable = versionAtLeast postgresql.version "11.0";
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
imports = [
|
||||||
|
(mkRemovedOptionModule [ "services" "postgresql" "extraConfig" ] "Use services.postgresql.settings instead.")
|
||||||
|
];
|
||||||
|
|
||||||
###### interface
|
###### interface
|
||||||
|
|
||||||
@ -212,10 +212,28 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig = mkOption {
|
settings = mkOption {
|
||||||
type = types.lines;
|
type = with types; attrsOf (oneOf [ bool float int str ]);
|
||||||
default = "";
|
default = {};
|
||||||
description = "Additional text to be appended to <filename>postgresql.conf</filename>.";
|
description = ''
|
||||||
|
PostgreSQL configuration. Refer to
|
||||||
|
<link xlink:href="https://www.postgresql.org/docs/11/config-setting.html#CONFIG-SETTING-CONFIGURATION-FILE"/>
|
||||||
|
for an overview of <literal>postgresql.conf</literal>.
|
||||||
|
|
||||||
|
<note><para>
|
||||||
|
String values will automatically be enclosed in single quotes. Single quotes will be
|
||||||
|
escaped with two single quotes as described by the upstream documentation linked above.
|
||||||
|
</para></note>
|
||||||
|
'';
|
||||||
|
example = literalExample ''
|
||||||
|
{
|
||||||
|
log_connections = true;
|
||||||
|
log_statement = "all";
|
||||||
|
logging_collector = true
|
||||||
|
log_disconnections = true
|
||||||
|
log_destination = lib.mkForce "syslog";
|
||||||
|
}
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
recoveryConfig = mkOption {
|
recoveryConfig = mkOption {
|
||||||
@ -245,6 +263,16 @@ in
|
|||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
|
services.postgresql.settings =
|
||||||
|
{
|
||||||
|
hba_file = "${pkgs.writeText "pg_hba.conf" cfg.authentication}";
|
||||||
|
ident_file = "${pkgs.writeText "pg_ident.conf" cfg.identMap}";
|
||||||
|
log_destination = "stderr";
|
||||||
|
log_line_prefix = cfg.logLinePrefix;
|
||||||
|
listen_addresses = if cfg.enableTCPIP then "*" else "localhost";
|
||||||
|
port = cfg.port;
|
||||||
|
};
|
||||||
|
|
||||||
services.postgresql.package =
|
services.postgresql.package =
|
||||||
# Note: when changing the default, make it conditional on
|
# Note: when changing the default, make it conditional on
|
||||||
# ‘system.stateVersion’ to maintain compatibility with existing
|
# ‘system.stateVersion’ to maintain compatibility with existing
|
||||||
|
@ -14,13 +14,10 @@ let
|
|||||||
baseBackupDir = "/tmp/pg_basebackup";
|
baseBackupDir = "/tmp/pg_basebackup";
|
||||||
walBackupDir = "/tmp/pg_wal";
|
walBackupDir = "/tmp/pg_wal";
|
||||||
atLeast12 = lib.versionAtLeast pkg.version "12.0";
|
atLeast12 = lib.versionAtLeast pkg.version "12.0";
|
||||||
restoreCommand = ''
|
|
||||||
restore_command = 'cp ${walBackupDir}/%f %p'
|
|
||||||
'';
|
|
||||||
|
|
||||||
recoveryFile = if atLeast12
|
recoveryFile = if atLeast12
|
||||||
then pkgs.writeTextDir "recovery.signal" ""
|
then pkgs.writeTextDir "recovery.signal" ""
|
||||||
else pkgs.writeTextDir "recovery.conf" "${restoreCommand}";
|
else pkgs.writeTextDir "recovery.conf" "restore_command = 'cp ${walBackupDir}/%f %p'";
|
||||||
|
|
||||||
in {
|
in {
|
||||||
name = "postgresql-wal-receiver-${postgresqlPackage}";
|
name = "postgresql-wal-receiver-${postgresqlPackage}";
|
||||||
@ -30,14 +27,17 @@ let
|
|||||||
services.postgresql = {
|
services.postgresql = {
|
||||||
package = pkg;
|
package = pkg;
|
||||||
enable = true;
|
enable = true;
|
||||||
extraConfig = ''
|
settings = lib.mkMerge [
|
||||||
wal_level = archive # alias for replica on pg >= 9.6
|
{
|
||||||
max_wal_senders = 10
|
wal_level = "archive"; # alias for replica on pg >= 9.6
|
||||||
max_replication_slots = 10
|
max_wal_senders = 10;
|
||||||
'' + lib.optionalString atLeast12 ''
|
max_replication_slots = 10;
|
||||||
${restoreCommand}
|
}
|
||||||
recovery_end_command = 'touch recovery.done'
|
(lib.mkIf atLeast12 {
|
||||||
'';
|
restore_command = "cp ${walBackupDir}/%f %p";
|
||||||
|
recovery_end_command = "touch recovery.done";
|
||||||
|
})
|
||||||
|
];
|
||||||
authentication = ''
|
authentication = ''
|
||||||
host replication ${replicationUser} all trust
|
host replication ${replicationUser} all trust
|
||||||
'';
|
'';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user