GRUB did not install?

Hey everyone,

Yesterday I installed NixOS, and after some tinkering I got it working. Pretty happy (for now) with the setup. However something went wrong with my GRUB install, and for educational reasons I would like to know why.

My main disk is /dev/nvme (abbreviated), GPT, has windows and ubuntu installed on it, with the Grub bootloader. By default, my laptop UEFI boots the /dev/nvme Grub.

My second disk is /dev/sda, MBR, with only a data partition on it for backups. This is where I installed NixOS. Because of MBR, I decided to go with the legacy install. Shrunk the data partition and added an ext4 partition, leaving the initial 1MB of the disk unformatted. I figured I could just select /dev/sda in the uefi boot menu after installing NixOS, get redirected to the NixOS GRUB, and proceed from there.

To accomplish this I added the following to my configuration.nix during installation:

# Disable UEFI completely, afaik
boot.loader.systemd-boot.enable = false; 
boot.loader.efi.canTouchEfiVariables = false;
# Turn GRUB on completely, expect it to be installed to bootsector of /dev/sda
boot.loader.grub.enable = true; 
boot.loader.grub.version = 2;
boot.loader.grub.device = "/dev/sda";

I mounted /dev/sda2 (the ext4 partition) to /mnt, and executed swapon on /dev/nvmep6 (the swap partition of ubuntu).

Installation went fine, no problems. However, afterwards selecting /dev/sda at the uefi boot menu did not work. If I select /dev/sda for booting in the boot menu the screen goes black for a second and then the same boot menu reappears, no messages unfortunately. However, GRUB does seem to be installed to /boot on my /dev/sda nixos partition. I used this to boot to NixOS anyway by adding the following snippet to the /dev/nvme Ubuntu GRUB, which luckily does not care about MBR, GPT and whatnot:

menuentry "NixOS" --class gnu-linux --class gnu {
    set root=(hd1,msdos2)
    configfile /boot/grub/grub.cfg


In this case, (hd1,msdos2) is my nixos mbr partition on /dev/sda.

This works even better than I expected, because now I can select NixOS from the grub menu, which is more user friendly than the uefi boot menu. However, I am still wondering why selecting Grub in the uefi boot menu does not work. I have three theories:

  • You cannot boot a MBR grub from a UEFI boot menu. Therefore, regardless of GRUB installing properly, uefi will not allow you to boot it.
  • I should’ve added boot.loader.efi.enable = false;. Because I did not do this, it is set to true by default somehow, which means nixos installs grub to boot even though I would have liked it to be installed in the boot sector of /dev/sda. But, this flag or something similar does not seem to exist?
  • Both

Does someone know what went wrong, what I did wrong, or how I can debug this to find out if this is either a broken grub on /dev/sda, or my uefi being picky? (Preferably without breaking my current nixos install)