Resetting your password on NixOS
What to do after if you accidentally lock yourself out
When messing around with my NixOS config during an install, I managed to accidentally log myself out of my system by setting my hashedPassword to a string that was not a hash.
Much of the time, the easiest way to fix this will be to revert to an earlier configuration in the bootloader (this being NixOS and all), but my situation was a bit special because this was the first configuration following a fresh install.
I was not inclined to go through the reinstall process, so fortunately, after a bit of searching and experimentation, I was able to reset my password by rebooting into single user mode. I set out the steps below for the benefit of my future self (lest this happen again) and any other foolhardy NixOS tinkerers.
You can enter single user mode by amending the kernel parameters at the GRUB boot menu:
- Select the desired NixOS boot entry
- Press e to edit the boot entry
- Append the following:
single systemd.setenv=SYSTEMD_SULOGIN_FORCE=1
- Continue to boot
You should get a root prompt and can then reset your user's password using passwd
, e.g. passwd huey
.