{ config, lib, pkgs, ... }:

with lib;

mkIf (elem "nextcloud" config.machine.services) {
  services.nextcloud = {
    enable = true;
    home = "/var/lib/nextcloud";
    hostName = "storage.${config.machine.domain}";
    https = true;
    maxUploadSize = "1024M";
    config = {
      adminuser = "derped";
      adminpassFile = "/secret/nextcloud_admin";
      dbtype = "mysql";
      dbhost = "localhost";
      dbport = "3306";
      dbuser = "nextcloud";
      dbpassFile = "/secret/nextcloud_db";
      dbname = "nextcloud";
      dbtableprefix = "oc_";
    };
    caching = {
      apcu = true;
      memcached = true;
      redis = false;
    };
  };
}