2023-10-21 20:46:17 +00:00
|
|
|
{
|
|
|
|
flake,
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
psCfg = config.pub-solar;
|
|
|
|
xdg = config.home-manager.users."${psCfg.user.name}".xdg;
|
|
|
|
backupDir = "/var/lib/invoiceplane/backup";
|
|
|
|
in {
|
|
|
|
age.secrets."invoiceplane-db-password.age" = {
|
|
|
|
file = "${flake.self}/secrets/invoiceplane-db-password.age";
|
|
|
|
mode = "600";
|
2023-10-24 13:54:18 +00:00
|
|
|
owner = "invoiceplane";
|
2023-10-21 20:46:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
age.secrets."invoiceplane-db-secrets.env" = {
|
|
|
|
file = "${flake.self}/secrets/invoiceplane-db-secrets.env";
|
|
|
|
mode = "600";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.invoiceplane.sites."invoicing.b12f.io" = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
database = {
|
|
|
|
user = "invoiceplane";
|
|
|
|
name = "invoiceplane";
|
|
|
|
passwordFile = config.age.secrets."invoiceplane-db-password.age".path;
|
|
|
|
host = "localhost";
|
2023-10-24 13:54:18 +00:00
|
|
|
port = 3306;
|
2023-10-21 20:46:17 +00:00
|
|
|
createLocally = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation = {
|
|
|
|
oci-containers = {
|
|
|
|
backend = "docker";
|
|
|
|
containers."invoiceplane-db" = {
|
2023-10-24 13:54:18 +00:00
|
|
|
image = "mariadb:11";
|
2023-10-21 20:46:17 +00:00
|
|
|
autoStart = true;
|
2023-10-24 13:54:18 +00:00
|
|
|
ports = [ "3306:3306" ];
|
2023-10-21 20:46:17 +00:00
|
|
|
volumes = [
|
2023-10-24 13:54:18 +00:00
|
|
|
"/var/lib/invoiceplane/db:/var/lib/mysql"
|
2023-10-21 20:46:17 +00:00
|
|
|
];
|
|
|
|
environmentFiles = [
|
|
|
|
config.age.secrets."invoiceplane-db-secrets.env".path
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${backupDir}' 0700 root root - -"
|
|
|
|
];
|
|
|
|
|
|
|
|
services.restic.backups = {
|
|
|
|
invoiceplane = {
|
|
|
|
paths = [
|
|
|
|
backupDir
|
|
|
|
"/var/lib/invoiceplane/invoicing.b12f.io"
|
|
|
|
];
|
|
|
|
initialize = true;
|
|
|
|
passwordFile = config.age.secrets."restic-password.age".path;
|
|
|
|
# See https://www.hosting.de/blog/verschluesselte-backups-mit-rclone-und-restic-in-nextcloud/
|
|
|
|
repository = "rclone:cloud.pub.solar:/backups/InvoicePlane";
|
|
|
|
backupPrepareCommand = ''
|
2023-10-24 13:54:18 +00:00
|
|
|
PW=$(cat ${config.age.secrets."invoiceplane-db-password.age".path})
|
|
|
|
${pkgs.docker-client}/bin/docker exec -t invoiceplane-db mariadb-dump --all-databases --password=$PW --user=invoiceplane > "${backupDir}/postgres.sql"
|
2023-10-21 20:46:17 +00:00
|
|
|
'';
|
|
|
|
rcloneConfigFile = config.age.secrets."rclone-pie.conf".path;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|