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

  runtime = {
    containers = {
      server = builder.mkContainer {
        authentik = true;
        subdomain = containerCfg.subdomain;
        image = "ghcr.io/suwayomi/suwayomi-server:${version}";
        port = 4567;
        secret = name;

        extraEnv = {
          BIND_PORT = "4567";
          AUTH_MODE = "none";
          WEB_UI_ENABLED = "true";
          WEB_UI_FLAVOR = "WebUI";
          # AUTO_DOWNLOAD_CHAPTERS = true;
          # AUTO_DOWNLOAD_EXCLUDE_UNREAD = true;
          # AUTO_DOWNLOAD_NEW_CHAPTERS_LIMIT = 0;
          # AUTO_DOWNLOAD_IGNORE_REUPLOADS = false;
          # DOWNLOAD_CONVERSIONS = {};
          # SERVE_CONVERSIONS = {};
          # MAX_SOURCES_IN_PARALLEL = 6;
          # UPDATE_EXCLUDE_UNREAD = true;
          # UPDATE_EXCLUDE_STARTED = true;
          # UPDATE_EXCLUDE_COMPLETED = true;
          # UPDATE_INTERVAL = 12; #Hours
          # UPDATE_MANGA_INFO = false;
          DATABASE_TYPE = "POSTGRESQL";
          DATABASE_URL = "postgresql://${builder.host}/suwayomi_db";
          DATABASE_USERNAME = "suwayomi_user";
          FLARESOLVERR_ENABLED = lib.boolToString (builtins.elem "flaresolverr" (((config.syscfg.server.containers.servarr or {}).extra or {}).modules or []));
          FLARESOLVERR_URL = "http://servarr-flaresolverr:8191";
          EXTENSION_REPOS = "[\"https://raw.githubusercontent.com/keiyoushi/extensions/repo/index.min.json\"]"; #https://raw.githubusercontent.com/keiyoushi/extensions/repo/index.min.json
        };

        overrides = {
          volumes = [
            "${serverCfg.path.manga.path}:/home/suwayomi/.local/share/Tachidesk/downloads"
            # "${serverCfg.path.config.path}/suwayomi:/home/suwayomi/.local/share/Tachidesk"
          ];
        };
      };
    };
  };
}
