Install NixOS from existing Linux

There is also another way which I used to install transfering from a VM. This also allows you to multi-boot alongside existing linux.

I’ll briefly talk here and if somebody wants more explanation I would explain.

DO NOT GO DOWN THIS WAY unless you have some basic understanding of partitioning and booatloaders.
There would be some minor hiccups but this is still pretty simple really. (I’m talking only about concepts, exact steps would need me to reinstall)

  1. Make a VM (It doesn’t matter if you use a fixed size HDD or not but HDD size should be similar to your NixOS partition size)

  2. Make three partitions, in your hardware computer. Note their exact byte sizes. CAREFUL- gparted on your existing linux and gparted on NixOS live cd may use different units by default. Now make the same partitions in the VM.
    a) /boot (yes, separate despite MBR, not a necessity but still). recommended size 300 MB
    b) /
    c) Swap (You’ll have an existing swap in your hardware, just make sure to label vm and hw swaps same). In hardware, swapoff, relabel, swapon.

  3. Remember to give the VM partitions a label. In hardware-configuration.nix refer to these labels. THIS IS IMPORTANT.

  4. Install. See that everything is how you’d like. If you don’t have a wired connection in your hardware computer then add a wifi program in your VM installation. I prefer iwd

  5. Reboot into the iso. dd from VM’s /boot to a file. Use scp to copy this to a hardware computer (as a file). Now dd to the hardware’s /boot.

  6. Reboot hardware. When you’re at grub, type in e. There, delete everything and type this:
    configfile (hd_,msdos_)/boot/grub/grub.cfg where you have to replace hd_ and msdos_ with appropriate numbers. Sidenote- arch’s grub allows completion with options at the bottom inside this editing interface, try hitting tab for options. You can also just jump directly to the grub command line and enter this configfile command there. There you also get tab completion.

If you are able to see NixOS grub then step 1 is done. Boot to your regular linux instead. Now copy the / partition from VM to hardware, similar to how you did for /boot. Now reboot hardware and use that configfile way.

Y0u’re inside NixOS. If you’d like you can do a nixos rebuild-switch --install-bootloader after changing boot.loader.grub.device.

I think this can be extended to BIOS + GPT and UEFI + GPT too but you’ll have to know your concepts there.

With BIOS + GPT, I believe the only difference is that in step 3, you’ll have to label your hardware partitions too. (with BIOS+MBR, labels are stored in the partition itself so dd takes care).

I’ve never used UEFI but on the arch wiki UEFI sounds even simpler than Legacy BIOS so maybe worth a try.

If anyone tries this, I’d love to hear your experience.

Thinking about it, you can actually install from Windows too, you’ll only need a live CD with grub. Or if you can boot to a VBR somehow then just install grub stage 1 in your /boot.