|
1 | 1 | { config, lib, libS, options, pkgs, utils, ... }:
|
2 | 2 |
|
3 | 3 | let
|
| 4 | + opt = options.services.postgresql; |
4 | 5 | cfg = config.services.postgresql;
|
5 | 6 | cfgu = config.services.postgresql.upgrade;
|
6 | 7 | latestVersion = if pkgs?postgresql_17 then "17" else "16";
|
| 8 | + mkTimerDefault = time: { |
| 9 | + OnBootSec = "10m"; |
| 10 | + OnCalendar = time; |
| 11 | + Persistent = true; |
| 12 | + RandomizedDelaySec = "10m"; |
| 13 | + }; |
7 | 14 | in
|
8 | 15 | {
|
9 | 16 | options.services.postgresql = {
|
|
41 | 48 |
|
42 | 49 | timerConfig = lib.mkOption {
|
43 | 50 | type = lib.types.nullOr (lib.types.attrsOf utils.systemdUtils.unitOptions.unitOption);
|
44 |
| - default = { |
45 |
| - OnCalendar = "02:00"; |
46 |
| - Persistent = true; |
47 |
| - RandomizedDelaySec = "10m"; |
48 |
| - }; |
| 51 | + default = mkTimerDefault "02:00"; |
49 | 52 | example = {
|
50 | 53 | OnCalendar = "06:00";
|
51 | 54 | Persistent = true;
|
|
119 | 122 |
|
120 | 123 | timerConfig = lib.mkOption {
|
121 | 124 | type = lib.types.nullOr (lib.types.attrsOf utils.systemdUtils.unitOptions.unitOption);
|
122 |
| - default = { |
123 |
| - OnCalendar = "03:00"; |
124 |
| - Persistent = true; |
125 |
| - RandomizedDelaySec = "10m"; |
126 |
| - }; |
| 125 | + default = mkTimerDefault "03:00"; |
127 | 126 | example = {
|
128 | 127 | OnCalendar = "06:00";
|
129 | 128 | Persistent = true;
|
|
351 | 350 | };
|
352 | 351 | };
|
353 | 352 |
|
354 |
| - timers = { |
| 353 | + timers = let |
| 354 | + mkTimerConfig = name: lib.mkMerge [ |
| 355 | + (lib.mkDefault opt."${name}".timerConfig.default) |
| 356 | + cfg."${name}".timerConfig |
| 357 | + ]; |
| 358 | + in { |
355 | 359 | postgresql-pg-repack = lib.mkIf cfg.pgRepackTimer.enable {
|
356 |
| - inherit (cfg.vacuumAnalyzeTimer) timerConfig; |
| 360 | + timerConfig = mkTimerConfig "pgRepackTimer"; |
357 | 361 | wantedBy = [ "timers.target" ];
|
358 | 362 | };
|
359 | 363 | postgresql-vacuum-analyze = lib.mkIf cfg.vacuumAnalyzeTimer.enable {
|
360 |
| - inherit (cfg.vacuumAnalyzeTimer) timerConfig; |
| 364 | + timerConfig = mkTimerConfig "vacuumAnalyzeTimer"; |
361 | 365 | wantedBy = [ "timers.target" ];
|
362 | 366 | };
|
363 | 367 | };
|
|
0 commit comments