{ config, pkgs, lib, ... }: let npub = config.sovran_systemsOS.nostr_npub; in lib.mkIf (config.sovran_systemsOS.features.haven && npub != "") { # ── Generate Haven runtime config from domain files ─────── systemd.services.haven-runtime-config = { description = "Generate Haven runtime config from domain files"; before = [ "haven.service" ]; requiredBy = [ "haven.service" ]; wantedBy = [ "multi-user.target" ]; serviceConfig = { Type = "oneshot"; RemainAfterExit = true; }; path = [ pkgs.coreutils ]; script = '' HAVEN=$(cat /var/lib/domains/haven) mkdir -p /run/haven cat > /run/haven/runtime.env </dev/null; then echo '[]' > "$FILE" chown haven:haven "$FILE" chmod 770 "$FILE" echo "Wrote valid empty JSON array to $FILE" else echo "$FILE already contains valid JSON, skipping" fi ''; }; systemd.services.haven.after = [ "haven-whitelist-setup.service" "haven-runtime-config.service" ]; systemd.services.haven.wants = [ "haven-whitelist-setup.service" "haven-runtime-config.service" ]; sovran_systemsOS.domainRequirements = [ { name = "haven"; label = "Haven NOSTR Relay"; example = "relay.yourdomain.com"; } ]; }