diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2023-12-29 22:40:38 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2023-12-29 22:40:38 +0100 |
commit | ae67327df3faaf106d2bcb352d4151774576bf00 (patch) | |
tree | 9675d97cef9bc880e771d6304da44e892fc7f444 /modules | |
parent | d4b30420812cd0b5ec97d6048e32903198b96f38 (diff) | |
download | nixos-ae67327df3faaf106d2bcb352d4151774576bf00.tar nixos-ae67327df3faaf106d2bcb352d4151774576bf00.tar.gz nixos-ae67327df3faaf106d2bcb352d4151774576bf00.tar.bz2 nixos-ae67327df3faaf106d2bcb352d4151774576bf00.tar.xz nixos-ae67327df3faaf106d2bcb352d4151774576bf00.zip |
...
Diffstat (limited to 'modules')
-rw-r--r-- | modules/pgbackrest.nix | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/modules/pgbackrest.nix b/modules/pgbackrest.nix index cc865bca..e02849f5 100644 --- a/modules/pgbackrest.nix +++ b/modules/pgbackrest.nix | |||
@@ -36,6 +36,10 @@ let | |||
36 | } "="; | 36 | } "="; |
37 | }; | 37 | }; |
38 | 38 | ||
39 | mkDSCPOption = options: mkOption { | ||
40 | type = types.numbers.between 0 63; | ||
41 | } // options; | ||
42 | |||
39 | loglevelType = types.enum ["off" "error" "warn" "info" "detail" "debug" "trace"]; | 43 | loglevelType = types.enum ["off" "error" "warn" "info" "detail" "debug" "trace"]; |
40 | inherit (utils.systemdUtils.unitOptions) unitOption; | 44 | inherit (utils.systemdUtils.unitOptions) unitOption; |
41 | in { | 45 | in { |
@@ -44,6 +48,10 @@ in { | |||
44 | enable = mkEnableOption "pgBackRest"; | 48 | enable = mkEnableOption "pgBackRest"; |
45 | 49 | ||
46 | package = mkPackageOption pkgs "pgbackrest" {}; | 50 | package = mkPackageOption pkgs "pgbackrest" {}; |
51 | dscpPackage = mkPackageOption pkgs "libdscp" { nullable = true; default = null; }; | ||
52 | |||
53 | dscp.archive-push = mkDSCPOption { default = 24; }; | ||
54 | dscp.backup = mkDSCPOption { default = 8; }; | ||
47 | 55 | ||
48 | configurePostgresql = { | 56 | configurePostgresql = { |
49 | enable = mkEnableOption "configuring PostgreSQL for sending WAL to pgBackRest" // { | 57 | enable = mkEnableOption "configuring PostgreSQL for sending WAL to pgBackRest" // { |
@@ -145,14 +153,32 @@ in { | |||
145 | environment.systemPackages = [ cfg.package ]; | 153 | environment.systemPackages = [ cfg.package ]; |
146 | 154 | ||
147 | services.postgresql.settings = mkIf cfg.configurePostgresql.enable { | 155 | services.postgresql.settings = mkIf cfg.configurePostgresql.enable { |
148 | archive_command = "pgbackrest --stanza ${escapeSystemdExecArg cfg.configurePostgresql.stanza} archive-push %p"; | 156 | archive_command = let |
157 | pgbackrest-dscp-wrapped = pkgs.writeShellApplication { | ||
158 | name = "pgbackrest-dscp"; | ||
159 | runtimeInputs = [ cfg.package ]; | ||
160 | text = '' | ||
161 | export LD_PRELOAD | ||
162 | LD_PRELOAD=''${LD_PRELOAD:+':'$LD_PRELOAD':'} | ||
163 | if [[ $LD_PRELOAD != *':'''${cfg.dscpPackage}/lib/libdscp.so''':'* ]]; then | ||
164 | LD_PRELOAD='${cfg.dscpPackage}/lib/libdscp.so'$LD_PRELOAD | ||
165 | fi | ||
166 | LD_PRELOAD=''${LD_PRELOAD#':'} | ||
167 | LD_PRELOAD=''${LD_PRELOAD%':'} | ||
168 | |||
169 | : "''${DSCP:=${toString cfg.dscp.archive-push}}" | ||
170 | |||
171 | exec -- pgbackrest "$@" | ||
172 | ''; | ||
173 | }; | ||
174 | pgbackrest = if cfg.dscpPackage != null then "${pgbackrest-dscp-wrapped}/bin/pgbackrest-dscp" else "${cfg.package}/bin/pgbackrest"; | ||
175 | in "${pgbackrest} --stanza ${escapeShellArg cfg.configurePostgresql.stanza} archive-push %p"; | ||
149 | archive_mode = true; | 176 | archive_mode = true; |
150 | max_wal_senders = mkDefault 3; | 177 | max_wal_senders = mkDefault 3; |
151 | wal_level = "replica"; | 178 | wal_level = "replica"; |
152 | }; | 179 | }; |
153 | 180 | ||
154 | systemd.services = { | 181 | systemd.services = { |
155 | postgresql.path = mkIf cfg.configurePostgresql.enable [ cfg.package ]; | ||
156 | pgbackrest-tls-server = mkIf cfg.tlsServer.enable { | 182 | pgbackrest-tls-server = mkIf cfg.tlsServer.enable { |
157 | description = "pgBackRest TLS-Server"; | 183 | description = "pgBackRest TLS-Server"; |
158 | wantedBy = [ "multi-user.target" ]; | 184 | wantedBy = [ "multi-user.target" ]; |
@@ -172,11 +198,6 @@ in { | |||
172 | Group = cfg.tlsServer.group; | 198 | Group = cfg.tlsServer.group; |
173 | ExecStart = "${cfg.package}/bin/pgbackrest server"; | 199 | ExecStart = "${cfg.package}/bin/pgbackrest server"; |
174 | ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; | 200 | ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; |
175 | |||
176 | Environment = [ | ||
177 | "LD_PRELOAD=${pkgs.libdscp}/lib/libdscp.so" | ||
178 | "DSCP=8" | ||
179 | ]; | ||
180 | }; | 201 | }; |
181 | }; | 202 | }; |
182 | } // mapAttrs' (name: backupCfg: nameValuePair "pgbackrest-backup@${escapeSystemdPath name}" { | 203 | } // mapAttrs' (name: backupCfg: nameValuePair "pgbackrest-backup@${escapeSystemdPath name}" { |
@@ -189,9 +210,9 @@ in { | |||
189 | Restart = "on-failure"; | 210 | Restart = "on-failure"; |
190 | RestartSec = "5min"; | 211 | RestartSec = "5min"; |
191 | 212 | ||
192 | Environment = [ | 213 | Environment = mkIf (cfg.dscpPackage != null) [ |
193 | "LD_PRELOAD=${pkgs.libdscp}/lib/libdscp.so" | 214 | "LD_PRELOAD=\"${cfg.dscpPackage}/lib/libdscp.so\"" |
194 | "DSCP=8" | 215 | "DSCP=\"${toString cfg.dscp.backup}\"" |
195 | ]; | 216 | ]; |
196 | }; | 217 | }; |
197 | }) cfg.backups; | 218 | }) cfg.backups; |