early but real · Apache-2.0
Terraform resources as Nix values.
Describe real infrastructure as Nix instead of HCL. A thin Go executor drives unmodified Terraform and OpenTofu provider binaries, and what the cloud returns flows back into Nix.
$ nix run github:nivis-project/nivis#nivis -- --version
You already know half of it.
Coming from Nix
The missing half is the provider ecosystem.
- A provider is a plugin binary that speaks to one cloud API. Nivis runs any OpenTofu-compatible provider as-is.
- plan previews what would change, apply makes it so, and state remembers what exists.
- A resource is an attrset built with
mkResource. Compose it with the functions and modules you already write.
Coming from Terraform
The missing half is the language.
- Same providers, same plan / apply / destroy. A
flake.nixtakes the place of your.tffiles. aws_s3_bucket.demo.idbecomesbucket.refAttr "id", an ordinary value you can pass to any function.- Nix also builds machines. A NixOS image and the cloud resources that boot it can live in one expression.
provider "aws" {
region = "eu-central-1"
}
resource "aws_s3_bucket" "demo" {
force_destroy = true
}providers.aws = lib.mkProvider {
source = "registry.opentofu.org/hashicorp/aws";
config.region = "eu-central-1";
};
resources = [
(lib.mkResource {
provider = "aws"; type = "aws_s3_bucket"; name = "demo";
config.force_destroy = true;
})
];Quick start
All you need is Nix with flakes enabled. The first two steps touch no cloud account.
Run it without cloning
$ nix run github:nivis-project/nivis#nivis -- --version
Take the guided tour
nivistutor scaffolds a sandboxed tutorial project, so you can watch a plan and an apply before any credentials are involved.
$ nix shell github:nivis-project/nivis#nivis github:nivis-project/nivis#tutor
$ nivistutor
Write a flake
One provider, one resource. This is a complete flake.nix.
{
inputs.nivis.url = "github:nivis-project/nivis";
outputs = { self, nivis }:
let lib = nivis.lib; in {
nivis.plan = ledger: lib.toIR {
providers.aws = lib.mkProvider {
source = "registry.opentofu.org/hashicorp/aws";
config.region = "eu-central-1";
};
resources = [
(lib.mkResource {
provider = "aws"; type = "aws_s3_bucket"; name = "demo";
config.force_destroy = true;
})
];
inherit ledger;
};
};
}Plan, apply, inspect, destroy
From here on you are creating real resources in your own AWS account.
$ nivis plan # preview changes
$ nivis apply # apply to fixpoint
$ nivis state show aws.aws_s3_bucket.demo
$ nivis destroy
The round trip
A provider creates a resource and returns values nobody could know beforehand: an IP, an ID, a generated name. Nivis hands those back to Nix and evaluates again, until nothing is left unknown.
- 01 evaluateNix evaluates your flake to a JSON plan. Values that only exist after apply become typed placeholders.
- 02 applyThe executor applies everything that is fully known, speaking the plugin protocol to the provider binaries.
- 03 ledgerWhatever the providers computed is collected in the ledger.
- 04 re-evaluateNix runs again with the ledger as input. Placeholders resolve, the next phase unlocks, and the loop repeats to a fixpoint.
note = lib.mkResource {
provider = "aws";
type = "aws_s3_object";
name = "note";
config = {
bucket = bucket.refAttr "id";
key = "hello-from-nix.txt";
content = lib.str [
"This file's content was generated by Nix.\n"
"It is stored in the bucket named: "
(bucket.refAttr "id")
"\n"
];
content_type = "text/plain";
};
};A file whose content depends on a name AWS has yet to invent
The bucket id does not exist until phase one has run. In phase two Nix builds the string around it, and the result becomes the body of a real S3 object.
Where Nivis sits
Terranix generates HCL from Nix and hands it to Terraform. Pulumi compiles providers through a bridge. Nivis keeps resources as Nix values and spawns the providers untouched.
| Nivis | OpenTofu / Terraform | Terranix | NixOps 4 | Pulumi | |
|---|---|---|---|---|---|
| Config language | Nix | HCL | Nix → HCL | Nix | TS, Python, Go, … |
| Reuses Terraform / OpenTofu providers | Yes, spawned unmodified | Yes, native | Yes, via Terraform | In progress | Yes, via bridge |
| Outputs feed back into config | Yes, phased re-evaluation | Partly: HCL references only | No | Yes | Yes, Output<T> |
| Plan before apply | Yes | Yes | Yes, via Terraform | Partly | Yes |
| OS build and cloud in one expression | Yes, NixOS image → AMI | No | No | Yes | No |
| License | Apache-2.0 | MPL-2.0 / BUSL-1.1 | MIT | LGPL-2.1 | Apache-2.0 core |
The Nivis projects
Every mark is the same curve, h(θ) = a + b · cos kθ, with different parameters.
Go deeper
Nivis is early. The round trip works across providers, and AWS applies, updates, replaces and destroys today. Issues and experiments are welcome.
Try it in five minutes