Boot into rescue mode with disabled root account

If you need to get a root shell on a NixOS[1] machine and the root account is disabled/locked (and/or you’ve forgotten all your passwords), here’s how to do it (without booting a live ISO).

When the machine boots, interrupt the bootloader and add this to the bootloader command-line:

[...] rescue systemd.setenv=SYSTEMD_SULOGIN_FORCE=1

(Without SYSTEMD_SULOGIN_FORCE=1 you will not be able to get a shell if the root account is disabled/locked.)


[1]: Or any GNU/Linux distro really.