Scripts2026年7月24日·1 分钟阅读

Nickel — Configuration Language with Contracts and Types

A configuration language written in Rust that uses contracts and gradual typing to produce correct, maintainable configuration files.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Nickel Config Language
直接安装命令
npx -y tokrepo@latest install cc1553ef-86f9-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

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 export and nickel 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.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产