Low-end infrastructure as code
On my homelab servers I run NixOS. I like it very much but I think it's fair to say that it is not the best choice for low-end boxes (I'm thinking something with 128MB RAM/1GB disk or similar).
I'd still like to manage these boxes in an infrastructure as code fashion. What would you recommend me to use?
Comments
teraform
14 cents per month netbsd at this aff TierHive
Interesting. I've used terraform to provision cloud resources but not to do things like installing packages or updating configuration.
Now I'm curious to know that what you're doing
NixOS FTW!
Yeah it is not for anything smaller than 1GB RAM and maybe 5GB disk, even when you pull in the minimal config and use syslinux instead of grub.
Hardly any VPS provider offers very low end boxes anymore (well except TierHive, but the cost is low enough, spinning up a 1GB/5GB VPS with them is not that expensive either)
DM us for private tracker invite.
For such low-end vps instances, I'd probably use ansible or simple shell scripts for configuration management. Terraform is great for provisioning infrastructure, but I wouldn't use it to manage packages inside the OS.
What do you think?
I haven't spent much time giving it a try yet but I'm inclined to write a simple provisioning script and leave it at that.
My reasoning is that with 128MB RAM/1GB disk the VPS isn't going to do a lot anyway. The amount of resources limits how many packages can be realistically installed and how many services can run.
I still like to have a provisioning script so I can easily get another VPS configured the same way or destroy and re-create the VPS as needed.
Nixos is by default as config/code no?
@marios Since you're leaning towards a provisioning script, one useful check is to run it twice on a disposable machine: the second run shouldn't duplicate config entries or recreate things unnecessarily. Keeping the script and intended config files together in Git would also make rebuilding easier.
A detail worth adding to the Ansible suggestion above:
ansible.builtin.rawandansible.builtin.scriptdon't require Python on the managed host. Ansible can run elsewhere, withgather_facts: falsefor a Python-free target. That gives you inventory/SSH orchestration without installing the normal Python module runtime on the tiny VPS.The trade-off is that
rawisn't automatically idempotent and doesn't support check mode; the script still needs to handle repeat runs correctly. Official docs: https://docs.ansible.com/projects/ansible/latest/collections/ansible/builtin/raw_module.htmlI just look at shell history to recreate a new box. Thats the old fashioned way to have a 'managed' box. Using mobaxterm or tmux for doing things on multiple nodes. Who needs puppet or ansible?
14 cents per month netbsd at this aff TierHive
Would be awesome if TierHive supported mounting a shared storage volume read-only across multiple machines, with a private writable overlay for each machine. You could then spin up a maintenance VM to update a shared /nix/store for the whole fleet, rather than storing the same packages separately on every machine.
That's a nice idea.
If I really wanted NixOS on a very low-end machine I would also consider treating it more like an appliance, either by doing a standard install with rebuilds done on a more beefy machine (with
nixos-rebuild switch --target-host ...) or with an approach similar to what's described in this post series https://nixcademy.com/posts/auto-growing-nixos-appliance-images-with-systemd-repart/You can set up your own VM on tierhive and serve that shared storage. Because it is tierhive, it won't cost you much!
DM us for private tracker invite.
Interesting
For something as small as 128MB RAM, I'd probably just stick with shell scripts and SSH.
I have a few low-spec VPSes myself, and I've found it easier to handle most of the setup and maintenance from another machine rather than installing extra stuff on each server.
Terraform makes sense if the provider has a decent API, but for configuring tiny boxes, simple scripts are usually enough.
Less stuff running in the background, less to worry about.
I tend to just use shell scripts although I guess, if you have a lot of boxes, you could use Ansible to try and automate it a bit more.
https://lowendspirit.com/nixos on 512mb ram
DM us for private tracker invite.
This is helpful for a beginner like me, because so far I have set up my first VPS by hand and I would struggle to repeat exactly the same steps if I had to start again. The suggestion from Parsifal to stick with shell scripts and SSH for very small boxes made the most sense to me, and FinCoder's tip about running a script twice on a disposable box is a check I would not have thought of. For just one VPS, would saving my setup steps as one simple shell script be a reasonable first step toward infrastructure as code, or is it worth learning Ansible from the start even for a single server?
I would probably start with a shell script and work from there. Remember that you can always use history to see your previous commands.
I am still in the "shell scripts and a notes file" stage for my small VPS boxes. Ansible looks like the practical next step for me, while NixOS feels powerful but a bit heavy for tiny servers. Curious how people here decide when a 128MB or 512MB box is worth codifying at all, instead of just setting it up once by hand.
To me size of the machine doesn't really matter when I decide if I want to use infrastructure as code. It's more a decision between "this is an experimental box I am not going to care to reproduce" vs "I want to be able to spin up a new box that looks exactly like this" or even "I want to be able to tear down this box and create a new one".
Unless I know I am doing a quick experiment I tend to err on the side of caution and have a way to reproduce things. On top of that, how I achieve that has some degrees ranging from "let's document what I am doing" to "let's script the setup" to "let's use Terraform to provision the infrastructure and NixOS to configure the machine"
Terraform, or ansible if you want something simpler
For boxes that small I'd keep it boring: Ansible over SSH, nothing resident on the machine. Terraform is great for spinning the VPS up at a provider, but it doesn't really manage what's inside it day to day. NixOS is lovely on a homelab box with real RAM, on 128MB it's just fighting the machine.
Break it, learn it, fix it.
One option nobody's mentioned: pyinfra. It's agentless like Ansible, but it runs plain shell commands over SSH, so the 128MB target doesn't need Python at all, and it's still idempotent, unlike
raw. Combine it with cloud-init (or your provider's first-boot script) for the bootstrap and you get "rebuild from scratch" without anything resident on the box.pyinframight be a good option. I had heard of it before but I kind of forgot about it. Thanks for reminding me it existsI'm in the shell scripts + git camp so far, for the same reason a few people here said: my boxes are tiny free-tier ones, so I don't want anything resident running on them. All my services are defined in private repos with Dockerfiles, and every time a deploy fails I just rebuild from scratch — that's how I keep finding the real bugs, like a wrong binary path in the Dockerfile or a missing env var. I haven't tried Ansible yet, but the tip about running a script twice on a disposable box stuck with me; my rebuilds are basically that test, just unplanned. Terraform feels like overkill until I have more than a couple of boxes to spin up the same way.