terranixlisted
Install: claude install-skill atvari-eu/nix-skills
# Terranix
[terranix](https://terranix.org) generates [Terraform JSON](https://developer.hashicorp.com/terraform/language/syntax/json)
from Nix modules. You write `config.nix`; the `terranix` tool (or a flake build)
produces `config.tf.json`, which OpenTofu (`tofu`) applies exactly like HCL —
same providers, same state, same plan/apply workflow.
Prefer OpenTofu over Terraform when the user hasn't pinned a choice: it's in
nixpkgs as `pkgs.opentofu`, command `tofu`, reads the same `.tf.json` files, and
resolves providers from its own registry mirror.
Two rules that prevent most mistakes:
- **`config.tf.json` is a build artifact.** Never hand-edit it; regenerate it.
Gitignore it along with state (see below).
- **Nix and Terraform share the `${}` syntax** (see
[Interpolation escaping](#interpolation-escaping)) — this clash is the single
biggest source of broken terranix configs.
Don't convert an existing working HCL project to terranix unasked; offer it if
the user is clearly Nix-first, but leave plain `.tf` repos alone otherwise.
## Two ways to run terranix
| | nixpkgs CLI (`pkgs.terranix`) | flake (`github:terranix/terranix`) |
| --- | --- | --- |
| Invocation | `terranix -q > config.tf.json` | `nix build -o config.tf.json` |
| Reads | `./config.nix` (or path argument) | `modules = [ ./config.nix ]` |
| Module args | `lib` is empty as of 2.8.0 | nixpkgs `lib` extended with `lib.tf.ref` / `lib.tfRef` |
| Best for | quick one-offs | anything real: pinning, modules, C