os/hosts/pie/invoiceplane.nix

88 lines
2.4 KiB
Nix

{
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";
owner = "invoiceplane";
};
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 = "127.0.0.1";
port = 3306;
createLocally = false;
};
poolConfig = {
"pm" = "dynamic";
"pm.max_children" = 32;
"pm.max_requests" = 500;
"pm.max_spare_servers" = 4;
"pm.min_spare_servers" = 2;
"pm.start_servers" = 2;
"php_admin_value[error_log]" = "/var/lib/invoiceplane/invoicing.b12f.io/logs/php-error.log";
"php_admin_flag[display_errors]" = "off";
"php_admin_flag[log_errors]" = "on";
"catch_workers_output" = "yes";
};
};
virtualisation = {
oci-containers = {
backend = "docker";
containers."invoiceplane-db" = {
image = "mariadb:11";
autoStart = true;
ports = [ "3306:3306" ];
volumes = [
"/var/lib/invoiceplane/db:/var/lib/mysql"
];
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 = ''
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"
'';
rcloneConfigFile = config.age.secrets."rclone-pie.conf".path;
};
};
}