I ran 'sudo nix-channel --update' and 'sudo nixos-rebuild switch,' and I can no longer boot

As the title said, I ran sudo nix-channel --update and sudo nixos-rebuild switch, and I can no longer boot to my desktop (I’m met with Emergency Mode).

Did I follow the wrong procedure? I was attempting to update the channels to also upgrade my packages.

Now, when I boot, regardless of what generation I boot from on the drive, I’m met with Emergency Mode, yet I cannot login when in TTY; it keeps reopening the TTY login screen.

The easiest thing I can do is format the drive and restart it all over again. But part of me wants to see if I can either:

Fix the problem


Restore and boot to the last working configuration.

Any pointers before I decide on my nuclear option to format and reinstall?

EDIT: I wish I followed this method instead… NixOS 23.05 manual | Nix & NixOS

I would check that your drives are listed correctly in your system config.

BTW “reinstall” in terms of formatting should almost never be necessary, you already have your config, so you can boot the live image and reuse said config. Make sure to mount everything relative to /mnt (eg mount root partition to /mnt, your /home partition to /mnt/home, etc), then use nixos-enter to acess your installed system from the live disc.

When you are met with the emergency mode, then you should be presented with some error, knowing this helps to debug your problem, also knowing your configuration can help massively.

Sadly this kind of problems sometimes occur, though they have become much rarer in the last years.

Today they are mostly related to some change in the config rather than indeed faulty nixpkgs. The fact though that you have the problem in all available generations means:

  1. The change in your config that caused the issue has been there for time longer than your GC retention period or
  2. There is indeed a problem with nixpkgs, which we then should try to identify, isolate and fix

As there is noone else reporting a similar problem so far, we have to assume 1 for now.

I was thinking this as well.

Would it make any sense to post my configuration.nix file here? I don’t believe it shows any passwd or any other sensitive user account data.

Do you think enabling “Automatic Upgrades” in my configuration.nix would have prevented the problem, or is it possible that a bad nixpkg could have caused this issue?

The difficult thing is that I haven’t ran any sudo nix-channel --update command since I started using NixOS (3 months ago), and I’ve continuously been running sudo nixos-rebuild switch since I started building my configuration.nix file with various pkgs. Isolating the pkg sounds nearly impossible…

But I have been replicating the config file on other systems… yet now I’m scared to run sudo nix-channel --update or any other form of upgrades for my pkgs…

UPDATE: I tried all the generations, and I’m still met with emergency mode; TTY1. Every time I try to “login” in TTY1, the screen flashes, and it’s expecting me to login again. CTRL+D does the same thing. I don’t think emergency mode is usable in any way… So I won’t be able to extract a system log via journalctl -xb .

I’ve already backed up my files and configuration.nix file, I’m just concerned that I don’t know how this problem started, and that I’d be replicating the same situation since it’s all declared in the config file.

So, I decided to wipe the drive, salvaged my configuration.nix file before formatting it, reinstalled NixOS, used this method to upgrade my packages and keep everything up to date: https://nixos.org/manual/nixos/stable/#sec-upgrading-automatic .

Everything’s working again!

My assumption is that I probably changed the “nix channel” when I ran nix-channel --update. As stated in the manual:


It is generally safe to switch back and forth between channels. The only exception is that a newer NixOS may also have a newer Nix version, which may involve an upgrade of Nix’s database schema. This cannot be undone easily, so in that case you will not be able to go back to your original channel.