refactor(tvix/glue): move Fetch[er] into its own types, fetch lazily

We actually want to delay fetching until we actually need the file. A
simple evaluation asking for `.outPath` or `.drvPath` should work even
in a pure offline environment.

Before this CL, the fetching logic was quite distributed between
tvix_store_io, and builtins/fetchers.rs.

Rather than having various functions and conversions between structs,
describe a Fetch as an enum type, with the fields describing the fetch.

Define a store_path() function on top of `Fetch` which can be used to
ask for the calculated store path (if the digest has been provided
upfront).

Have a `Fetcher` struct, and give it a `fetch_and_persist` function,
taking a `Fetch` as well as a desired name, and have it deal with all
the logic of persisting the PathInfos. It also returns a StorePathRef,
similar to the `.store_path()` method on a `Fetch` struct.

In a followup CL, we can extend KnownPaths to track fetches AND
derivations, and then use `Fetcher` when we need to do IO into that
store path.

Change-Id: Ib39a96baeb661750a8706b461f8ba4abb342e777
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11500
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2024-04-22 14:02:48 +03:00 committed by clbot
parent dc444e55dc
commit 091de12a9a
8 changed files with 538 additions and 399 deletions

2
tvix/Cargo.lock generated
View file

@ -4394,6 +4394,7 @@ dependencies = [
"hex-literal",
"lazy_static",
"magic",
"md-5",
"nix 0.27.1",
"nix-compat",
"pin-project",
@ -4402,6 +4403,7 @@ dependencies = [
"rstest",
"serde",
"serde_json",
"sha1",
"sha2",
"tempfile",
"thiserror",