{ ... }:

{
  networking.firewall.allowedTCPPorts = [
    60300
    9980
  ];

  virtualisation.quadlet = {
    networks.nextcloud = { };

    containers = {
      nextcloud-db = {
        containerConfig = {
          image = "postgres:17";
          networks = [ "nextcloud" ];

          volumes = [
            "/data/nextcloud/db:/var/lib/postgresql/data:Z"
          ];

          environmentFiles = [
            "/data/nextcloud/db.env"
          ];

          exec = "postgres -c listen_addresses='*' -c unix_socket_directories=''";
        };

        serviceConfig.Restart = "always";
      };

      nextcloud-redis = {
        containerConfig = {
          image = "redis:alpine";
          networks = [ "nextcloud" ];
        };

        serviceConfig.Restart = "always";
      };

      nextcloud-app = {
        containerConfig = {
          image = "nextcloud:apache";

          publishPorts = [ "60300:80" ];

          networks = [ "nextcloud" ];

          volumes = [
            "/mnt/snow/Docker/nextcloud/data:/var/www/html:z"
          ];

          # environments로 변경 및 attrset 형식으로 정의
          environments = {
            POSTGRES_HOST = "nextcloud-db";
            REDIS_HOST = "nextcloud-redis";
            NEXTCLOUD_OVERWRITEPROTOCOL = "https";
          };

          environmentFiles = [
            "/data/nextcloud/db.env"
          ];
        };

        unitConfig = {
          Requires = [
            "nextcloud-db.service"
            "nextcloud-redis.service"
          ];

          After = [
            "nextcloud-db.service"
            "nextcloud-redis.service"
          ];
        };

        serviceConfig.Restart = "always";
      };

      nextcloud-cron = {
        containerConfig = {
          image = "nextcloud:apache";

          networks = [ "nextcloud" ];

          volumes = [
            "/mnt/snow/Docker/nextcloud/data:/var/www/html:z"
          ];

          exec = "/cron.sh";
        };

        unitConfig = {
          Requires = [
            "nextcloud-db.service"
            "nextcloud-redis.service"
          ];

          After = [
            "nextcloud-db.service"
            "nextcloud-redis.service"
          ];
        };

        serviceConfig.Restart = "always";
      };

      collabora = {
        containerConfig = {
          image = "collabora/code:latest";

          hostname = "collabora";

          publishPorts = [ "9980:9980" ];

          addCapabilities = [ "MKNOD" ];

          podmanArgs = [
            "--privileged"
            "--tty"
          ];

          # environments로 변경 및 attrset 형식으로 정의
          environments = {
            extra_params = "--o:ssl.enable=false --o:ssl.termination=true";
          };
        };

        serviceConfig.Restart = "always";
      };
    };
  };
}
