dotfiles/modules/nixos/services/firefly/default.nix

125 lines
2.9 KiB
Nix
Raw Normal View History

2025-06-27 01:37:33 -05:00
{ flake, config, ... }:
let
inherit (flake.config.people) user0;
2025-06-27 01:47:26 -05:00
inherit (flake.config.people.users.${user0}) email;
2025-06-27 02:02:14 -05:00
inherit (flake.config.services.instances) firefly-iii web;
2025-06-27 01:37:33 -05:00
inherit (flake.config.machines.devices) ceres;
2025-06-27 02:02:14 -05:00
service = firefly-iii;
2025-06-27 02:29:20 -05:00
localhost = web.localhost.address1;
2025-06-27 01:37:33 -05:00
host = service.domains.url0;
in
{
services = {
firefly-iii = {
enable = true;
2025-06-27 03:45:44 -05:00
virtualHost = "0.0.0.0";
2025-06-27 03:40:36 -05:00
enableNginx = true;
2025-06-27 01:37:33 -05:00
settings = {
APP_KEY_FILE = config.sops.secrets."${service.name}-key".path;
2025-06-27 01:47:26 -05:00
SITE_OWNER = email.address0;
2025-06-27 01:37:33 -05:00
DB_DATABASE = "firefly";
DB_USERNAME = "firefly";
DB_PASSWORD_FILE = config.sops.secrets."${service.name}-pass".path;
2025-06-27 03:27:52 -05:00
TRUSTED_PROXIES = "**";
APP_URL = "https://${host}";
2025-06-27 01:37:33 -05:00
};
};
2025-06-27 03:27:52 -05:00
2025-06-27 03:43:04 -05:00
nginx = {
enable = true;
virtualHosts.${config.services.firefly-iii.virtualHost} = {
listen = [
{
addr = "0.0.0.0";
port = 8080;
}
];
};
};
2025-06-27 03:27:52 -05:00
2025-06-27 03:22:31 -05:00
caddy = {
virtualHosts = {
"${host}" = {
extraConfig = ''
encode gzip
2025-06-27 03:10:31 -05:00
2025-06-27 03:43:04 -05:00
reverse_proxy localhost:8080 {
2025-06-27 03:27:52 -05:00
header_up Host {host}
2025-06-27 03:22:31 -05:00
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto https
header_up X-Forwarded-Host {host}
header_up X-Forwarded-Ssl on
header_up Connection ""
timeout 240s
dial_timeout 240s
}
2025-06-27 03:10:31 -05:00
2025-06-27 03:22:31 -05:00
@session_cookie header Cookie *session*
handle @session_cookie {
header Cache-Control "no-cache, no-store, must-revalidate"
}
2025-06-27 02:27:11 -05:00
2025-06-27 03:22:31 -05:00
request_body {
max_size 64MB
}
2025-06-27 03:27:52 -05:00
2025-06-27 03:22:31 -05:00
tls ${service.ssl.cert} ${service.ssl.key}
'';
};
};
};
2025-06-27 01:37:33 -05:00
};
2025-06-27 01:44:17 -05:00
sops =
let
sopsPath = secret: {
path = "${service.sops.path0}/${service.name}-${secret}";
owner = service.name;
mode = "600";
};
in
{
secrets = builtins.listToAttrs (
map
(secret: {
name = "${service.name}-${secret}";
value = sopsPath secret;
})
[
"key"
"pass"
]
);
};
2025-06-27 02:51:05 -05:00
# fileSystems."/var/lib/${service.name}" = {
# device = service.paths.path0;
# fsType = "none";
# options = [
# "bind"
# ];
# depends = [
# ceres.storage0.mount
# ];
# };
2025-06-27 02:13:52 -05:00
users.users.${service.name}.extraGroups = [
"caddy"
];
2025-06-27 01:37:33 -05:00
systemd.tmpfiles.rules = [
2025-06-27 02:51:05 -05:00
# "Z ${service.paths.path0} 755 ${service.name} ${service.name} -"
2025-06-27 01:37:33 -05:00
"Z ${service.sops.path0} 755 ${service.name} ${service.name} -"
];
networking = {
firewall = {
allowedTCPPorts = [
2025-06-27 03:18:27 -05:00
8080
2025-06-27 01:37:33 -05:00
service.ports.port0
];
};
};
}