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

# Build and run the Nomarchy VM (installed environment) for testing.

echo "Building Nomarchy VM (Installed Environment)..."
echo "Note: To test the INSTALLER, run 'nomarchy-test-installer' instead."
nix build .#nixosConfigurations.default.config.system.build.vm

if [ $? -eq 0 ]; then
    # Drop any persisted VM disk so activation runs against fresh state.
    # Without this, broken symlinks from a prior activation survive rebuilds
    # and mask fixes on the next launch.
    rm -f ./nomarchy.qcow2
    echo "Success! Launching VM..."
    ./result/bin/run-nomarchy-vm
else
    echo "Error: VM build failed."
    exit 1
fi
