What do you do when you cannot boot into NixOS, and it hangs?

I’m not sure what started this issue, but it might have happened after doing recent sudo nixos-rebuild switch --upgradecommand, and I’m guessing I had to cancel it before it completed.

When I boot my NixOS drive, after inputting my encryption password, shows a bunch of “failed daemons" and ‘services”, and it hangs before showing without ever loading the desktop.

So for instance:

[FAILED] Failed to start Nix Garbage Collector
[FAILED] Failed to start NixOS Upgrade
[FAILED] Failed to start resolvconf update.

So forth.

When I access my previous generations, I’m met with the following:

You are in emergency mode. After logging in, type "journalctl -xb" to view system logs, "systemctl reboot" to reboot, or "exit" to continue bootup

Cannot open access to console, the root account is locked.
See sulogin(8) man page more details.

When errors like these occur, what can be done to fix them?

I generally setup a specialisation with no features and some tools available I don’t usually keep in my home-manager, I use that as a safe mode sort of thing.

What you can do from here is open a live environment with a nixos installer and nixos-enter from the live environment.

1 Like

Why are you mixing manual and automatic updates? This way you can’t really know whether your cancelled update is causing issues or whether a previous update broke.

Anyway failing services are usually a symptom, not the cause. Very likely there were errors before.

If you are unable to log into the emergency mode using your root password, then it is likely that mounting / failed. Then again I’d not expect the service errors to even appear. So it is likely that you disabled root yourself.

So your best bet now is to use a rescue/live USB, mount, nixos-enter, and then try to inspect boot logs for the actual error.

Usually as a good first measure you can always try a store repair on the entered environment.

1 Like

That’s a good question.

I think it was something I was experimenting with at least 3 or 4 years ago that I forgot I had in my config:

# system auto upgrades
system.autoUpgrade = {
	enable = true;
	allowReboot = false;
	channel = "https://channels.nixos.org/nixos-24.11";
};

I guess there’s no point in using it since I manually do most of my upgrades. I just never thought to disable it… But I hashed all the lines out, in case I wanted to revisit it.

I think I was depending on some kind of “automation.” But eventually, I preferred running updates on my own time.

I’m able to mount the drive, and access all my Home files.

So your best bet now is to use a rescue/live USB, mount, nixos-enter

I’m unfamiliar with using nixos-enter.

I have many NixOS drives in various laptops.

With the unbotable drive in a external M.2, and with the ability to mount and access root in the external using another NixOS laptop, what commands should I run to diagnose the unbootable drive?

What command allows me to access and diagnose the external drive via nixos-enter?

Thank you!

nixos-enter is a specialised chroot wrapper that runs a partial system activation.

Within that environment, and if you have mounted everything correctly, you should be able to just use journalctl to inspect logs of previous boot attempts.

My usual recommendation is to do so from the Live usb, using the exact hardware the system is “used to”.