Show HN: Making a Minecraft Server with NixOS on EC2

github.com

3 points by josecodea 16 hours ago

Why? Mostly because I wanted to do something fun, cost effective, and learn a bit about NixOS along the way.

So first of all, the friend group... We like to play boardgames together, and we wanted to take the gaming online, because we cannot meet that often. We agreed on MineCraft as the most accessible for everyone because it requires a single-time purchase and a computer. Hooray, getting them to agree on something is difficult.

Now, no one wanted to pay for the MineCraft monthly fee to get one of the Microsoft MineCraft servers. Somewhat reasonably, as we might spend 8 hours playing one day and then go 3 months without launching the game. So I told them: don't worry, I got it.

That's as far as the friend group is involved, the rest is implementation details.

Now, I needed my solution, and I wanted to use NixOS. Why? Because it is a declarative way of configuring an entire Linux machine, and I like that because I am silly-brained and forget everything that I type into the terminal. Therefore having all the config persisted as code is great, and if I accidentally nuke the machine, it's just a few commands to have an equivalent machine up and running. Am I over-engineering? Most certainly. But hey! This also means that the code may serve as a template so that other people deploy the thing themselves. So, to me, this is the vibes of "Infra-as-Code" combined with the vibes of configuring a Linux machine.

Cool, what's next? The hosting provider, right. So I chose AWS EC2 for no particular reason other than I am familiar with it, and also that AWS has an API to start and stop the EC2 instances. Efficiency! (Apparently other hosting services like Hetzner and Linode do not offer a similar API to reduce costs, but feel free to correct me here). This way, the EC2 server is running only as long as people are actually playing, so my bill can be like 2 dollars for an active month as we don't play that much. By this point you sort of get the idea, if you want all the gritty implementation details you may check the full blog post here:

https://bloggeroo.dev/articles/202402292320

In the end, I added my friends to a Discord server, they run a command like `/turn on server`, a Discord bot answers: `The server is available at IP address 123`, and we go explore some caves for 4 hours just to lose all our gear at the end. Hooray!

One spicy detail is that I did this from my MacOS, which was a bit of a challenge because a local NixOS is required to deploy the NixOS on EC2 (I used Docker). So, if you read the whole thing: thanks and have fun!

If you find this particularly useful, I am keen to know why in order to inform myself for future topics. Thnx:)