#!/usr/bin/env bash set -euo pipefail if ! command -v gum &> /dev/null; then echo "gum (from charm.sh) is required but not found in PATH." exit 1 fi if ! command -v jq &> /dev/null; then echo "jq is required but not found in PATH." exit 1 fi # List flake configs without evaluating them HOSTS=() while IFS= read -r line; do HOSTS+=("$line") done < <(nix flake show --json | jq -r '.nixosConfigurations | keys[]') if [ ${#HOSTS[@]} -eq 0 ]; then echo "No NixOS configurations found in flake." exit 1 fi # Prompt user for a config SELECTED=$(printf "%s\n" "${HOSTS[@]}" | gum choose --header="Select a NixOS VM config:") if [ -z "$SELECTED" ]; then echo "No hostname selected. Exiting." exit 1 fi echo "Building VM for flake config: $SELECTED" # Build the VM nix run ".#nixosConfigurations.$SELECTED.config.system.build.vm"