Recently, I decided to go down the journey of running things with NixOS. While I started with my laptop, I naturally decided to make my workspace problems part of my cloud adventure. So I figured I'd share my adventure along with my initial process for getting NixOS into the cloud. In this post, I've provided some of the commands I ran and a link to the repository I'm using to setup my OpenStack images on a Genestack cloud.
Why?
There were a couple of places on the internet that highlighted how to generate NixOS images using a generator via nixpkg. While OpenStack was an option, the generator didn't result in an image I could use as a general-purpose, standalone base image and didn't seem to incorporate many of the "features" I've come to expect in the cloud. So, to solve my cloudy wants with my new NixOS addiction, I set off to do a thing.
Image Requirements
After poking around, I decided I needed my NixOS-OpenStack to have the following attributes.
UEFI boot
Q35 machine type (compatible)
QEMU aware
Virtio support
Latest stable NixOS 23.11
Latest Kernel Image (6.8+)
Cloud-Init enabled
Standalone system
The Repository
To do what I needed, I put together a repository, which I've iterated on to craft the image I feel is well suited for the cloud and fits my immediate needs.
🚸
To make the above repo work, it assumes you have flakes and nix-command on your system.
Running the build within the Repository
To get started, clone the repository locally.
Create an OpenStack-compatible image for NixOS
Running the build with a remote repository
There's no need to clone the above repo to run the build; the following command can be used to run the build.
After the build, you will have a new qcow2 file in the results directory.
Upload the image and store the result in Glance
The image output will look similar to this.
The image we created with all the flags will enable the OpenStack features I need for the cloud: EFI boot, virtio, newer machine type, multi-queue networking, and image quiescing. This is made better by cloud-init, which will handle the systemd-networkd setup, hostnames, host keys, default users, SSH keys, etc. From my Nix noob point of view, the setup is allowing me to succeed in the cloud with NixOS.
💡
The metadata provided will ensure that OpenStack boots our image with the appropriate drivers and optimizations.
Boot your server
💡
Note the nic, flavor, and key-name will all be unique for your environment.
Creating the instance is simple and follows the standard OpenStack server create process.
The server creation will look similar to the following:
Creating and viewing the instance information in the OpenStack web UI is also possible.
After booting, all of the cloud-init bits will run, and we can log in via SSH with our defined keypair. The instance can also be accessed via the built-in serial console.
Server and system logs are also available for the instance.
Hope this helps someone
While I'm sure I've made some mistakes, and there are ways this could be much better, it works! The following configuration generates a simple, fully featured NixOS virtual machine image (which could probably be used with Baremetal via Ironic, too... soon-tm).
The best part of this setup is that it works inside and outside of OpenStack. The image is general purpose enough to be used on most any KVM hypervisor effectively, which is what I was going after, even if my system of choice happens to be OpenStack 😉