51 lines
1.2 KiB
Bash
51 lines
1.2 KiB
Bash
#!/usr/bin/env bash
|
||
|
||
set -euo pipefail
|
||
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'
|
||
NC='\033[0m'
|
||
|
||
print_info() {
|
||
echo -e "${BLUE}ℹ ${NC} $1"
|
||
}
|
||
|
||
print_success() {
|
||
echo -e "${GREEN}✓${NC} $1"
|
||
}
|
||
|
||
print_error() {
|
||
echo -e "${RED}✗${NC} $1"
|
||
}
|
||
|
||
print_warning() {
|
||
echo -e "${YELLOW}⚠${NC} $1"
|
||
}
|
||
|
||
print_info "Available system 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" |