#!/usr/bin/env bash
set -e

# Select system timezone declaratively for Nomarchy NixOS.

STATE_FILE="/etc/nixos/state.json"

timezone=$(timedatectl list-timezones | gum filter --height 20 --header "Set timezone") || exit 1

tmp=$(mktemp); sudo jq --arg tz "$timezone" '.timezone = $tz' "$STATE_FILE" > "$tmp" && sudo mv "$tmp" "$STATE_FILE"

echo "Timezone is now set to $timezone. Applying changes..."
sudo nomarchy-sys-update
