feat(tvix/glue): support builtin:fetchurl

nixpkgs calls <nix/fetchurl.nix> during nixpkgs bootstrap.

This produces a fake derivation with system = builtin
and builder = builtin:fetchurl, and needs to download files from the
internet.

At the end of the Derivation construction, if we have such a derivation,
also synthesize a `Fetch` struct, which we add to the known fetch paths.

This will then cause these fetches to be picked up like all other
fetches in TvixStoreIO.

Change-Id: I72cbca4f85da106b25eda97693a6a6e59911cd57
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10975
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2024-02-19 22:20:09 +07:00 committed by flokli
parent b08379096f
commit 842d6816bf
5 changed files with 197 additions and 15 deletions

View file

@ -170,6 +170,7 @@ pub(crate) mod derivation_builtins {
use std::collections::BTreeMap;
use crate::builtins::utils::{select_string, strong_importing_coerce_to_string};
use crate::fetchurl::fetchurl_derivation_to_fetch;
use super::*;
use bstr::ByteSlice;
@ -506,6 +507,17 @@ pub(crate) mod derivation_builtins {
))),
)));
// If the derivation is a fake derivation (builtins:fetchurl),
// synthesize a [Fetch] and add it there, too.
if drv.builder == "builtin:fetchurl" {
let (name, fetch) =
fetchurl_derivation_to_fetch(&drv).map_err(|e| ErrorKind::TvixError(Rc::new(e)))?;
known_paths
.add_fetch(fetch, &name)
.map_err(|e| ErrorKind::TvixError(Rc::new(e)))?;
}
// Register the Derivation in known_paths.
known_paths.add_derivation(drv_path, drv);