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.nix takes the place of your .tf files.
  • aws_s3_bucket.demo.id becomes bucket.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.
main.tf
provider "aws" {
  region = "eu-central-1"
}

resource "aws_s3_bucket" "demo" {
  force_destroy = true
}
flake.nix (excerpt)
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

Read the full getting-started guide

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.

  1. 01 evaluate
    Nix evaluates your flake to a JSON plan. Values that only exist after apply become typed placeholders.
  2. 02 apply
    The executor applies everything that is fully known, speaking the plugin protocol to the provider binaries.
  3. 03 ledger
    Whatever the providers computed is collected in the ledger.
  4. 04 re-evaluate
    Nix 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.

Follow the AWS S3 tutorial

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.

NivisOpenTofu / TerraformTerranixNixOps 4Pulumi
Config languageNixHCLNix → HCLNixTS, Python, Go, …
Reuses Terraform / OpenTofu providersYes, spawned unmodifiedYes, nativeYes, via TerraformIn progressYes, via bridge
Outputs feed back into configYes, phased re-evaluationPartly: HCL references onlyNoYesYes, Output<T>
Plan before applyYesYesYes, via TerraformPartlyYes
OS build and cloud in one expressionYes, NixOS image → AMINoNoYesNo
LicenseApache-2.0MPL-2.0 / BUSL-1.1MITLGPL-2.1Apache-2.0 core

Read the full comparison, including CDK and CloudFormation

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