11
votes
Tips to use NixOS on a server?
I see some people using NixOs on their servers. I would like to try it out to self host some services and learn about NixOs.
I use hetzner and they have an NixOs iso available so I can just use that to install NixOs. But how do people manage remote instances of NixOs? They would just use ansible or something like it, to run nix on the host, or is there a better way?
Thanks
I have a VPS that I run NixOS on, I'll share my configs in a few hours.
Edit: still plan on doing this, just got busy and didn't have the chance to.
Edit 2: See this topic.
If you're starting out with NixOS, just SSH in (or use the VNC console, if you lock yourself out of SSH), hand-edit your
configuration.nix
, runnixos-rebuild test
and so on.As you get more into NixOS, there's two things, you may wish to automate one or both of them - management of your
/etc/nixos/
directory, as well as automatically runningnixos-rebuild
. I do the former using a Git repo that I replicate using Syncthing, and do the latter entirely manually. All my NixOS boxes (desktops, laptops, a home server, and a cloud server) are "pets" and not "cattle", so I haven't had the desire to automatically upgrade them or apply configuration changes.If you run into any issues with Hetzner, I run my NixOS server on Vultr and have been happy with it. You can also easily run a VM locally using VirtualBox etc. That wouldn't get you closer to your goal of self-hosting services, but if you run into any issues during installation, it may be helpful to troubleshoot if they're Hetzner-specific or not.
If it helps get you started, here's a copy-paste of my installation notes for disk partitioning that creates an encrypted & compressed root-on-ZFS. You can certainly use a less fun filesystem like ext4 or xfs, too. Or, if you don't want the encryption, leave off the
encryption/keyformat/keylocation
options.These notes assume UEFI since all my bare-metal machines use it. I assume Hetzner, like Vultr, does MBR boot for their VMs instead of UEFI, in which case you'll want
mklabel msdos
instead and skipset 1 esp on
.And if you haven't found it already, bookmark The Big Options Page.
Think I will skip the zfs for now, but thanks for the tips that was exactly what I was looking for!
I haven't experimented with NixOS on the server yet, but there's a dedicated tool, NixOps, for deploying nix packages to (among other things) cloud servers.
You may find this useful: https://christine.website/blog/backslash-kubernetes-2021-01-03 - someone running NixOS on Hetzner.
Discussion on Lobsters: https://lobste.rs/s/p5mc01/kubernetes