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

# Nomarchy Update Available Script
# Checks if flake updates are available and returns info for Waybar

REPO_DIR=""
if [ -f "/etc/nixos/flake.nix" ]; then
    REPO_DIR="/etc/nixos"
elif [ -f "/etc/nomarchy/flake.nix" ]; then
    REPO_DIR="/etc/nomarchy"
fi

if [ -z "$REPO_DIR" ]; then
    echo "Nomarchy repo not found."
    exit 0
fi

# Fast-fail if offline to avoid expensive nix commands.
if ! ping -c 1 -W 2 1.1.1.1 >/dev/null 2>&1; then
    exit 0
fi

# Get current status
CURRENT_REV=$(nix flake metadata "$REPO_DIR" --json | jq -r '.lock.nodes.root.inputs.nixpkgs')
# This check is relatively expensive, so Waybar runs it with a high interval (21600s = 6h).

# Just return an icon if we are in a system that can be updated.
echo ""
