Factor out postgresql

This commit is contained in:
Nathan McCarty 2023-05-07 00:50:39 -04:00
parent 2826bb8ad0
commit 0eeadc535f
Signed by: thatonelutenist
SSH Key Fingerprint: SHA256:hwQEcmak9E6sdU9bXc98RHw/Xd1AhpB5HZT7ZSVJkRM
5 changed files with 34 additions and 19 deletions

View File

@ -45,6 +45,7 @@
passwordFile = config.sops.secrets."borg-password".path; passwordFile = config.sops.secrets."borg-password".path;
sshKey = config.sops.secrets."borg-ssh-key".path; sshKey = config.sops.secrets."borg-ssh-key".path;
}; };
postgresql.backup = true;
}; };
config = { config = {
setupGrub = false; setupGrub = false;
@ -117,15 +118,6 @@
extraConfigFiles = [ config.sops.secrets."matrix-secrets.yaml".path ]; 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 # Install our utilties
environment.systemPackages = with pkgs; [ matrix-synapse-tools.synadm ]; environment.systemPackages = with pkgs; [ matrix-synapse-tools.synadm ];

View File

@ -55,6 +55,7 @@
passwordFile = config.sops.secrets."borg-password".path; passwordFile = config.sops.secrets."borg-password".path;
sshKey = config.sops.secrets."borg-ssh-key".path; sshKey = config.sops.secrets."borg-ssh-key".path;
}; };
postgresql.backup = true;
}; };
config = { config = {
setupGrub = false; setupGrub = false;
@ -97,14 +98,6 @@
root = "/var/www/pack.forward-progress.net"; 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 # Setup the gitlab runners
services.gitlab-runner = let services.gitlab-runner = let
nix-shared = with lib; { nix-shared = with lib; {

View File

@ -25,6 +25,7 @@ in {
./services/matrix.nix ./services/matrix.nix
./services/ipfs.nix ./services/ipfs.nix
./services/resolved.nix ./services/resolved.nix
./services/postgresql.nix
]; ];
options = with lib; options = with lib;
@ -86,6 +87,10 @@ in {
enable = mkEnableOption "nginx"; enable = mkEnableOption "nginx";
acme = mkEnableOption "ACME Integration"; acme = mkEnableOption "ACME Integration";
}; };
postgresql = {
enable = mkEnableOption "postgresql";
backup = mkEnableOption "postgresqlbackup";
};
# Matrix # Matrix
matrix = { matrix = {
enable = mkEnableOption "matrix"; enable = mkEnableOption "matrix";

View File

@ -1,14 +1,15 @@
{ config, lib, pkgs, inputs, ... }: { config, lib, pkgs, inputs, ... }@orig:
let nathan = config.nathan; let nathan = config.nathan;
in with lib; { in with lib; {
config = mkMerge [ config = mkMerge [
(mkIf nathan.services.matrix.enable { (mkIf nathan.services.matrix.enable {
# Enable nginx # Enable nginx
nathan.services.nginx.enable = true; nathan.services.nginx.enable = true;
# Enable postresql
nathan.services.postgresql = { enable = true; };
services = { services = {
# Setup postgres # Setup postgres
postgresql = { postgresql = {
enable = true;
initialScript = pkgs.writeText "synapse-init.sql" '' initialScript = pkgs.writeText "synapse-init.sql" ''
CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'matrix-synapse'; CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'matrix-synapse';
CREATE DATABASE "synapse" WITH OWNER "synapse" CREATE DATABASE "synapse" WITH OWNER "synapse"

View File

@ -0,0 +1,24 @@
{ config, lib, pkgs, ... }:
let nathan = config.nathan;
in with lib; {
config = mkMerge [
(mkIf nathan.services.postgresql.enable {
services.postgresql = {
enable = true;
settings = { };
};
})
(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";
};
})
];
}