31 lines
927 B
Bash
31 lines
927 B
Bash
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
source "$(dirname "$0")/../common.sh"
|
|
|
|
print_info "Available generations:"
|
|
if [[ "$EUID" -ne 0 ]]; then
|
|
sudo nix-env --profile /nix/var/nix/profiles/system --list-generations
|
|
else
|
|
nix-env --profile /nix/var/nix/profiles/system --list-generations
|
|
fi
|
|
|
|
echo -n "Enter generation number to rollback to: "
|
|
read -r GEN_NUM
|
|
|
|
if [[ -z "$GEN_NUM" ]]; then
|
|
print_error "No generation number provided"
|
|
exit 1
|
|
fi
|
|
|
|
print_warning "Rolling back to generation $GEN_NUM..."
|
|
if [[ "$EUID" -ne 0 ]]; then
|
|
sudo nix-env --profile /nix/var/nix/profiles/system --switch-generation "$GEN_NUM" && \
|
|
sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch
|
|
else
|
|
nix-env --profile /nix/var/nix/profiles/system --switch-generation "$GEN_NUM" && \
|
|
/nix/var/nix/profiles/system/bin/switch-to-configuration switch
|
|
fi
|
|
|
|
print_success "Rollback to generation $GEN_NUM complete"
|