2023-10-08 17:32:00 +00:00
|
|
|
{
|
|
|
|
flake,
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
2023-10-09 20:52:28 +00:00
|
|
|
}: let
|
|
|
|
psCfg = config.pub-solar;
|
|
|
|
xdg = config.home-manager.users."${psCfg.user.name}".xdg;
|
|
|
|
backupDir = "/var/lib/firefly/backup";
|
|
|
|
in {
|
2023-10-08 17:32:00 +00:00
|
|
|
age.secrets."firefly-secrets.env" = {
|
2023-11-05 17:56:11 +00:00
|
|
|
file = "${flake.self}/secrets/firefly-secrets.env.age";
|
2023-11-12 17:19:07 +00:00
|
|
|
mode = "400";
|
2023-10-08 17:32:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
age.secrets."firefly-db-secrets.env" = {
|
2023-11-05 17:56:11 +00:00
|
|
|
file = "${flake.self}/secrets/firefly-db-secrets.env.age";
|
2023-11-12 17:19:07 +00:00
|
|
|
mode = "400";
|
2023-10-08 17:32:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
age.secrets."firefly-importer-secrets.env" = {
|
2023-11-05 17:56:11 +00:00
|
|
|
file = "${flake.self}/secrets/firefly-importer-secrets.env.age";
|
2023-11-12 17:19:07 +00:00
|
|
|
mode = "400";
|
2023-11-05 17:56:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
age.secrets."firefly-cron-secrets.env" = {
|
|
|
|
file = "${flake.self}/secrets/firefly-cron-secrets.env.age";
|
2023-11-12 17:19:07 +00:00
|
|
|
mode = "400";
|
2023-10-08 17:32:00 +00:00
|
|
|
};
|
|
|
|
|
2023-11-14 17:44:46 +00:00
|
|
|
security.acme.certs = {
|
|
|
|
"firefly.b12f.io" = {};
|
|
|
|
"firefly-importer.b12f.io" = {};
|
|
|
|
};
|
2023-11-13 14:48:05 +00:00
|
|
|
|
2023-11-14 17:44:46 +00:00
|
|
|
services.nginx.virtualHosts = {
|
|
|
|
"firefly.b12f.io" = {
|
|
|
|
forceSSL = true;
|
|
|
|
useACMEHost = "firefly.b12f.io";
|
|
|
|
locations."/".proxyPass = "http://127.0.0.1:8080";
|
|
|
|
};
|
|
|
|
"firefly-importer.b12f.io" = {
|
|
|
|
forceSSL = true;
|
2023-11-14 21:52:43 +00:00
|
|
|
useACMEHost = "firefly-importer.b12f.io";
|
2023-11-14 17:44:46 +00:00
|
|
|
locations."/".proxyPass = "http://127.0.0.1:8081";
|
|
|
|
};
|
2023-10-08 17:32:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services."docker-network-firefly" = let
|
|
|
|
docker = config.virtualisation.oci-containers.backend;
|
|
|
|
dockerBin = "${pkgs.${docker}}/bin/${docker}";
|
|
|
|
in {
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
before = ["docker-firefly.service"];
|
|
|
|
script = ''
|
|
|
|
${dockerBin} network inspect firefly >/dev/null 2>&1 || ${dockerBin} network create firefly --subnet 172.20.0.0/24
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation = {
|
|
|
|
oci-containers = {
|
|
|
|
backend = "docker";
|
|
|
|
|
|
|
|
containers."firefly" = {
|
|
|
|
image = "fireflyiii/core:latest";
|
|
|
|
autoStart = true;
|
|
|
|
volumes = [
|
|
|
|
"/var/lib/firefly/upload:/var/www/html/storage/upload"
|
|
|
|
];
|
|
|
|
extraOptions = [ "--network=firefly" ];
|
|
|
|
environmentFiles = [
|
|
|
|
./.env.firefly
|
|
|
|
config.age.secrets."firefly-secrets.env".path
|
2023-11-05 17:56:11 +00:00
|
|
|
config.age.secrets."firefly-cron-secrets.env".path
|
2023-10-08 17:32:00 +00:00
|
|
|
];
|
2023-11-01 15:27:29 +00:00
|
|
|
ports = [ "127.0.0.1:8080:8080" ];
|
2023-10-08 17:32:00 +00:00
|
|
|
dependsOn = [ "firefly-db" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
containers."firefly-db" = {
|
|
|
|
image = "postgres:16";
|
|
|
|
autoStart = true;
|
|
|
|
volumes = [
|
|
|
|
"/var/lib/firefly/db:/var/lib/postgresql/data"
|
|
|
|
];
|
|
|
|
extraOptions = [ "--network=firefly" ];
|
|
|
|
environmentFiles = [
|
|
|
|
config.age.secrets."firefly-db-secrets.env".path
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
containers."firefly-importer" = {
|
|
|
|
image = "fireflyiii/data-importer:latest";
|
|
|
|
autoStart = true;
|
|
|
|
extraOptions = [ "--network=firefly" ];
|
2023-11-01 15:27:29 +00:00
|
|
|
ports = [ "127.0.0.1:8081:8080" ];
|
2023-10-11 12:32:09 +00:00
|
|
|
environment = {
|
2023-11-01 15:27:29 +00:00
|
|
|
FIREFLY_III_URL = "https://firefly.b12f.io";
|
2023-10-11 12:32:09 +00:00
|
|
|
};
|
2023-10-08 17:32:00 +00:00
|
|
|
environmentFiles = [
|
2023-10-24 13:54:18 +00:00
|
|
|
./.env.firefly-importer
|
2023-10-08 17:32:00 +00:00
|
|
|
config.age.secrets."firefly-importer-secrets.env".path
|
|
|
|
];
|
|
|
|
dependsOn = [ "firefly" ];
|
|
|
|
};
|
|
|
|
|
2023-11-05 17:56:11 +00:00
|
|
|
containers."firefly-cron" = {
|
|
|
|
image = "alpine";
|
|
|
|
autoStart = true;
|
|
|
|
cmd = [
|
|
|
|
"sh"
|
|
|
|
"-c"
|
|
|
|
"echo \"0 3 * * * wget -qO- http://firefly:8080/api/v1/cron/$STATIC_CRON_TOKEN\" | crontab - && crond -f -L /dev/stdout"
|
|
|
|
];
|
|
|
|
environmentFiles = [
|
|
|
|
config.age.secrets."firefly-cron-secrets.env".path
|
|
|
|
];
|
|
|
|
extraOptions = [ "--network=firefly" ];
|
|
|
|
};
|
2023-10-08 17:32:00 +00:00
|
|
|
};
|
|
|
|
};
|
2023-10-09 20:52:28 +00:00
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${backupDir}' 0700 root root - -"
|
|
|
|
];
|
|
|
|
|
|
|
|
services.restic.backups = {
|
|
|
|
firefly = {
|
|
|
|
paths = [
|
|
|
|
backupDir
|
|
|
|
"/var/lib/firefly/upload"
|
|
|
|
];
|
|
|
|
initialize = true;
|
2023-11-05 17:56:11 +00:00
|
|
|
passwordFile = config.age.secrets."restic-password".path;
|
2023-10-09 20:52:28 +00:00
|
|
|
# See https://www.hosting.de/blog/verschluesselte-backups-mit-rclone-und-restic-in-nextcloud/
|
|
|
|
repository = "rclone:cloud.pub.solar:/backups/FireflyIII";
|
|
|
|
backupPrepareCommand = ''
|
2023-10-09 21:09:24 +00:00
|
|
|
${pkgs.docker-client}/bin/docker exec -t firefly-db pg_dumpall -c -U firefly > "${backupDir}/postgres.sql"
|
2023-10-09 20:52:28 +00:00
|
|
|
'';
|
|
|
|
rcloneConfigFile = config.age.secrets."rclone-pie.conf".path;
|
|
|
|
};
|
|
|
|
};
|
2023-10-08 17:32:00 +00:00
|
|
|
}
|