-
Notifications
You must be signed in to change notification settings - Fork 0
Recovery
System recovery and rollback procedures for NullOS.
NixOS provides powerful recovery capabilities through generations, allowing you to roll back changes or recover from a broken system.
1. Boot system 2. Access GRUB menu (press Escape or Shift during boot if hidden) 3. Select "NixOS - All configurations" 4. Choose a previous generation 5. Boot into that generation
Your system will boot with the older configuration.
After booting into an old generation:
# Make it the default
sudo nixos-rebuild switch --rollback
# Or switch to specific generation
sudo nix-env --switch-generation 42 --profile /nix/var/nix/profiles/system
sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switchsudo nix-env --list-generations --profile /nix/var/nix/profiles/systemhome-manager generations-
Boot from NixOS live USB
-
Mount system partitions:
sudo mount /dev/nvme0n1p2 /mnt
sudo mount /dev/nvme0n1p1 /mnt/boot- Enter system:
sudo nixos-enter --root /mnt- Rollback or fix:
nixos-rebuild switch --rollback
# Or edit configuration and rebuild- Reboot:
exit
reboot- Identify the error:
sudo nixos-rebuild switch --flake .#hostname --show-trace- Check recent changes:
git log --oneline -10
git diff HEAD~1- Revert changes:
git revert HEAD
# Or
git reset --hard HEAD~1- Rebuild:
sudo nixos-rebuild switch --flake .#hostname-
Boot into previous generation from GRUB
-
Check what changed:
nix-diff \
/nix/var/nix/profiles/system-42-link \
/nix/var/nix/profiles/system-43-link- Fix and rebuild:
# Edit configuration
sudo nixos-rebuild switch --flake .#hostname# List available backups
sudo restic -r sftp:server:/backups snapshots
# Find file
sudo restic -r sftp:server:/backups ls latest | grep filename
# Restore file
sudo restic -r sftp:server:/backups restore latest \
--target /tmp/restore \
--include /path/to/file# Find deleted file
git log --all --full-history -- path/to/file
# Restore from commit
git checkout commit-hash -- path/to/fileFrom live USB:
# Mount and enter system
sudo mount /dev/sdXn /mnt
sudo mount /dev/sdXm /mnt/boot
sudo nixos-enter --root /mnt
# Reset password
passwd username
# Exit and reboot
exit
rebootSame procedure as user password:
passwd root-
Boot into recovery
-
Clean up:
# Remove old generations
sudo nix-collect-garbage -d
# Optimize store
sudo nix-store --optimise
# Remove unused packages
sudo nix-store --gc- Check space:
df -h /# Verify store
sudo nix-store --verify --check-contents
# Repair
sudo nix-store --verify --check-contents --repair# From live USB, mount and enter
sudo nixos-enter --root /mnt
# Reinstall GRUB
sudo nixos-rebuild switch
# Or manually
sudo grub-install /dev/sdX
sudo nixos-rebuild switch# Reinstall bootloader
bootctl install# Check interface
ip link
# Bring up interface (replace wlan0/eth0 with your interface)
sudo ip link set wlan0 up
# Or use NetworkManager (recommended)
sudo systemctl restart NetworkManager
cmcli cNixOS keeps metadata about generations:
# Rebuild database
sudo nix-store --verify
# Check for corruption
sudo nix-store --verify --check-contents-
Add to kernel parameters:
systemd.unit=emergency.target -
Or at GRUB: Press 'e', add to linux line
-
Boot - drops to root shell
-
Make fixes
-
Continue boot:
systemctl default- Backup home directory
- Save NixOS configuration
- Note installed packages
# From live USB
# Format partitions
sudo mkfs.ext4 /dev/sdXn
sudo mkfs.fat -F 32 /dev/sdXm
# Mount
sudo mount /dev/sdXn /mnt
sudo mkdir -p /mnt/boot
sudo mount /dev/sdXm /mnt/boot
# Restore config
# ... copy NixOS config to /mnt/etc/nixos
# Install
sudo nixos-install
# Restore home
# ... restore from backup- Enable automated Restic backups
- Test restores monthly
- Keep configuration in Git
# Before big changes
git add .
git commit -m "Working config before X change"
# Test changes
sudo nixos-rebuild test --flake .#hostname
# If successful, make permanent
sudo nixos-rebuild switch --flake .#hostname# Don't delete all generations
sudo nix-collect-garbage --delete-older-than 30dWhen system breaks:
- Can you boot into previous generation?
- Do you have a live USB ready?
- Is your NixOS config in Git?
- Do you have recent backups?
- Can you access emergency shell?
- Do you know your disk partition layout?
# Download NixOS ISO
wget https://channels.nixos.org/nixos-unstable/latest-nixos-minimal-x86_64-linux.iso
# Write to USB
sudo dd if=nixos.iso of=/dev/sdX bs=4M status=progressKeep notes on:
- Partition layout
- Encryption setup
- Network configuration
- Hardware details
# Backup config regularly
rsync -av /etc/nixos/ /mnt/backup/nixos-config/
# Or use Git
cd ~/NullOS
git add .
git commit -m "Current working config"
git push- Backup - Automated backup setup
- Troubleshooting - Common issues
- Installation - Fresh install guide