nixos-config/switch.sh
2025-03-10 21:11:14 +04:00

20 lines
627 B
Bash
Executable File

#!/usr/bin/env bash
# Helper script to switch between NixOS configurations
set -e
# Default to the nixos configuration if no argument is provided
CONFIG=${1:-nixos}
# Check if the configuration exists in flake.nix
if ! grep -q "nixosConfigurations.$CONFIG" flake.nix; then
echo "Error: Configuration '$CONFIG' not found in flake.nix"
echo "Available configurations:"
grep -o "nixosConfigurations\.[a-zA-Z0-9_-]*" flake.nix | sed 's/nixosConfigurations\./ - /'
exit 1
fi
echo "Switching to configuration: $CONFIG"
sudo nixos-rebuild switch --flake ".#$CONFIG"
echo "Successfully switched to $CONFIG configuration"