Blog - GitHub

NixOS on Oracle Cloud’s Free Tier Machines

2023-08-20

Recently I found myself needing a new VPS with a lot of memory but without a massively high pricetag to host a Minecraft server for me and some friends. After doing some looking around, I found out about how generous the Oracle Cloud Free Tier was, especially on the Ampere VMs giving everyone a whopping 24GB RAM and 4 CPU cores. Not only that, but you then get a further two VM’s of their VM.Standard.E2.1.Micro shape, which provide you with an x86_64 VM with 1 CPU core and 1GB of RAM, one of which is currently being used to host this very blog!

However, as I went to install NixOS on the smaller Micro instances, something hit me, and it hit me hard. The install method that I used for the Ampere VM wouldn’t work on the Micro VMs due to how much RAM (wasn’t) available. As such, I had to come up with some new ideas in order to get NixOS on one.

Ideas

  1. Make a VM with 2GB RAM and reshape it after the install? While this sounds like the easiest solution, and even the one that’s recommended in the NixOS Wiki for installing NixOS on a server, there was one problem. Even on the first month of the Free Trial (which gave me £250.00 credit to use) still didn’t allow me to reshape the VM down to 1GB RAM after creating it, so clearly this wasn’t a good option.
  2. Clone an image of the Ampere VM and use that as the base image when creating the new VM? This idea seems like it’d work, with one major concern. Architecture. The Amphere VM is running on an Arm64 CPU, meaning that (of course) x86 applications won’t be present, and its not exactly going to be the easiest job to swap the Architectures.
  3. Create a new image using a larger x86_64 VM and then using that image on the 1GB RAM instances? While it’s a bit more involved, it should be easy enough to do, and would make it easier for me to install NixOS in VM’s in the future if I decide to upgrade from a free tier account to a paid account.

Upgrading my Oracle Cloud account to a paid tier is looking quite likely in the future given how competitive the pricing is compared to Linode. Even if I don’t end up using extra VMs beyond the three I’ll be using on the free tier (assuming that I keep the Ampere VM as a single instance and don’t split it up), the block volume storage is a little-over 1/4th the pricing of Linode, meaning I can get ~4x the storage on Oracle Cloud compared to Linode, while not having to pay for the VM on top of that.

Looks like I’ll be going with idea 3. With my current free tier account I get 200GB of storage, and with each VM taking a minimum of 47GB of storage for their boot volumes (as of the time of writing this, totalling up to 94GB), I have plenty of storage space remaining to create a boot volume image using a non-free-tier VM with my £250 credit and use that image to create my cheaper VMs with NixOS pre-installed onto them.

Creating the VM

To make the VM we’ll be using to run NixOS on, we’ll get started with an Ubuntu VM with some decent hardware. If, like me, you’re doing this in your first month of the Oracle Cloud Free Tier, you’ll hopefully still have the £250 free credit, so we’re going to take full advantage of that in order to make sure that the install goes by as quickly as it can. Thankfully, we only plan on running this VM for a couple of hours to create a NixOS image, otherwise after our free trial ended, this VM would cost us an eye-watering £134.71/month to keep running. Or at least it would, if you didn’t have to opt-in to paying for Oracle Cloud services.

Ultimately, my VM ended up being a VM.Standard.E3.Flex with 8 CPU cores and 16GB of RAM, running Ubuntu 22.04, fittingly called “image-maker”.

Creative name, I know.

Aside from this, just remember to either upload your public SSH key, or download the SSH keys that Oracle will generate for you. It’s entirely up to you if you want to re-use these after NixOS is installed, personally I don’t bother and just end up using just one SSH key per device, but that’s moreso out of laziness than a recommendation of good security…

Getting the VM ready

Now that the VM’s been created, the first step is to install our main pre-requisite, I’m sure you could guess what it was, nix! The steps for this are the exact same as installing Nix on any other Linux OS, meaning all you have to do is run this command

sh <(curl -L https://nixos.org/nix/install) --daemon

Once you’ve run the install command and you get the prompt to restart your shell, all you have to do is exit your SSH connection and re-connect to the VM. Now you’ll have Nix installed and ready to go!