Installing nixos from another linux distro, can't install grub

Hey all,

I’m trying to install nixos from Arch Linux. I’ve followed the section on the manual referring to this approach, I must say that it is very well written and the overall experience was very smooth! I do have some comments though but they are out of scope for this thread.

On Arch Linux, I have Syslinux installed as my boot loader. The problem I have is that after I run the command:

$ sudo mv -v /boot /boot.bak &&
    sudo /nix/var/nix/profiles/system/bin/switch-to-configuration boot

I get an error on reboot from my BIOS, saying that “syslinux can’t load ldlinux.c32” - meaning somehow my BIOS tries to load syslinux.

My suspicion is that there’s a problem in /etc/nixos/configuration.nix and I’ll need to rerun sudo /nix/var/nix/profiles/system/bin/switch-to-configuration boot. How can I know if my grub configuration in /etc/nixos/configuration.nix should fit my hardware? I’m using an Intel NUC and here are the relevant parts it relating boot:

# Use the GRUB 2 boot loader.
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
# boot.loader.grub.efiSupport = true;
# boot.loader.grub.efiInstallAsRemovable = true;
# boot.loader.efi.efiSysMountPoint = "/boot/efi";
# Define on which hard drive you want to install Grub.
boot.loader.grub.device = "/dev/sda"; # or "nodev" for efi only

Am I missing something?

Thankfully, after I get the Syslinux error from the BIOS on reboot I only need to mv /mnt/boot{,.nix} && mv /mnt/boot{.bak,} so I’m not panicked because of this and I’m patient.

Is your Arch install booting in EFI?

I don’t know. I installed it a long time ago and I forgot. I read about the subject on the internet and I gained some more knowledge but I’m still unsure.

I can tell you that lsblk shows me only 1 partition on my main hard drive /dev/sda - /dev/sda1 and that’s it.

EDIT:

I tried setting boot.loader.grub.efiSupport to true, I ran:

sudo -E nix-env -p /nix/var/nix/profiles/system -f '<nixpkgs/nixos>' -I nixos-config=/etc/nixos/configuration.nix -iA system

And I got this error when running sudo /nix/var/nix/profiles/system/bin/switch-to-configuration boot:

/nix/store/mhhjj1d9ml4i3gb9j6gy83yy33ngcsgv-grub-2.04-rc1/sbin/grub-install: error: /boot doesn't look like an EFI partition.
/nix/store/qm3dlsxn0847m5l7ivmcm5dxckgicz93-install-grub.pl: installation of GRUB EFI into /boot failed

In my working, Syslinux /boot directory, I have the following files:

initramfs-linux-fallback.img
initramfs-linux.img
intel-ucode.img
syslinux/
vmlinuz-linux

EDIT2:

I’ve also tried setting boot.loader.grub.device = "nodev" and set boot.loader.grub.efiSupport to true and false and both options didn’t work and I always got the ldlinux.c32 error messsage.

You’re booting mbr bios. That ldlinux.c32 module should I believe live in the syslinux directory, and if absent, may be resulting in the syslinux error.

Are you booting Arch from a USB? And is that single sda1 partition the internal drive?

Yes, ldlinux.c32 is found in /boot/syslinux/. I boot Arch from a normal SSD hard drive. /dev/sda1 is it’s single partition.

So you’re installing nix on a separate internal drive?

No, I’m trying to install nixos on the same hard drive - /dev/sda.

So is the goal dualboot, or to replace the Arch install with nixos? You will have to create another partition for dualboot of course. If it’s a matter of replacing arch and syslinux, it may be problematic trying to make those changes on the active boot disk. You can boot from a live Arch usb or a nix USB.

For what it’s worth, if you’re going to kill the Arch install, if the computer is post-2011 and supports UEFI, reformatting the drive as gpt and using an efi setup brings advantages in configuring the bootloader and in dualbooting. But that’s not lightly done if you want to spare your Arch install.

Oh I see now. Thanks for your quick replies! I suppose the best option would be now to get a nix installation ISO and burn it on a USB right?

I’m not sure I’d like to completely kill my Arch Install… I have backups for all configurations in /etc but I guess that would mean formatting the SSD hard drive right? I have lots of files there which I don’t have backups for and doing so will require some effort.

What do you mean by “advantages in configuring the bootloader and in dualbooting”? If I never plan to have more then 1 OS on it will this benefit me? I would like however to have the option to roll back my system to a previous kernel in case a kernel update was broken. Is this considered dual boot?

Thanks again for your help.

Yes

You can have more primary partitions, efibootmanager is a very effective tool, boot blocks written to mbr are harder to manage, efi partitions are easier, no flags to set. I say overall just more fine grained control and less brittle.

No, dualboot is having both nixos and arch in parallel on the same drive, but able to boot independently. These roll backs are nixos tapping into grub’s ability to have numerous kernels available. You see it other distros like centos, but nixos has taken the principle way beyond to fully restore previous iterations. It’s very cool.

Thanks a lot for your good explanations.

I guess this won’t matter much to me because I’m not interested in playing too much with this kind of stuff, I just want a machine that boots. Maybe one day…

As for finishing my installation using the NixOS ISO USB, could you please confirm for me what will I need to do, once I’ve boot with the USB? To my understanding, I’ll need to do the following:

  1. Mount my SSD hard drive in /mnt.
  2. Set the following in /mnt/etc/nixos/configuration.nix:
  boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;
  boot.loader.grub.device = "/dev/sda"; # or "nodev" for efi only
  1. Not sure about this one:
nixos-install --root /mnt

Assuming you keep your system booting bios/mbr those grub settings are enough. That nixos-install command is what will actually install nixos to your drive. The manual has a good step-by-step once you boot from a nix USB. Remember to save Arch files beforehand.

Pardon me for taking so long to reply. Unfortunately, I’ve had to format my SSD and use a partition layout as suggested in the manual. The good news are that I’ve a working NixOS installation and everything works out smoothly but the sad news are that I’ve had done a “small” mistake in the process and a lot of my data was deleted. Almost nothing wasn’t backed up but It has taken me quiet some time to get xserver working the way I want so I could access Firefox and respond here.

Anyway, I’ll conclude this thread in that “The operation wasn’t successful, but the patient lived!”. I’ll note though that I tried exactly what you suggested in your last comment even before you’ve wrote it because I assumed it’d work but it didn’t.

Thanks again for your willing to help. Cheers.