From 07bf8a0b6d4541e1982968c03279a0491056ac2f Mon Sep 17 00:00:00 2001 From: Yureka Date: Wed, 7 Aug 2024 19:18:45 +0200 Subject: [PATCH] feat(tvix/pathinfo/nixhttp): use ingest stores from url This still defaults to the "default" services, but allows users to tell the nix+http pathinfoservice to ingest the castore nodes into a non-default blob-/directoryservice when used with the experimental store composition. Change-Id: I5c0f683ce95d888eadf3f302520a47f42f1a481d Reviewed-on: https://cl.tvl.fyi/c/depot/+/12148 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/store/src/pathinfoservice/nix_http.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tvix/store/src/pathinfoservice/nix_http.rs b/tvix/store/src/pathinfoservice/nix_http.rs index 5f1eed1a0..2ff094858 100644 --- a/tvix/store/src/pathinfoservice/nix_http.rs +++ b/tvix/store/src/pathinfoservice/nix_http.rs @@ -267,6 +267,7 @@ pub struct NixHTTPPathInfoServiceConfig { impl TryFrom for NixHTTPPathInfoServiceConfig { type Error = Box; fn try_from(url: Url) -> Result { + // Be careful about the distinction between `None` and `Some(vec![])`! let mut public_keys: Option> = None; for (_, v) in url .query_pairs() @@ -277,13 +278,28 @@ impl TryFrom for NixHTTPPathInfoServiceConfig { .get_or_insert(Default::default()) .extend(v.split_ascii_whitespace().map(ToString::to_string)); } + + // FUTUREWORK: move url deserialization to serde? + let blob_service = url + .query_pairs() + .into_iter() + .find(|(k, _)| k == "blob_service") + .map(|(_, v)| v.to_string()) + .unwrap_or("default".to_string()); + let directory_service = url + .query_pairs() + .into_iter() + .find(|(k, _)| k == "directory_service") + .map(|(_, v)| v.to_string()) + .unwrap_or("default".to_string()); + Ok(NixHTTPPathInfoServiceConfig { // Stringify the URL and remove the nix+ prefix. // We can't use `url.set_scheme(rest)`, as it disallows // setting something http(s) that previously wasn't. base_url: url.to_string().strip_prefix("nix+").unwrap().to_string(), - blob_service: "default".to_string(), - directory_service: "default".to_string(), + blob_service, + directory_service, public_keys, }) }