{ config, containerCfg, pkgs, lib, builder, name, ... }:
let 
version = "latest";
serverCfg = config.syscfg.server;
in {
  requires.secrets = [ name ];

  runtime = {
    containers = {
      server = builder.mkContainer {
        subdomain = containerCfg.subdomain;
        image = "collabora/code:${version}";
        port = 9980;
        secret = name;
        extraEnv = {
          "aliasgroup1" = "https://${serverCfg.containers.nextcloud.subdomain}.${serverCfg.domain}";
          "server_name" = "${containerCfg.subdomain}.${serverCfg.domain}";
          "username" = "collabora_user";
          "VIRTUAL_HOST" = "${containerCfg.subdomain}.${serverCfg.domain}";
          "VIRTUAL_PORT" = "9980";
          "VIRTUAL_PROTO" = "http";
          "DONT_GEN_SSL_CERT" = "true";
          "RESOLVE_TO_PROXY_IP" = "true";
          "extra_params" = "--o:ssl.enable=false --o:ssl.termination=true";
          "dictionaries" = "en fr de jp no";
        };
        
        overrides = {
          volumes = [
            "${pkgs.noto-fonts}/share/fonts/noto:/opt/collaboraoffice/share/fonts/truetype/noto:ro"
            "${pkgs.ibm-plex}/share/fonts/opentype:/opt/collaboraoffice/share/fonts/opentype/plex:ro"
          ];
        };
      };
    };
  };
}
