I’ve been playing around with Nix and NixOS for the past week and honestly, I don’t really like NixOS. But, now I dislike other OSes even more since I finally understand what they’re all missing compared to NixOS!

Anyways, as you might know, this site is hosted on SIPB’s XVM service and uses Arch Linux. Since NixOS totally ruined Arch and every other Linux distro for me, I decided to switch the server for this site to using NixOS instead.

Fortunately, it’s not too hard to install NixOS in a low-RAM environment like XVM (assuming you already have some NixOS experience). I found a helpful guide which funnily enough also uses the same “dd the raw disk image” trick that I came up with, and it’s honestly nicer using NixOS and Disko instead of that hacky crazy insane thing with resizing root partitions that I did last time. Disko can declaratively build the disk image, although if you don’t care about the filesystem (I specifically NEED Btrfs), you can use nixos-generators instead. Oh and by the way the Disko logo has the same meme energy as XVM’s:

Disko logo

XVM logo

Anyways, here are the steps that I did:

  1. Write a flake and a Disko config. Don’t forget to include boot.initrd.availableKernelModules = ["xen-blkfront" "xen-netfront"]; for Xen reasons.
  2. Build the disk image.
  3. Boot up an Arch ISO (or any other ISO) as an HVM on XVM.
  4. Assuming you’re on MITnet, open up port 8000 on your firewall and run python -m http.server in the directory with the disk image, then get your IP address using ip a.
  5. In the HVM, run curl -s IPADDR:8000/main.raw | dd of=/dev/xvda bs=1M status=progress.
  6. Run parted /dev/xvda and resizepart 3 100% to expand the root partition to fill up the entire disk.
  7. For Btrfs, run mount /dev/xvda3 /mnt and btrfs filesystem resize max /mnt to expand the Btrfs filesystem to fill the entire partition.

And that’s it! Easy as that. Now you have a lovely NixOS VM!

What’s next?

To reconfigure or update your VM, use nixos-rebuild switch --target-host on a different machine since XVM doesn’t have enough RAM for evaluating Nix expressions or building derivations on the VM itself.

I recommend setting zramSwap.enable = true since XVM has very limited RAM and daemonIOSchedClass = "idle" so that Nix daemon operations don’t overload or freeze your VM with too many I/O operations.