How to "restore" or "generate" boot partition from nixos-enter environment?

I’ve recently installed NixOS on ZFS. I have two NVMe drives and both of them have two partitions: 1G for “EFI System” (EF00) and the rest of the disk space for “Solaris root” (BF00). ZFS pool has a single mirror vdev that consists of two BF00 partitions mentioned above. The EF00 partitions are formatted with mkfs.vfat -F 32. I’ve also configured GRUB to use both of these partitions (with mirroredBoots option).

Here’s the relevant snippet of my configuration.nix:

  boot.loader.grub = {
    enable = true;
    efiSupport = true;
    mirroredBoots = [
      {
        path = "/boot";
        devices = [ "nodev" ];
      }
      {
        path = "/boot-fallback";
        devices = [ "nodev" ];
      }
    ];
  };

  boot.zfs.devNodes = "/dev/disk/by-id";
  boot.supportedFilesystems = [ "zfs" ];
  boot.loader.efi.canTouchEfiVariables = true;

  fileSystems."/" = {
    device = "zroot/os";
    fsType = "zfs";
  };

  fileSystems."/nix" = {
    device = "zroot/nix";
    fsType = "zfs";
  };

  fileSystems."/home" = {
    device = "zroot/home";
    fsType = "zfs";
  };

  fileSystems."/boot" = {
    device = "/dev/disk/by-uuid/2710-238A";
    fsType = "vfat";
    options = [ "nofail" ];
  };

  fileSystems."/boot-fallback" = {
    device = "/dev/disk/by-uuid/2778-3DBA";
    fsType = "vfat";
    options = [ "nofail" ];
  };

The configuration seems to work as expected, but I’m a bit worried that ZFS snapshots won’t include /boot and /boot-fallback.

In case of boot partitions corruption, is there a way to “restore” or “generate” /boot using NixOS Live USB and nixos-enter (or some other utilities)?

1 Like

You can just use nixos-install again, I believe. That will install a “new” profile that’s exactly the same as your current one, and as part of the process reinstall the bootloader.

You can also manually use nixos-enter and run the script upstream runs to install the bootloader: https://github.com/NixOS/nixpkgs/blob/bb8b5735d6f7e06b9ddd27de115b0600c1ffbdb4/nixos/modules/installer/tools/nixos-install.sh#L199

Oh, seems the wiki has instructions too: Bootloader - NixOS Wiki

2 Likes