Building a NixOS Homelab
nixos homelab devops linux
Building a NixOS Homelab
After one too many "what did I install on this box?" moments, I rebuilt my entire homelab on NixOS. Everything is declarative now — the whole machine is one git repo.
The flake
{
description = "homelab";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }: {
nixosConfigurations.box = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [ ./configuration.nix ];
};
};
}
Why it's worth it
- Reproducible —
nixos-rebuild switchgets me an identical machine every time. - Rollbacks — bad config? boot the previous generation.
- Documented by default — the config is the documentation.
# rebuild and switch
sudo nixos-rebuild switch --flake .#box
# roll back if it broke
sudo nixos-rebuild switch --rollback
NixOS is a rabbit hole. A very good rabbit hole.
It took a weekend to learn, but I haven't lost track of a single service since.