Skip to main content

Module nix_transform

Module nix_transform 

Source
Expand description

Nix-powered IR transforms (external evaluator: nix-instantiate or sui). Nix-powered IR transforms.

Shells out to an external Nix evaluator (nix-instantiate by default; aliased to sui in sui-enabled environments) to apply a user-supplied Nix expression over an IacResource. The expression is a single-argument lambda:

# transform.nix
resource: resource // {
  description = "v2 — updated by Nix transform";
  attributes = map (a:
    if a.name == "password" then a // { sensitive = true; } else a
  ) resource.attributes;
}

Call flow:

  1. Rust emits the IR as a Nix attribute set via NixBackend’s resource_to_nix converter (internal helper used by this module too)
  2. Nix evaluates (<expression>) <emitted-attrset> and prints JSON via builtins.toJSON
  3. Rust reads the JSON output and reconstructs an IacResource

This is the pragmatic realization of “Nix as the extension language for IR transforms.” Sui integration at the Rust library level (linking sui-eval directly, no process boundary) is a natural follow-up; the API surface here stays the same.

Enums§

NixEvaluator
Which evaluator binary to call. nix-instantiate is the default; users can override via NixEvaluator::Custom("sui".into()) or via the NIX_EVALUATOR environment variable.
NixTransformError
Errors from running a Nix-powered transform.

Functions§

apply_nix_transform
Apply a Nix lambda expression to an IacResource.
evaluator_available
Check whether the configured evaluator is available on PATH.