My day job is writing SwiftUI. What I love about it is the mental model: you describe what the screen should look like for a given state, and the framework figures out how to get from here to there. You don’t manually move views around and hope you didn’t forget to clean something up.
I’m drawn to functional programming for the same reason. When there is no hidden state, and the same inputs reliably produce the same output, code feels calm and predictable.
Eventually I started wondering whether a whole home server could work that way. NixOS says yes: you describe the entire machine in code, and one command makes the server match the repository. That turns out to be a surprisingly big deal when you start letting AI coding agents help run it.
The setup, in brief
Before this rewrite, my homelab was a folder of docker-compose files backed by a lot of shell history that only lived in my head. The very first commit in this repo is Initial snapshot of docker compose config.
Now the entire home server is defined in one repository: encrypted disks across two drives, apps like Paperless, Immich, Plex, and Homebridge, private Tailscale access, encrypted secrets, nightly backups, and Telegram alerts when something breaks.
Instead of a sprawling system configured by hand over months, the whole server is around two dozen files:
flake.nix # entry point for the server
hosts/homeserver/ # hardware, disks, and host settings
modules/
base.nix # OS basics, SSH, automatic weekly updates
network.nix # Tailscale, reverse proxy, firewall
secrets.nix # encrypted secrets wiring
backup.nix # nightly backups
monitoring/ # Grafana dashboard and Telegram alerts
containers/ # the apps themselves
The problem with AI agents on a traditional server
Coding agents are great at fixing problems and wiring things up, until you point one at a traditional Linux server.
On Ubuntu, an agent gets things done by running commands: installing packages, editing config files scattered across /etc, changing permissions, and restarting services. To do anything useful, it needs sudo or root access.
Once it finishes, it’s hard to tell what actually changed. The state of the machine is spread across the filesystem, and the chat transcript is the only record of how it got there. Nobody carefully audits a 400-line terminal log once the app starts working again.
That leaves you with two bad options: approve every single shell command one by one, or trust the agent blindly and hope it didn’t leave behind a subtle mess.
With NixOS, the agent writes code, not commands
On NixOS, the agent never needs access to the live server at all. Its output is a git diff. That diff is the entire change, with nothing hidden outside it.
Because the server is just code, you get all the normal software habits back. I can read the diff myself, and I can even ask a second agent to review the first agent’s work. One of my favorite commits in the repo is Fix review findings in the NixOS config, where a review pass caught real edge cases before they ever hit the server, like a missing SSH host key for automated updates and a bug where one missing secret could block others from loading. Both the config and the fix were written with Claude: an agent reviewing an agent’s work, with every finding showing up as a diff instead of a surprise on the server.
Adding a new app shows why this works so well for AI. An app module just declares what port it wants and which secrets it needs:
homelab.services.soundtouch = { port = 8408; upstream = "127.0.0.1:8000"; };
homelab.secretEnvFiles.soundtouch = {
MGMT_USERNAME = "SOUNDTOUCH_MGMT_USER";
MGMT_PASSWORD = "SOUNDTOUCH_MGMT_PASS";
};
From those few lines, the rest of the config automatically sets up the HTTPS proxy, opens the firewall port over Tailscale, and injects the environment variables at startup. And because secrets are stored encrypted in git with sops-nix, the agent can wire up passwords and API keys without ever seeing the actual values.
The loop: edit → verify → PR → merge → deploy
With the server living in git, working with an AI agent becomes a normal pull-request workflow:
- The agent works on a branch. No SSH, no
sudo, no live server access. - Quick checks locally. Even though my Mac can’t natively build the Linux server image, it can still run syntax checks or offload a test build to the server.
- CI builds the entire OS. On every pull request, GitHub Actions builds the full NixOS system. If the agent hallucinated an option or broke a dependency, the build fails before anything is merged.
- I review and merge. I inspect a clean, bounded diff instead of a shell transcript.
- The server updates itself. Once a week, the server pulls
mainand switches to the latest merged commit (or I trigger an update right away).
Automated dependency updates fit the exact same loop. Renovate opens PRs for OS updates and container images, and CI builds each one. Even how much I trust automation is written down in config: container digest updates merge themselves once they’re three days old and the build is green, a new NixOS release waits for me to read the release notes, and database upgrades are switched off entirely. The server also reports its exact git commit to Grafana and Telegram, so I always know which version of the repo is running.
When it goes wrong: rollback
Even with CI and code review, mistakes still slip through. With NixOS, every update creates a new system generation instead of overwriting the old one in place. If something breaks, I switch back to the previous generation, either from the boot menu or on the server. You can also git revert the bad PR, and the next deploy brings the machine back.
Closing
Declarative infrastructure makes AI much safer to use, but it doesn’t solve everything:
- Apps are still containers. NixOS declares how containers are wired up, not what happens inside them.
- Some state can’t be declared. Database upgrades, HomeKit pairings, and app migrations still require manual care.
Coming back to SwiftUI: the magic of declarative code is separating what you want from how to get there. For a home server, that separation turns out to be the exact boundary that makes AI coding agents trustworthy. You let the agent write the description, let CI verify it, and let the system handle the rest.