Files
NixOS/modules/ncli/commands/switch.nix
Cookiez 134fc441a5 - Simplified command cases by removing unnecessary semicolons.
- Improved error handling in rebuild.nix for clarity and consistency.
2026-05-29 09:29:31 +02:00

36 lines
1.2 KiB
Nix

# ncli/commands/switch.nix — Specialization switching
lib: {
switch_case = ''
current=""
if [ -f /etc/nixos-tags ]; then
current=$(cat /etc/nixos-tags)
fi
if [ "$#" -ge 2 ]; then
spec_name="$2"
if [ -n "$current" ]; then
echo "Already on specialization: $current. Cannot switch directly to '$spec_name'. Please reboot or return to default first."
else
if [ -d "/run/current-system/specialisation/$spec_name" ]; then
echo "Switching to specialization: $spec_name"
sudo /run/current-system/specialisation/"$spec_name"/bin/switch-to-configuration test
else
echo "Error: Specialization '$spec_name' not found."
echo "Available specializations:"
ls /run/current-system/specialisation/
fi
fi
else
if [ -n "$current" ]; then
echo "Already on a specialization: $current. To switch, please reboot, or use 'sudo nixos-rebuild switch --flake .' to get back to default, and then switch after."
else
specs=$(ls /run/current-system/specialisation/)
echo "Specializations available:"
echo "$specs"
echo ""
echo "To switch to a specialization, run: 'ncli switch <tag>'"
fi
fi
'';
}