|
| 1 | +{ |
| 2 | + lib, |
| 3 | + nixosModulesPath, |
| 4 | + config, |
| 5 | + ... |
| 6 | +}: |
| 7 | +let |
| 8 | + cfg = config.supabase.services.logrotate; |
| 9 | +in |
| 10 | +{ |
| 11 | + imports = map (path: nixosModulesPath + path) [ |
| 12 | + # FIXME: we can't use the logrotate module from nixpkgs becauce it's defined as a no-op option in system-manager: |
| 13 | + # https://github.com/numtide/system-manager/blob/main/nix/modules/default.nix#L102-L108 |
| 14 | + # |
| 15 | + # error: The option `services.logrotate' in module `/nix/store/...-source/nix/modules' |
| 16 | + # would be a parent of the following options,but its type `attribute set' does not support nested options. |
| 17 | + # |
| 18 | + # "/services/logging/logrotate.nix" |
| 19 | + ]; |
| 20 | + |
| 21 | + options = { |
| 22 | + supabase.services.logrotate = { |
| 23 | + enable = lib.mkEnableOption "Whether to enable the logrotate systemd service."; |
| 24 | + }; |
| 25 | + }; |
| 26 | + |
| 27 | + config = lib.mkIf cfg.enable { |
| 28 | + environment.etc = { |
| 29 | + "logrotate.d/logrotate-postgres-auth.conf".text = '' |
| 30 | + /var/log/postgresql/auth-failures.csv { |
| 31 | + size 10M |
| 32 | + rotate 5 |
| 33 | + compress |
| 34 | + delaycompress |
| 35 | + notifempty |
| 36 | + missingok |
| 37 | + } |
| 38 | + ''; |
| 39 | + "logrotate.d/logrotate-postgres-csv.conf".text = '' |
| 40 | + /var/log/postgresql/postgresql.csv { |
| 41 | + size 50M |
| 42 | + rotate 9 |
| 43 | + compress |
| 44 | + delaycompress |
| 45 | + notifempty |
| 46 | + missingok |
| 47 | + postrotate |
| 48 | + sudo -u postgres /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data logrotate |
| 49 | + endscript |
| 50 | + } |
| 51 | + ''; |
| 52 | + "logrotate.d/logrotate-postgres.conf".text = '' |
| 53 | + /var/log/postgresql/postgresql.log { |
| 54 | + size 50M |
| 55 | + rotate 3 |
| 56 | + copytruncate |
| 57 | + delaycompress |
| 58 | + compress |
| 59 | + notifempty |
| 60 | + missingok |
| 61 | + } |
| 62 | + ''; |
| 63 | + "logrotate.d/logrotate-walg.conf".text = '' |
| 64 | + /var/log/wal-g/*.log { |
| 65 | + size 50M |
| 66 | + rotate 3 |
| 67 | + copytruncate |
| 68 | + delaycompress |
| 69 | + compress |
| 70 | + notifempty |
| 71 | + missingok |
| 72 | + } |
| 73 | + ''; |
| 74 | + }; |
| 75 | + |
| 76 | + # FIXME: logrotate.service isn't a valid unit file (missing ExecStart), because it's already provided by Ubuntu: |
| 77 | + # systemd.services.logrotate = { |
| 78 | + # wantedBy = lib.mkForce [ |
| 79 | + # "system-manager.target" |
| 80 | + # ]; |
| 81 | + # }; |
| 82 | + |
| 83 | + # Try to overide systemd logrotate.timer to run every 5 minutes |
| 84 | + # https://umuttechin.medium.com/overriding-systemd-unit-files-on-linux-30f44d925f72 |
| 85 | + systemd.timers.logrotate = { |
| 86 | + wantedBy = [ "timers.target" ]; |
| 87 | + timerConfig.OnCalendar = "*:0/5"; |
| 88 | + timerConfig.Persistent = true; |
| 89 | + }; |
| 90 | + }; |
| 91 | +} |
0 commit comments