201173afac
C++ nix uses C-style zero-terminated char pointers to represent strings internally - however, up to this point, tvix has used Rust `String` and `str` for string values. Since those are required to be valid utf-8, we haven't been able to properly represent all the string values that Nix supports. To fix that, this change converts the internal representation of the NixString struct from `Box<str>` to `BString`, from the `bstr` crate - this is a wrapper around a `Vec<u8>` with extra functions for treating that byte vector as a "morally string-like" value, which is basically exactly what we need. Since this changes a pretty fundamental assumption about a pretty core type, there are a *lot* of changes in a lot of places to make this work, but I've tried to keep the general philosophy and intent of most of the code in most places intact. Most notably, there's nothing that's been done to make the derivation stuff in //tvix/glue work with non-utf8 strings everywhere, instead opting to just convert to String/str when passing things into that - there *might* be something to be done there, but I don't know what the rules should be and I don't want to figure them out in this change. To deal with OS-native paths in a way that also works in WASM for tvixbolt, this also adds a dependency on the "os_str_bytes" crate. Fixes: b/189 Fixes: b/337 Change-Id: I5e6eb29c62f47dd91af954f5e12bfc3d186f5526 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10200 Reviewed-by: tazjin <tazjin@tvl.su> Reviewed-by: flokli <flokli@flokli.de> Reviewed-by: sterni <sternenseemann@systemli.org> Autosubmit: aspen <root@gws.fyi> Tested-by: BuildkiteCI |
||
---|---|---|
.. | ||
benches | ||
builtin-macros | ||
docs | ||
proptest-regressions/value | ||
src | ||
tests | ||
.skip-subtree | ||
build.rs | ||
Cargo.toml | ||
default.nix | ||
README.md |
Tvix Evaluator
This project implements an interpreter for the Nix programming language. You can experiment with an online version of the evaluator: tvixbolt.
The interpreter aims to be compatible with nixpkgs
, on the
foundation of Nix 2.3.
Important note: The evaluator is not yet feature-complete, and while the core mechanisms (compiler, runtime, ...) have stabilised somewhat, a lot of components are still changing rapidly.
Please contact TVL with any questions you might have.
Building tvix-eval
Please check the README.md
one level up for instructions on how to build this.
The evaluator itself can also be built with standard Rust tooling (i.e. cargo build
).
If you would like to clone only the evaluator and build it directly with Rust tooling, you can do:
git clone https://code.tvl.fyi/depot.git:/tvix/eval.git tvix-eval
cd tvix-eval && cargo build
Tests
Tvix currently has three language test suites for tvix-eval:
-
nix_tests
andtvix_tests
are based on the same mechanism borrowed from the C++ Nix implementation. They consist of Nix files as well as expected output (if applicable). The test cases are split into four categories:eval-okay
(evaluates successfully with the expected output),eval-fail
(fails to evaluate, no expected output),parse-okay
(expression parses successfully, no expected output) andparse-fail
(expression fails to parse, no expected output). Tvix currently ignores the last two types of test cases, since it doesn't implement its own parser.Both test suites have a
notyetpassing
directory. All test cases in here test behavior that is not yet supported by Tvix. They are considered to be expected failures, so you can't forget to move them into the test suite proper when fixing the incompatibility.Additionally, separate targets in the depot pipeline, under
//tvix/verify-lang-tests
, check both test suites (includingnotyetpassing
directories) against C++ Nix 2.3 and the default C++ Nix version in nixpkgs. This way we can prevent accidentally introducing test cases for behavior that C++ Nix doesn't exhibit.-
nix_tests
has the test cases from C++ Nix's language test suite and is sporadically updated by manually syncing the directories. Thenotyetpassing
directory shows how far it is until we pass it completely. -
tvix_tests
contains test cases written by the Tvix contributors. Some more or less duplicate test cases contained innix_tests
, but many cover relevant behavior that isn't bynix_tests
. Consequently, it'd be nice to eventually merge the two test suites into a jointly maintained, common Nix language test suite.It also has a
notyetpassing
directory for missing behavior that is discovered while working on Tvix and isn't covered by thenix_tests
suite.
-
-
nix_oracle
can evaluate Nix expressions in Tvix and compare the result against C++ Nix (2.3) directly. Eventually it should gain the ability to property test generated Nix expressions. An additional feature is that it can evaluate expressions without--strict
, so thunking behavior can be verified more easily.
rnix-parser
Tvix is written in memory of jD91mZM2, the author of rnix-parser who sadly passed away.
Tvix makes heavy use of rnix-parser in its bytecode compiler. The parser is now maintained by Nix community members.