{ config, pkgs, ... }:

{
  imports = [
    ./collabora.nix
  ];

  services.nextcloud = {
    enable = true;
    package = pkgs.nextcloud32;
    hostName = "cloud.lyes.eu";
    https = true;
    configureRedis = true;
    maxUploadSize = "10G";

    extraAppsEnable = true;
    extraApps = {
      inherit (config.services.nextcloud.package.packages.apps) mail calendar contacts user_oidc notes richdocuments;
    };

    config = {
      dbtype = "pgsql";
      dbuser = "baba";
      dbname = "baba";
      dbpassFile = config.age.secrets.baba-db-pass.path;
      adminpassFile = config.age.secrets.baba-admin-pass.path;
    };

    phpOptions = {
      "opcache.interned_strings_buffer" = "32";
      "opcache.memory_consumption" = "512";
    };
  };

  services.nginx.virtualHosts.${config.services.nextcloud.hostName} = {
    forceSSL = true;
    enableACME = true;
  };

  age.secrets = {
    baba-db-pass = {
      file = ../../../secrets/zora/services/baba-db-pass.age;
      owner = "nextcloud";
      group = "nextcloud";
    };
    baba-admin-pass = {
      file = ../../../secrets/zora/services/baba-admin-pass.age;
      owner = "nextcloud";
      group = "nextcloud";
    };
  };
}
