[Solved] How to install NixOS text-only in libvirt?

I want to try out nixos, but I don’t want the frustration of messing with hardware to do it. I tried creating a VM, but nixos won’t cooperate with libvirt. I ran the following:

virt-install --name=nixos \
--memory=8196 --vcpus=2 \
--cdrom=/public/Software/Linux/OS/latest-nixos-minimal-x86_64-linux.iso \
--disk /home/virtual/kvm/nixos/nixos.qcow2,device=disk,bus=virtio,size=8 \
--os-type=generic  \
--nographics \
--console pty,target_type=serial

This boots the disk, but then it freezes:

Loading /boot/bzImage... ok
Loading /boot/initrd...ok

Is there something else I need to do to get this working?

1 Like

It’s booting as normal but without connecting to the serial console. That’s the 5th option in the bootloader, I dont know if there’s an easy way to select it without connecting to the display unfortunately.

Potential solutions to the best of my knowledge

  • look inside the iso and do a direct kernel boot with the correct command line.
  • use the OVA from nixos.org, there are ways to import OVAs into libvirt.
  • try cloud-init. There is support for that in NixOS but I dont think we have pre-built cloud-init images…

If other distros default to enabling the serial console in installers I think NixOS should too.

1 Like

I figured it out. It seems that the serial port doesn’t get initialized properly, but the standard console works fine. So just set the console target_type to virtio:

virt-install --name=nixos \
--memory=8196 \
--vcpus=2 \
--disk /path/to/my-nixos-disk-image.qcow2,device=disk,bus=virtio,size=16 \
--cdrom=/path/to/latest-nixos-minimal-x86_64-linux.iso \
--os-type=generic  \
--boot=uefi \
--nographics \
--console pty,target_type=virtio

I wrote up quick blog post about it: https://technicalsourcery.net/posts/nixos-in-libvirt/


I don’t get this to work. It seems to get stuck on the following

(although I have needed to adjust the commandline to remove the --nographics call to see this)

1 Like

Ok, seemed I needed to adjust the command line. Add an option --import and remove the --boot=uefi

1 Like