{ config, ... }:
let
  abDomain = "${config.clan.core.vars.generators.b4l-actual-budget.files.subdomain.value}.${config.networking.fqdn}";
in
{
  clan.core.vars.generators.b4l-actual-budget = {
    files.subdomain.secret = false;

    prompts = {
      subdomain = {
        persist = true;
        type = "line";
        description = "Sub-domain for Actual Budget app. Default:(budget)";
      };
    };

    script = ''cat $prompts/subdomain || echo -n "budget" > $out/subdomain'';
  };

  services.actual = {
    settings = {
      allowedLoginMethods = [
        "password"
        "openid"
      ];
      trustedProxies = [ "127.0.0.1" ];
    };
  };
  services.nginx.virtualHosts."${abDomain}" = {
    useACMEHost = "${config.networking.fqdn}";
    forceSSL = true;
    locations."/" = {
      proxyPass = "http://localhost:${builtins.toString config.services.actual.settings.port}";
    };
  };
}
