Subject: [tvix] string contexts vs. reference scanning

From: Vincent Ambo <[email-masked]>
Date: Mon, 9 Jan 2023 14:07:58 -0800

[this mail thread is started out of another mail conversation]

We are currently implementing `builtins.derivationStrict`, which
translates the string context in evaluator values to the inputDrvs and
inputSrcs fields in a derivation struct in C++ Nix.

Florian and I have been "documenting"[0] our understanding of the code
that does this in Nix as we go along.

As amjoseph has previously said, string contexts are likely unnecessary:

Adam Joseph <[email-masked]> writes:
> Related to that second reason: I've written a tool (using the awesome
> libnixstore crate) that calculates drv.inputDrvs using scanForReferences
> instead of string contexts, and compares the calculated results to what
> cppnix produced. I ran it on the 144,586 derivations in my buildfarm's
> store, and (after fixing a lot of bugs in my scanner) there was only a
> single disagreement in the entire store, which IMHO is better described
> as a revealed bug in nixpkgs

Because of this, We plan to use reference scanning over derivation input
attributes instead of string contexts, but may need to address the
problem of implementing unsafeDiscardStringContext to support certain
use cases[1].

Adam, would you be up for pushing a WIP CL (or a commit straight to
//users/amjoseph!) with the scanner you've written (and esp. with your
bugfixes!) that we could then figure out how to integrate? It might help
us avoid some overhead of running into the same bugs again :)

Any other input people might have on string contexts is also welcome!

[0]: https://github.com/tvlfyi/nix/commit/wtf-are-contexts

[1]: I'm not actually sure about this. It's possible that all these
use-cases that exist right now (e.g. string context discarding in TVL's
:llama: step) actually go away with the Tvix model of starting builds
immediately, but strongly ordered. Thoughts?