1. Backup your data.

  2. Reboot into rescue mode with the control panel.

  3. Connect to KVM with the control panel.

    You can also SSH into the host with login credentials from KVM.

  4. Download NixOS image.

    Likely you won’t have enough disk space in rescue mode so use ramfs.

    1
    2
    3
    4
    
    mkdir /mnt/ramdisk
    mount -t ramfs ramfs /mnt/ramdisk
    cd /mnt/ramdisk
    wget https://channels.nixos.org/nixos-21.11/latest-nixos-minimal-x86_64-linux.iso
    
  5. Load image with qemu.

    https://community.ovh.com/en/t/installing-operating-system-from-custom-image-on-ovh-vps-centos-8-tutorial/3561

    1
    2
    
    apt install qemu-kvm
    qemu-system-x86_64 -netdev type=user,id=mynet0 -device virtio-net-pci,netdev=mynet0 -m 2048 -enable-kvm -drive index=0,media=disk,if=virtio,file=/dev/sdb -cdrom latest-nixos-minimal-x86_64-linux.iso -boot d
    
  6. Connect to the installer inside QEMU guest.

    On your local machine, forward the VNC port locally.

    1
    
    ssh -o "UserKnownHostsFile=/dev/null" -NL 5900:localhost:5900 root@${YOUR_HOST}
    

    Then connect to vnc://localhost with your VNC client. “Screen Sharing.app” on macOS somehow didn’t work for me.

  7. Install as usual inside VNC.

    Follow instructions in https://nixos.org/manual/nixos/stable/index.html#sec-installation. Use vda whenever sda is referenced.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    
    sudo -i
    parted /dev/vda -- mklabel msdos
    parted /dev/vda -- mkpart primary 1MiB -8GiB
    parted /dev/vda -- mkpart primary linux-swap -8GiB 100%
    mkfs.ext4 -L nixos /dev/sda1
    mkswap -L swap /dev/sda2
    mount /dev/disk/by-label/nixos /mnt
    swapon /dev/vda2
    nixos-generate-config --root /mnt
    vi /mnt/etc/nixos/configuration.nix
    # uncomment boot.loader.grub.device and set it to "/dev/vda"
    nixos-install
    
  8. Shutdown the qemu guest.

    1
    
    shutdown -h now
    
  9. Reboot with the control panel into non-rescue mode.

  10. Now that we are no longer in rescue mode, change /dev/vda back to /dev/sda.

    1
    
    vi /etc/nixos/configuration.nix
    
  11. Done.