From 253530ea6ff7aaf9db59e7b6ac7eefa2808d0675 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sat, 30 Jan 2021 22:15:33 +0100 Subject: [PATCH] postgresql-backup: move to own services This way the `startAt` setting is only set once. --- configuration.nix | 4 ++++ services/default.nix | 1 + services/matrix.nix | 6 ++---- services/miniflux.nix | 3 ++- services/postgresql-backup.nix | 19 +++++++++++++++++++ 5 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 services/postgresql-backup.nix diff --git a/configuration.nix b/configuration.nix index 27a5f71..170d7d9 100644 --- a/configuration.nix +++ b/configuration.nix @@ -94,6 +94,10 @@ useACME = true; domain = "monitoring.${config.networking.domain}"; }; + + postgresql-backup = { + enable = true; + }; }; security.acme.acceptTerms = true; diff --git a/services/default.nix b/services/default.nix index c1006e1..c66c1e5 100644 --- a/services/default.nix +++ b/services/default.nix @@ -6,5 +6,6 @@ ./matrix.nix ./miniflux.nix ./monitoring.nix + ./postgresql-backup.nix ]; } diff --git a/services/matrix.nix b/services/matrix.nix index 1eedc98..d5abf9f 100644 --- a/services/matrix.nix +++ b/services/matrix.nix @@ -13,6 +13,7 @@ with lib; let cfg = config.my.services.matrix; + my = config.my; federationPort = { public = 8448; private = 11338; }; clientPort = { public = 443; private = 11339; }; @@ -28,11 +29,8 @@ in { package = pkgs.postgresql_12; }; - services.postgresqlBackup = { - enable = true; + services.postgresqlBackup = mkIf my.services.postgresql-backup.enable { databases = [ "matrix-synapse" ]; - # Borg backup starts at midnight so create DB dump just before - startAt = "*-*-* 23:30:00"; }; services.matrix-synapse = { diff --git a/services/miniflux.nix b/services/miniflux.nix index ab65fe5..bcf3f47 100644 --- a/services/miniflux.nix +++ b/services/miniflux.nix @@ -4,6 +4,7 @@ with lib; let cfg = config.my.services.miniflux; + my = config.my; domain = config.networking.domain; in { @@ -28,7 +29,7 @@ in { config = mkIf cfg.enable { # services.postgresql is automatically enabled by services.miniflux, let's # back it up - services.postgresqlBackup = { + services.postgresqlBackup = mkIf my.services.postgresql-backup.enable { databases = [ "miniflux" ]; }; diff --git a/services/postgresql-backup.nix b/services/postgresql-backup.nix new file mode 100644 index 0000000..bb37914 --- /dev/null +++ b/services/postgresql-backup.nix @@ -0,0 +1,19 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.my.services.postgresql-backup; +in { + options.my.services.postgresql-backup = { + enable = mkEnableOption "Backup SQL databases"; + }; + + config = mkIf cfg.enable { + services.postgresqlBackup = { + enable = true; + # Borg backup starts at midnight so create DB dump just before + startAt = "*-*-* 23:30:00"; + }; + }; +}