Nixos-rebuild switch isn't updating the Grub menu with new generations

Recently, I noticed that my new generations are not being added to the Grub menu. I have been using my NixOS system (with Windows in dual boot) for about 2 years now without facing this issue.

Issue:

Running the command:

$ sudo nixos-rebuild switch --flake .

I am getting the following message in the output:

warning: Git tree '/home/abdulla/.dotfiles' is dirty
updating GRUB 2 menu...
/nix/store/m101dg80ngyjdb02g6jwy80sr7kzj26g-bash-5.2p26/bin/bash: line 1: /etc/grub.d/30_os-prober: No such file or directory

(note: I believe Git isn’t causing this issue but just leaving that message here just in case other’s think it could be the cause of the mess up.)

Relevant post/reading:

I have seen relevant post here and they mentioned that /boot is not mounted as one expects. Though I am unsure how to change that to the proper one?

I have also looked at Reinstalling the Bootloader command in bootloader wiki in NixOS that supposedly fixes all bootloader issues, but running the command isn’t working for me. The command (note: I have pasted the error of this command at the end):

$ sudo nixos-rebuild --install-bootloader boot

I also read in the bootloader wiki that :

The usual fix for this problem is to add the missing entry for fileSystems."/boot" in hardware-configuration.nix (or where your mount points are defined).

But it seems that the entry is pointing to the proper partition? I think? The following will explain why I think so~

System Inspection:

Looking into my system partitions:

$ sudo fdisk -l

I see that I do have two ESP EFI System:

Device               Start        End   Sectors   Size Type
/dev/nvme0n1p1        2048     534527    532480   260M EFI System
/dev/nvme0n1p7  1177346048 1178574847   1228800   600M EFI System

I believe I created the second ESP when installing NixOS freshly 2 years ago.
So, (if am not mistaken) I just need to tell NixOS to look at /dev/nvme0n1p7 when it is updating the Grub menu? If so, how can I do that?
(I am sorry I am relatively new to these type of boot errors in nix and am not very comfortable with making any changes without understanding or knowing it is safe–afraid I might do more harm then good~)

Also, upon inspecting the UUID of the EFI System Partition:

$ ls -l /dev/disk/by-uuid/
...
lrwxrwxrwx 1 root root 15 Jul 26 10:52 D053-54DE -> ../../nvme0n1p7
...

it matches with the one in hardware-configuration.nix:

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/D053-54DE";
      fsType = "vfat";
    };

So I am not sure what’s causing the new generations to not be added to the grub menu?


Error when Reinstalling the bootloader:

I get the following error after running sudo nixos-rebuild --install-bootloader boot:

error:
       … while evaluating the attribute 'config'

         at /nix/store/72vz3idq9zwhmsbc0xssnyq52iziwlgy-source/lib/modules.nix:334:9:

          333|         options = checked options;
          334|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          335|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/store/72vz3idq9zwhmsbc0xssnyq52iziwlgy-source/lib/modules.nix:334:18:

          333|         options = checked options;
          334|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          335|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)
building Nix...
error:
       … while evaluating the attribute 'config'

         at /nix/store/72vz3idq9zwhmsbc0xssnyq52iziwlgy-source/lib/modules.nix:334:9:

          333|         options = checked options;
          334|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          335|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/store/72vz3idq9zwhmsbc0xssnyq52iziwlgy-source/lib/modules.nix:334:18:

          333|         options = checked options;
          334|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          335|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)
building the system configuration...
error:
       … while evaluating the attribute 'config.system.build.toplevel'

         at /nix/store/72vz3idq9zwhmsbc0xssnyq52iziwlgy-source/lib/modules.nix:334:9:

          333|         options = checked options;
          334|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          335|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/store/72vz3idq9zwhmsbc0xssnyq52iziwlgy-source/lib/modules.nix:334:18:

          333|         options = checked options;
          334|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          335|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)
1 Like

If you’re using flakes then you need to pass the --flake .#<hostname> flag as well.

my apologies, that was a typing error when I was writing the question. The command that I ran was:

sudo nixos-rebuild switch --flake .

I have made the correction in the question~ Thank you~

I meant in the boot command, did you try this?

sudo nixos-rebuild --flake . --install-bootloader boot
1 Like

Ah I didn’t, but I just tried it. I get the following message:

updating GRUB 2 menu...
/nix/store/m101dg80ngyjdb02g6jwy80sr7kzj26g-bash-5.2p26/bin/bash: line 1: /etc/grub.d/30_os-prober: No such file or directory

Perhaps you can do this from a live system? What are your current boot.loader.grub settings?

my current boot.loader.grub settings are:

  boot.loader.grub.enable = true;
  boot.loader.grub.device = "nodev";
  boot.loader.grub.useOSProber = true;

I also tried adding the boot.loader.grub.efiSupport = true; as suggested here, but that gave me the following message in the output. But this didn’t fix the issue as upon restart, new generation weren’t added to the GRUB menu:

updating GRUB 2 menu...
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
lsblk: /dev/mapper/no*[0-9]: not a block device
lsblk: /dev/mapper/block*[0-9]: not a block device
lsblk: /dev/mapper/devices*[0-9]: not a block device
lsblk: /dev/mapper/found*[0-9]: not a block device
Found Windows Boot Manager on /dev/nvme0n1p1@/efi/Microsoft/Boot/bootmgfw.efi

I will try this out now~

So I just tried this (took a while to find a pendrive that works) but this didn’t work as well :disappointed:

Upon booting from a live system, I mounted my root partition and my boot partition with these:

$ sudo mount /dev/nvme0n1p9 /mnt
$ sudo mount /dev/nvme0n1p7 /mnt/boot

And did sudo nixos-enter, which dropped me in a shell of [root@nixos:/]#. I then added the command line from Reinstalling the Bootloader:

$ nixos-enter
[root@nixos:/]# NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system/bin/switch-to-configuration boot

The following is the output that I get:

updating GRUB 2 menu...
/nix/store/m101dg80ngyjdb02g6jwy80sr7kzj26g-bash-5.2p26/bin/bash: line 1: /etc/grub.d/30_os-prober: No such file or directory

which is basically the same as previous cases… :frowning_face:

Okay so I found a fix after reading this issue comment on Github but I have no idea what I did.

I added two new boot.loader settings to the configuration.nix:

  boot.loader.grub.efiSupport = true;
  boot.loader.efi.canTouchEfiVariables = true;

And this fixed the issue.

I did nixos-rebuild switch and this was the output:

$ sudo nixos-rebuild switch --flake .
updating GRUB 2 menu...
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
lsblk: /dev/mapper/no*[0-9]: not a block device
lsblk: /dev/mapper/block*[0-9]: not a block device
lsblk: /dev/mapper/devices*[0-9]: not a block device
lsblk: /dev/mapper/found*[0-9]: not a block device
Found Windows Boot Manager on /dev/nvme0n1p1@/efi/Microsoft/Boot/bootmgfw.efi
installing the GRUB 2 boot loader into /boot...
Installing for x86_64-efi platform.
modprobe: can't change directory to '/lib/modules': No such file or directory
Installation finished. No error reported.
activating the configuration...
setting up /etc...
reloading user units for abdulla...
restarting sysinit-reactivation.target

I restarted my computer and I booted into the new generation. Thank you @eljamm for your help! :heart:

3 Likes