{ config, lib, pkgs, ... }: with lib; let rootCfg = config.selfhosted; common = rootCfg.common; moduleCfg = rootCfg.seafile; cfg = moduleCfg.notification; hostDataPath = "${common.dataDir}/seafile"; in { imports = [ ./config.nix ]; options.selfhosted.seafile.notification = { name = mkOption { type = types.str; }; hostHttpPort = mkOption { type = types.port; }; }; config = mkIf moduleCfg.enable { virtualisation.oci-containers.containers.${cfg.name} = { image = "docker.io/seafileltd/notification-server:13.0-latest"; ports = [ "0.0.0.0:${toString cfg.hostHttpPort}:8083" ]; environmentFiles = [ config.sops.templates."seafile-notification.env".path ]; volumes = [ "${hostDataPath}/notification/logs:/shared/seafile/logs" ]; log-driver = "journald"; extraOptions = [ "--network=${common.network.name}" ]; }; systemd.services."${common.backend}-${cfg.name}" = { serviceConfig = { Restart = lib.mkOverride 90 "always"; }; wantedBy = [ "${common.backend}-${moduleCfg.targetName}.target" ]; partOf = [ "${common.backend}-${moduleCfg.targetName}.target" ]; requires = [ "${common.backend}-${moduleCfg.mariadb.name}.service" "${common.backend}-${moduleCfg.server.name}.service" ]; after = [ "${common.backend}-${moduleCfg.mariadb.name}.service" "${common.backend}-${moduleCfg.server.name}.service" ]; path = with pkgs; [ curl gawk ]; preStart = '' echo "Waiting for Seafile server to be ready..." for i in {1..60}; do status=$(curl -sI --max-time 5 "http://localhost:${toString moduleCfg.server.hostHttpPort}" | head -1 | awk '{print $2}') if [[ "$status" =~ ^(200|301|302)$ ]]; then echo "Seafile server is up (HTTP $status, attempt $i)" break fi echo "Seafile not ready yet (status: $status) ... ($i/60)" sleep 1 done mkdir -p ${hostDataPath}/notification ''; }; }; }