diff --git a/machines/matrix/configuration.nix b/machines/matrix/configuration.nix index 6ef88de..000ee46 100644 --- a/machines/matrix/configuration.nix +++ b/machines/matrix/configuration.nix @@ -45,6 +45,7 @@ passwordFile = config.sops.secrets."borg-password".path; sshKey = config.sops.secrets."borg-ssh-key".path; }; + postgresql.backup = true; }; config = { setupGrub = false; @@ -117,15 +118,6 @@ extraConfigFiles = [ config.sops.secrets."matrix-secrets.yaml".path ]; }; - # Backup postgres - services.postgresqlBackup = { - enable = true; - compression = "none"; - backupAll = true; - # Every monring at 4 AM - startAt = "*-*-* 4:00:00"; - }; - # Install our utilties environment.systemPackages = with pkgs; [ matrix-synapse-tools.synadm ]; diff --git a/machines/oracles/configuration.nix b/machines/oracles/configuration.nix index 0eba7f0..740504c 100644 --- a/machines/oracles/configuration.nix +++ b/machines/oracles/configuration.nix @@ -55,6 +55,7 @@ passwordFile = config.sops.secrets."borg-password".path; sshKey = config.sops.secrets."borg-ssh-key".path; }; + postgresql.backup = true; }; config = { setupGrub = false; @@ -97,14 +98,6 @@ root = "/var/www/pack.forward-progress.net"; }; - # Backup postgres, as used by matrix - services.postgresqlBackup = { - enable = true; - compression = "none"; - backupAll = true; - startAt = "OnCalendar=00/2:00"; - }; - # Setup the gitlab runners services.gitlab-runner = let nix-shared = with lib; { diff --git a/modules/linux/default.nix b/modules/linux/default.nix index 98e3f1c..7326f33 100644 --- a/modules/linux/default.nix +++ b/modules/linux/default.nix @@ -25,6 +25,7 @@ in { ./services/matrix.nix ./services/ipfs.nix ./services/resolved.nix + ./services/postgresql.nix ]; options = with lib; @@ -86,6 +87,10 @@ in { enable = mkEnableOption "nginx"; acme = mkEnableOption "ACME Integration"; }; + postgresql = { + enable = mkEnableOption "postgresql"; + backup = mkEnableOption "postgresqlbackup"; + }; # Matrix matrix = { enable = mkEnableOption "matrix"; diff --git a/modules/linux/services/matrix.nix b/modules/linux/services/matrix.nix index e92523a..55c27a0 100644 --- a/modules/linux/services/matrix.nix +++ b/modules/linux/services/matrix.nix @@ -1,14 +1,15 @@ -{ config, lib, pkgs, inputs, ... }: +{ config, lib, pkgs, inputs, ... }@orig: let nathan = config.nathan; in with lib; { config = mkMerge [ (mkIf nathan.services.matrix.enable { # Enable nginx nathan.services.nginx.enable = true; + # Enable postresql + nathan.services.postgresql = { enable = true; }; services = { # Setup postgres postgresql = { - enable = true; initialScript = pkgs.writeText "synapse-init.sql" '' CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'matrix-synapse'; CREATE DATABASE "synapse" WITH OWNER "synapse" diff --git a/modules/linux/services/postgresql.nix b/modules/linux/services/postgresql.nix new file mode 100644 index 0000000..15605a8 --- /dev/null +++ b/modules/linux/services/postgresql.nix @@ -0,0 +1,21 @@ +{ config, lib, pkgs, ... }: +let nathan = config.nathan; +in with lib; { + config = mkMerge [ + (mkIf nathan.services.postgresql.enable { + services.postgresql = { enable = true; }; + }) + (mkIf + (nathan.services.postgresql.enable && nathan.services.postgresql.backup) { + # Backup postgres + services.postgresqlBackup = { + enable = true; + compression = "zstd"; + compressionLevel = 6; + backupAll = true; + # Every morning at 4 AM + startAt = "*-*-* 4:00:00"; + }; + }) + ]; +}