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

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

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

  services.nextcloud = {
    hostName = ncDomain;
    package = pkgs.nextcloud32;

    settings = {

      overwriteprotocol = "https";
      trusted_domains = [ ];
      trusted_proxies = [ ];
    };
  };
  services.nginx.virtualHosts."${ncDomain}" = {
    useACMEHost = "${config.networking.fqdn}";
    forceSSL = true;
  };
}
