{ config ,lib, self, pkgs, ... }: let cfg = config.services.forgejo; srv = cfg.settings.server; # aidé getHostsFromDir = dir: let entries = builtins.readDir dir; hostDirs = lib.filterAttrs (_: type: type == "directory") entries; in lib.mapAttrsToList (name: _: let infoPath = dir + "/${name}/info.nix"; # On importe info.nix s'il existe info = if builtins.pathExists infoPath then import infoPath else { }; in { inherit name info; } ) hostDirs; # On récupère les listes de toutes les VM et machines physiques (même sans default.nix !) allVms = getHostsFromDir ../../../hosts/vm; allPhysiques = getHostsFromDir ../../../hosts/physiques; allHosts = allVms ++ allPhysiques; # fin de l'aides # On refait la liste des gatus endpoints endpointsFromInfos = lib.concatMap (host: let customEndpoints = host.info.gatus.endpoints or [ ]; in customEndpoints ) allHosts; gatus-announce = pkgs.writeShellScriptBin "gatus-announce" '' set -euo pipefail FILE="/var/lib/gatus/config/99-announcements.yaml" YQ="${pkgs.yq-go}/bin/yq" if [ ! -f "$FILE" ] || [ ! -s "$FILE" ]; then echo "announcements: []" > "$FILE" chmod 644 "$FILE" fi case "''${1:-}" in add) TYPE="''${2:-}" MESSAGE="''${3:-}" if [ -z "$TYPE" ] || [ -z "$MESSAGE" ]; then echo "Usage: sudo gatus-announce add \"\"" exit 1 fi TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ") TS="$TIMESTAMP" TY="$TYPE" MSG="$MESSAGE" \ $YQ -i '.announcements = [{"timestamp": strenv(TS), "type": strenv(TY), "message": strenv(MSG), "archived": false}] + (.announcements // [])' "$FILE" chmod 644 "$FILE" echo "Annonce ajoutée ($TYPE) : $MESSAGE" ;; list) $YQ '.announcements | to_entries | .[] | "[" + (.key | tostring) + "] (" + (if .value.archived then "archivée" else "ACTIVE" end) + ") [" + .value.type + "] " + .value.message' "$FILE" ;; archive) INDEX="''${2:-}" if [ -z "$INDEX" ]; then echo "Usage: sudo gatus-announce archive " exit 1 fi $YQ -i ".announcements[$INDEX].archived = true" "$FILE" chmod 644 "$FILE" echo "Annonce [$INDEX] archivée." ;; clear) $YQ -i '(.announcements[] | select(.archived == false)).archived = true' "$FILE" chmod 644 "$FILE" echo "Toutes les annonces actives ont été archivées." ;; *) echo "Commandes disponibles :" echo " sudo gatus-announce add \"\" -> Ajoute une nouvelle annonce" echo " sudo gatus-announce list -> Affiche les annonces et leur index" echo " sudo gatus-announce archive -> Archive une annonce précise" echo " sudo gatus-announce clear -> Archive toutes les annonces actives" exit 1 ;; esac ''; in { environment.systemPackages = [ gatus-announce ]; services.openssh.settings.AcceptEnv = [ "GIT_PROTOCOL" ]; services.forgejo = { enable = true; settings = { server = { DOMAIN = "git-test.crans.org"; ROOT_URL = "https://${srv.DOMAIN}"; HTTP_PORT = 3000; }; service = { DISABLE_REGISTRATION = true; }; }; }; services.gatus = { enable = true; openFirewall = false; settings = { web.port = 8080; ui.title = "Page Status Crans"; ui.description = "Show all Status for Crans infrasctructure"; ui.dashboard-heading = "Crans Status"; ui.dashboard-subheading = "Monitor the health of Crans endpoints in real-time"; ui.header = "Crans"; ui.logo = ../../../assets/logo_crans_dark.png ; ui.favicon.default = ../../../assets/logo_crans_dark.png ; ui.link = "https://crans.org"; storage.type = "memory"; #storage.path = "gatus.db"; endpoints = endpointsFromInfos; skip-invalid-config-update = true; }; }; users.users.gatus = { isSystemUser = true; group = "gatus"; }; users.groups.gatus = {}; systemd.services.gatus.serviceConfig = { }; # Override the systemd service to watch a directory instead of the single /nix/store file systemd.services.gatus = { environment = { GATUS_CONFIG_PATH = lib.mkForce "/var/lib/gatus/config"; }; serviceConfig = { StateDirectory = "gatus"; ExecStartPre = let generatedConfig = (pkgs.formats.yaml { }).generate "gatus-base.yaml" config.services.gatus.settings; in pkgs.writeShellScript "gatus-setup-config" '' mkdir -p /var/lib/gatus/config ln -sf ${generatedConfig} /var/lib/gatus/config/00-base.yaml echo "announcements: - timestamp: "2026-11-12T01:00:00Z" type: outage message: "Investigating elevated latency on EU servers." archived: false" >> /var/lib/gatus/config/99-announcements.yaml ''; DynamicUser = lib.mkForce false; User = "gatus"; Group = "gatus"; }; }; }