insert a nixos bootable drive
run this command to get list of drives
lsblk
enter sudo mode
sudo -i
mount the bad drive in my case nvme0n1pe2 is the main partition and nvme0n1pe1 is the boot partition
mount /dev/nvme0n1p2 /mnt
mount /dev/nvme0n1p1 /mnt/boot
add all the channels you had on your bad drive to confirm them run
nixos-enter
then
sudo nix-channel --list
this will give the list of all the channels
now you can exit it by typing
exit
nixos-enter
pick a previous generation you want the build to be based on
NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system-<generation-number>-link/bin/switch-to-configuration boot
example:
NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system-113-link/bin/switch-to-configuration boot
thats all you can reboot you pc and everything should be back to normal
now add the channels. In my case i use nixos unstable and home manager so i will run
nix-channel --add https://nixos.org/channels/nixos-unstable nixos
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
and after adding all the channels we update our channels by running
nix-channel --update
then finally run
nixos-install
at the end it will ask you for password