• Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A reasonable configuration language

Ruud’s Configuration Language

Ruud’s Configuration Language, RCL for short, is a domain-specific language optimized for specifying human-written data with just enough abstraction features to avoid repetition. It is a superset of json that extends it into a simple functional programming language that resembles Python and Nix. Use cases include:

  • Querying json documents, like jq, but with a more familiar language.
  • Generating repetitive configuration files, such as GitHub Actions workflows or Terraform configuration.
  • Enabling large repositories to split configuration into small reusable pieces that can be referenced from a single consistent entry point, in the same way that Nix enables this for Nixpkgs.
  • Sharing configuration between tools that do not natively share data. For example, import the same user account definitions into Terraform, Tailscale, Kubernetes, and Ansible.

RCL can be used through the rcl command-line tool that can export documents to json and other formats. It can also be used through a native Python module, with an interface similar to the json module.

Warning

While RCL is usable, it is still in an early exploratory stage with frequent breaking changes. This is a hobby project without stability promise.

Getting started

See the manual for more information. The most useful chapters to get started:

You may also find the examples in the examples directory instructive.

Rationale

Why another config language?

  • HCL is too ad-hoc to be suitable for any serious abstraction (setunion is variadic so it only works with a statically known number of sets; flatten recursively flattens so it can’t be typed properly and breaks generic code, for comprehensions can’t do nested loops, for_each syntax is bolted on, etc.)

  • Nix-the-language is great but forces the entire Nix store on you when all I want is to evaluate expressions.

  • Python is great but requires some boilerplate for doing the IO if you want to use it as a configuration language. Also the syntactic order of list comprehensions prevents autocomplete in editors.

  • Dhall has the right ideas but the syntax and heavy use of Unicode symbols make it look ugly.

  • CUE and Nickel were not invented here.

  • For more background, see the blog post: A reasonable configuration language.

Classification

  • Purely functional: RCL documents are expressions that evaluate to values, rather than sequences of statements that have side effects. Values are immutable, there are no mutable objects. Functions are values.

  • Gradually typed: Optional type annotations can be used to prevent bugs and to make code more self-documenting. All type annotations are enforced.

  • Json superset: Vaporware, this is not fully implemented; floats are not yet supported.

Usage

Build:

cargo build --release

Print usage:

target/release/rcl
target/release/rcl eval --help

Evaluate an RCL expression to json:

target/release/rcl eval examples/tags.rcl

Query an RCL or json document:

target/release/rcl query examples/tags.rcl input.tags.ams01

Autoformat an RCL expression (non-destructive, prints to stdout):

target/release/rcl fmt examples/tags.rcl

Highlight an RCL expression in your terminal:

target/release/rcl highlight examples/tags.rcl

Development

Run all tests and checks below in one command:

nix flake check

Run golden tests:

cargo build
golden/run.py

Check the grammar for ambiguities:

bison -Werror=all etc/bison/grammar.y

Run unit tests and lints:

cargo test
cargo clippy

Typecheck Python sources

mypy --strict --exclude pyrcl .
mypy --strict pyrcl

Check formatting:

cargo fmt
black .

View coverage of the golden tests:

nix build .#coverage --out-link result
xdg-open result/index.html

Run the fuzzer:

cargo +nightly-2023-06-03 fuzz run main -- -dict=fuzz/dictionary.txt -timout=5

Building the Python module

Build the shared object:

cargo build --manifest-path pyrcl/Cargo.toml

Give the shared object the appropriate name for the Python interpreter to discover it:

mv target/debug/{libpyrcl,rcl}.so

Tell Python where to find the shared object, run the interpreter:

PYTHONPATH=target/debug python3
>>> import rcl
>>> help(rcl.loads)
>>> rcl.load_file("examples/buckets.rcl")

Building WASM

See the readme in the wasm directory.

License

RCL is licensed under the Apache 2.0 license. It may be used in free software as well as closed-source applications, both for commercial and non-commercial use under the conditions given in the license. If you want to use RCL in your GPLv2-licensed software, you can add an exception to your copyright notice. Please do not open an issue if you disagree with the choice of license.

More Repositories

1

hound

A wav encoding and decoding library in Rust
Rust
464
star
2

claxon

A FLAC decoder in Rust
Rust
285
star
3

blog

My personal site
Haskell
122
star
4

pris

A language for designing slides
Rust
115
star
5

robigo-luculenta

Proof of concept spectral path tracer in Rust
Rust
106
star
6

musium

Music playback daemon with web-based library browser
Rust
81
star
7

luculentus

Proof of concept spectral path tracer
C++
46
star
8

convector

Interactive CPU path tracer
Rust
45
star
9

thread-id

Get a unique thread ID in Rust
Rust
41
star
10

filebuffer

Fast and simple file reading for Rust
Rust
35
star
11

noblit

An immutable append-only database
Rust
27
star
12

bs1770

A Rust library that implements ITU-R BS.1770-4 loudness measurement
Rust
18
star
13

kilsbergen

A clean MkDocs theme
HTML
10
star
14

transducers

A transducer library for Rust
Rust
10
star
15

hoff

A gatekeeper for your commits
Haskell
8
star
16

rx

Reactive programming for Rust
Rust
8
star
17

sempervivum

A plant watering tracker
PureScript
8
star
18

tako

Updater for single files
Rust
7
star
19

sqlog

Ingest Nginx logs into a SQLite database for easy querying
Python
7
star
20

notes

Make Git remember so I don’t have to
6
star
21

dotfiles

My universal personal configuration
Vim Script
5
star
22

deadlock

Fast search-based password manager
C++
5
star
23

miniserver

Nginx and Lego on Flatcar Linux
Python
5
star
24

hanson

Self-hosted prediction market app
Python
5
star
25

fibint

Compute Fibonacci numbers efficiently using finite fields
C++
4
star
26

squiller

Generate boilerplate from annotated SQL queries
Rust
4
star
27

bscthesis

The source for my bachelor’s thesis
TeX
3
star
28

gitscrobbler

Cross-reference commit history with your Last.fm scrobbles
C#
3
star
29

zerorack

Experiments with circuit compilation and zk-snarks
Haskell
3
star
30

hitsgame

Create your own version of the game Hitster
Python
3
star
31

btrfs-mirror-subvolumes

Mirror btrfs subvolumes to another file system while preserving sharing
Rust
2
star
32

rust-utrecht

Source code to go with the Rust Utrecht meetups
Rust
2
star
33

audiograter

A GTK-based spectrogram viewer
Rust
2
star
34

adventofcode

My solutions to Advent of Code
Pony
1
star
35

basstrace

Visualize room acoustics
Rust
1
star
36

christmas-tree

An API for lighting up my Christmas tree
Haskell
1
star
37

git-dep

A tool to manage dependent branches
Haskell
1
star
38

deepnote

Generate track embeddings based on listening history
Python
1
star
39

ggj15

Global Game Jam 2015 game
C#
1
star