Usually if you screw up the configuration.nix
you can rollback to a previous generation during boot.
Then you use https://nixos.org/nixos/manual/#sec-rollback to fix the rollback generation.
However if you really screw it up, and none of the generations work, you may need use a recovery method.
Get a NixOS ISO (it's best to get one that has a same or similar version as your current one).
Boot into the NixOS ISO. Then once you're booted. You need to setup the root filesystem. In most cases, you only need:
/mnt
/mnt/boot
/mnt/tmp
Then you can use nixos-install
which will do a nixos-rebuild
but targetting /mnt
.
You may not need /mnt/boot
if you are not also rebuilding any of the boot directory.