{ config, lib, pkgs, ... }:
{
  imports = [
    ./collabora
    ./nginx
  ];

  config = lib.mkIf config.system.fileserver.enable {
    services.nextcloud = {
      enable = true;
      package = pkgs.nextcloud30;
      hostName = "cloud.${config.domains.p2}";
      https = true;
      config = {
        adminuser = config.sysusers.main;
        adminpassFile = "${pkgs.writeText "initial" config.secrets.initialPass}";
      };
      settings = {
        trusted_proxies = [ "127.0.0.1" ];
        trusted_domains = [ "cloud.${config.domains.p2}" ];
        overwriteprotocol = "https";
        mail_smtphost = "mx.${config.domains.p1}";
        mail_domain = "${config.domains.p1}";
        mail_from_address = "noreply";
        mail_smtpauth = "true";
        mail_smtpname = "noreply@${config.domains.p2}";
        mail_smtppassword = config.secrets.noreplyPassword;
        mail_smtpmode = "smtp";
        mail_smtpport = 587;
      };
    };
    environment.persistence."/persist".directories = [
      "/var/lib/nextcloud"
    ];
  };
}
