{ flake, config, ... }: let inherit (flake.config.services.instances) firefly-iii; inherit (flake.config.machines.devices) ceres; # localhost = "${ceres.ip.addess0}:${service.ports.port0}"; host = service.domains.url0; service = firefly-iii; in { services = { firefly-iii = { enable = true; dataDir = service.paths.path0; virtualHost = host; poolConfig = { "listen.owner" = config.services.caddy.user; "pm" = "dynamic"; "pm.max_children" = 32; "pm.start_servers" = 2; "pm.min_spare_servers" = 2; "pm.max_spare_servers" = 4; "pm.max_requests" = 500; }; settings = { DB_CONNECTION = "pgsql"; DB_HOST = "localhost"; DB_PORT = 5432; DB_DATABASE = service.name; DB_USERNAME = service.name; APP_URL = "https://${host}"; APP_KEY_FILE = config.sops.secrets."${service.name}-pass".path; DB_PASSWORD_FILE = config.sops.secrets."${service.name}-data".path; }; }; firefly-iii-data-importer = { enable = true; }; caddy = { virtualHosts = { ${host} = { extraConfig = '' root * ${config.services.firefly-iii.package}/public encode gzip php_fastcgi unix//run/phpfpm/firefly-iii.sock { try_files {path} /index.php?{query} trusted_proxies private_ranges } file_server tls ${service.ssl.cert} ${service.ssl.key} ''; }; }; }; }; 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; }) [ "pass" "data" ] ); }; # fileSystems."/var/lib/${service.name}" = { # device = service.paths.path0; # fsType = "none"; # options = [ # "bind" # ]; # depends = [ # ceres.storage0.mount # ]; # }; # users.users.${service.name}.extraGroups = [ "caddy" ]; systemd.tmpfiles.rules = [ "Z ${service.paths.path0} 755 ${service.name} ${service.name} -" "Z ${service.sops.path0} 755 ${service.name} ${service.name} -" ]; networking = { firewall.allowedTCPPorts = [ 8080 8081 5432 ]; }; }