How to manage raspberry cluster with nix? (strategies)

Hello everyone, I was wondering if someone could help me figure out a way to properly handle a cluster of raspberry pi’s.

I’m currently doing the following:

  1. Creating an .img with unique hostname, my mac’s public ssh key, avahi.enable = true and the wifi configured for each raspberry pi (I have 4).
  2. Flashing each distinctive .img into each rpi.
  3. TODO: Use deploy-rs to update all of them probably using ssh username@hostname

Is there an alternative to this? How could I create one .img, flash it into all of my raspberries, and then configure each one?

I have already considered some options, but I’m not a big fan:

Option 1:
I’ve checked this tutorial: A guide to build a Raspberry Pi cluster managed by NixOps

but it involves manually configuring the raspberry.

I could create my own iso with just wifi settings, with a default hostname, but it would mean I would have to find the assigned IP during DHCP for each rpi, because the hostname would be duplicated. Right?

Option 2
I could manually set the IPs, but I’m not sure it would work well when moving to a different network (let’s say I move in a couple of months). Would it work well when other devices are using DHCP?

Thanks!

I think this is the use-case for bento; although I’ve yet to try it.

Currently I manage my systems similarly: each has a separate entry in a single flake. They share common config through modules. The ones which boot from sdCard each have another entry to make the OS image – this part still needs a lot of tuning. This is enough for me to bring up most new machines headless – unless I need to tweak BIOS settings.

Each system has a unique hostname. My network DHCP server is configured to add hostnames to its DNS. All lan hosts are addressable as hostname.lan. If a device does not let me set its hostname (my thermostat), I configure the router to assign a name based on MAC address. (I find this easier than trying to manage avahi on all hosts; although I hope to get that working someday.) This generally solves the host discoverability problem.

You even could add some scripts to have the hostname assigned dynamically on first boot. (I expect avahi has this capability.) Then you look at your router console to see what name was assigned, or have them report the name to some other well-known host. This would let you use a single image for multiple machines.

I’ve been managing my home network this way since long before nix existed. Over the years I’ve found considerable value in understanding how to interpret what the router sees – especially as I prefer to run most machines headless.

1 Like