#!/usr/bin/env bash

# Nomarchy System Update Script
# 1. Applies system-wide NixOS changes

set -e

# Detect the repository location
if [ -f "/etc/nixos/flake.nix" ]; then
    REPO_DIR="/etc/nixos"
elif [ -f "/etc/nomarchy/flake.nix" ]; then
    REPO_DIR="/etc/nomarchy"
else
    echo "Error: Nomarchy flake repository not found in /etc/nixos or /etc/nomarchy."
    exit 1
fi

# Apply NixOS changes from the local flake
echo "Applying system-level changes from $REPO_DIR..."
sudo nixos-rebuild switch --flake "$REPO_DIR#default" --impure

echo "System update complete."
