Introduction
Nickel is a configuration language for generating JSON, YAML, and TOML with the safety of types and the flexibility of a dynamic language. Written in Rust, it provides gradual typing and contracts that validate values at evaluation time, catching errors before deployment.
What Nickel Does
- Generates JSON, YAML, and TOML output from a single source language
- Validates configuration values using contracts (runtime type checks)
- Supports gradual typing so users can add type annotations incrementally
- Provides functions, records, and merging for modular configuration
- Catches constraint violations and type errors before configuration is deployed
Architecture Overview
Nickel programs are evaluated by an interpreter written in Rust. The pipeline parses source into an AST, performs optional static type checking, then reduces to normal form. Contracts are checked lazily when values cross boundaries. Record merging combines fragments with priority semantics. The result is serialized via nickel export.
Self-Hosting & Configuration
- Single binary (nickel) with no external dependencies beyond a Rust toolchain or Nix
- Files use the .ncl extension and can import other .ncl files by path
- The LSP server (nickel-lang-lsp) provides editor integration for VS Code and Neovim
- Libraries shared as packages imported via file paths or URLs
- CI integration via
nickel exportandnickel typecheck
Key Features
- Contracts enforce constraints on values (e.g., port numbers, non-empty strings) at evaluation time
- Gradual typing allows mixing typed and untyped code in the same program
- Record merging with priorities enables layered configuration (defaults, overrides, environment-specific)
- First-class functions and polymorphism for reusable configuration abstractions
- Deterministic evaluation produces reproducible output from the same inputs
Comparison with Similar Tools
- CUE — Uses lattice-based types and unification; Nickel uses contracts with gradual typing
- Jsonnet — Focused on JSON templating; Nickel adds a type system and contract validation
- Dhall — Total functional language with strong guarantees; Nickel is more flexible with gradual typing
- HCL — Domain-specific to Terraform; Nickel is general-purpose for any configuration target
FAQ
Q: What is the difference between types and contracts? A: Types are checked statically on annotated code. Contracts are checked at runtime when values cross boundaries, validating dynamic or untyped code.
Q: Can Nickel replace my YAML files?
A: Yes. Write configuration in Nickel and use nickel export to produce YAML, JSON, or TOML for consumption by other tools.
Q: Is Nickel Turing-complete? A: Yes, unlike Dhall which is intentionally total. Nickel allows general recursion, though configuration programs are typically terminating.
Q: How mature is Nickel? A: Nickel reached 1.0 stability and is actively developed. The contract and type system are stable, and the language is used in production with NixOS integration.