Resetting your password on NixOS

What to do after if you accidentally lock yourself out

  •  1 min  •  

When messing around with my NixOS config, I managed to accidentally log myself out of my system by setting my hashedPassword to a string that was not a hash.

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:

  1. Select the desired NixOS boot entry
  2. Press e to edit the boot entry
  3. Append the following: single systemd.setenv=SYSTEMD_SULOGIN_FORCE=1
  4. Continue to boot

You should get a root prompt and can then reset your user's password using passwd, e.g. passwd huey.