Nickel

Continuous integration Website

Nickel is the cheap configuration language.

Its purpose is to automate the generation of static configuration files - think JSON, YAML, XML, or your favorite data representation language - that are then fed to another system. It is designed to have a simple, well-understood core: it is in essence JSON with functions.

Nickel's salient traits are:

The motto guiding Nickel's design is:

Great defaults, design for extensibility

There should be a standard, clear path for common things. There should be no arbitrary restrictions that limit what you can do you the one day you need to go beyond.

Use cases

Nickel is a good fit in any situation where you need to generate a complex configuration, be it for a single app, a machine, whole infrastructure, or a build system.

The motivating use cases are in particular:

Most aforementioned projects have their own bespoke configuration language. See Comparison. In general, application-specific languages might suffer from feature creep, lack of abstractions or just feel ad hoc. Nickel buys you more for less.

The Nickel ecosystem

Related projects that are part of the Nickel ecosystem:

Getting started

Please follow the getting started guide for Nickel users on the nickel-lang website. The instructions below are either reproduced for this document to be self-contained or because they are aimed toward hacking on the Nickel interpreter itself (e.g. building the nickel-lang-core crate documentation).

Run

  1. Get a Nickel binary:

  2. Run your first program:

    console $ nickel <<< 'let x = 2 in x + x' 4

    Or load it from a file:

    console $ echo 'let s = "world" in "Hello, " ++ s' > program.ncl $ nickel -f program.ncl "Hello, world"

  3. Start a REPL:

    ```console $ nickel repl nickel> let x = 2 in x + x 4

    nickel> ```

    Use :help for a list of available commands.

  4. Export your configuration to JSON, YAML or TOML:

    console $ nickel export --format json <<< '{foo = "Hello, world!"}' { "foo": "Hello, world!" }

Use nickel help for a list of subcommands, and nickel help <subcommand> for help about a specific subcommand.

Editor Setup

Nickel has syntax highlighting plugins for Vim/Neovim, and VSCode. In-editor diagnostics, type hints, and auto-completion are provided by the Nickel Language Server. Please follow the LSP guide to set up syntax highlighting and NLS.

Formatting

Warning: because the cargo registry (crates.io) requires that all dependencies of Nickel are published there as well, the format feature isn't enabled when installing nickel with cargo install as of Nickel version 1.2.0. In this case, please use Topiary separately to format Nickel source code.

To format a Nickel source file, use nickel format (-i is short for --in-place):

console nickel format -i -f my-config.ncl

Nickel uses Topiary to format Nickel code under the hood.

Please follow the Formatting Capabilities section of the LSP documentation to know how to hook up the Nickel LSP and Topiary in order to enable formatting inside your code editor.

Build

  1. Download build dependencies:

  2. Build Nickel:

    console cargo build --release

    And voilĂ ! Generated files are placed in target/release.

Test

Run tests with

console cargo test

Documentation

The user manual is available on the nickel-lang.org website, and in this repository as a collection of Markdown files in doc/manual.

To get the documentation of the nickel-lang codebase itself:

  1. Build the doc:

    console cargo doc --no-deps

  2. Open the file target/doc/nickel/index.html in your browser.

Examples

You can find examples in the ./examples directory.

Current state and roadmap

Nickel is currently released in version 1.0. We expect the core design of the language to be stable and the language to be useful for real-world applications. The next steps we plan to work on are:

Comparison

See RATIONALE.md for the design rationale and a more detailed comparison with these languages.

Comparison with other configuration languages

| Language | Typing | Recursion | Evaluation | Side-effects | |----------|-------------------------------|------------|------------|--------------------------------------------------| | Nickel | Gradual (dynamic + static) | Yes | Lazy | Yes (constrained, planned) | | Starlark | Dynamic | No | Strict | No | | Nix | Dynamic | Yes | Lazy | Predefined and specialized to package management | | Dhall | Static (requires annotations) | Restricted | Lazy | No | | CUE | Static (everything is a type) | No | Lazy | No, but allowed in the separated scripting layer | | Jsonnet | Dynamic | Yes | Lazy | No | | JSON | None | No | Strict | No | | YAML | None | No | N/A | No | | TOML | None | No | N/A | No |