Small tip that took me embarrassingly long to figure out, sharing in case it helps others who mix LLM tooling into their NixOS setup.
I use a couple of little helper scripts that call LLM APIs (commit message generation, log triage). My first approach was hardcoding the API base URL and key into my scripts, then keeping the scripts out of git. That was ugly: my Nix expression for the machine and my actual scripts drifted apart, and swapping providers meant editing several files.
What I settled on:
1. The scripts read two environment variables (API_BASE, API_KEY) and nothing else.
2. Those variables are set through my Nix configuration, so the whole machine stays declarative while the secrets live in one place outside the repo.
3. For the endpoint itself I use an aggregated gateway (y-api.bestvirtualgoods.com) with an OpenAI-compatible interface. The nice property for a Nix setup: the “model” becomes just another config option. I can switch to a cheaper or faster model by changing one line in configuration.nix instead of editing every script.
Since everything is OpenAI-compatible, none of the tooling cares what the upstream actually is. Rolling back a bad model choice is now literally `nixos-rebuild switch` to the previous generation.
Not affiliated with the gateway, just describing my setup. Curious how others handle API keys in their Nix configs - sops-nix feels like overkill for one key, but maybe I’m wrong.