feat(tvix/glue/fetchers): support file:// URLs

Nix supports file:// - URLs for `fetchurl` and `fetchTarball`.

Convert the enums and function arguments to hold a URL type.
reqwest::Url is a re-export of the url crate, but they don't re-export
the parsing errors, and as we want to hold these in our Error types, add
it to Cargo.toml explicitly.

The Fetcher::download function now checks on the scheme, and either
opens the file locally, or does do a HTTP request as before.

Fetch gets its custom debug impl, removing potentially sensitive
username and password out of URLs.

Change-Id: I777db1fe487370e822cbfec4624034aca5e08045
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11504
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2024-04-22 20:05:49 +03:00 committed by flokli
parent dfef3d18d1
commit 8181817e53
9 changed files with 124 additions and 37 deletions

View file

@ -3,6 +3,7 @@ use nix_compat::{
nixhash::{self, NixHash},
store_path::BuildStorePathError,
};
use reqwest::Url;
use std::rc::Rc;
use thiserror::Error;
@ -33,7 +34,7 @@ impl From<DerivationError> for tvix_eval::ErrorKind {
pub enum FetcherError {
#[error("hash mismatch in file downloaded from {url}:\n wanted: {wanted}\n got: {got}")]
HashMismatch {
url: String,
url: Url,
wanted: NixHash,
got: NixHash,
},
@ -41,6 +42,9 @@ pub enum FetcherError {
#[error("Invalid hash type '{0}' for fetcher")]
InvalidHashType(&'static str),
#[error("Unable to parse URL: {0}")]
InvalidUrl(#[from] url::ParseError),
#[error(transparent)]
Http(#[from] reqwest::Error),