Split ncli across multiple files in its own directory
This commit is contained in:
40
modules/ncli/commands/switch.nix
Normal file
40
modules/ncli/commands/switch.nix
Normal file
@ -0,0 +1,40 @@
|
||||
# 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
|
||||
;;
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user