NixOS hangs on turn off. Reboot works, but removes bootloader

Hi, I’m having a very weird scenario.

I can’t turn off my PC gracefully. I have a Dual Boot with Windows 11, I’m not using grub and is UEFI.
If I turn off the PC, the last message is:

xhci_hcd 0000:08:00.2: xHC error in resume, USBSTS 0x401

And then I need to force shutdown.

Also, if I reboot or my PC, it works, but then it goes directly to Windows as there is no bootloader other than the windows. I have to do nixos-enter and fix the bootloader.

Any ideas on what could happen? I have Nvidia graphics (RTX 2080) and I did follow the hardware configuration from the wiki with stable drivers.

Any hints on how to debug would be appreciated.
Thanks in advance.

Windows likely either removed the Linux bootloader or made the Windows bootloader the first entry. Also when you say, “not grub”, do you mean you are using systemd-boot?

You can use efibootmgr to view the current bootloader order and change it if necessary. It might help to leave the Windows bootloader just as a non-primary entry… otherwise Windows might keep trying to install it’s own. Also make sure the Linux entry is pointing to a grub/systemd-boot specific EFI file and not generic like EFI/BOOT/BOOTX64.EFI.

If somehow the Linux bootloader files are missing from /boot, then a nixos-rebuild boot --install-bootloader ... should fix that. You might still have to fix the bootloader order. Is that how you have fixed it after nixos-enter?

I’m not sure about the reboot issue, are there perhaps any log items about unstopped processes or services?

These are two separate issues. IDK about the former but the latter is likely due to not allowing the bootloader to set EFIVARs. Enable that.

Next you should check your UEFI settings. With EFIVAR support enabled, the NixOS bootloader should be preferred but some UEFIs are buggy piles of crap, so you might have to change the order manually.

Windows doesn’t remove other EFI bootloaders.

Windows overwriting the bootloader was only a thing in MBR times when there could only be one bootloader per device.

Thanks for the help :pray:

I’m using systemd-boot for the entries. I also wanted to have windows as the first entry selected but didn’t find any way to do it by adding that in a configuration (maybe something like auto-windows?)

I just added this config to my configuration.nix:

boot.loader = { efi = {
    canTouchEfiVariables = true;
    efiSysMountPoint = "/boot/efi";

It seems that this is doing the trick :thinking:
I had “canTouchEfiVariables” before, so the new thing is the efiSysMountPoint, but I believe that is the default.

Also, I did enabled XHCI Pre-Boot Mode on my BIOS.

I can turn off and reboot without anything breaking.