diff options
Diffstat (limited to 'tvix/glue/src/builtins/derivation.rs')
-rw-r--r-- | tvix/glue/src/builtins/derivation.rs | 84 |
1 files changed, 33 insertions, 51 deletions
diff --git a/tvix/glue/src/builtins/derivation.rs b/tvix/glue/src/builtins/derivation.rs index b17b90466965..3048fd8390c2 100644 --- a/tvix/glue/src/builtins/derivation.rs +++ b/tvix/glue/src/builtins/derivation.rs @@ -179,12 +179,10 @@ pub(crate) mod derivation_builtins { use nix_compat::nixhash::CAHash; use nix_compat::store_path::{build_ca_path, hash_placeholder}; use sha2::Sha256; - use tvix_castore::proto as castorepb; - use tvix_castore::proto::node::Node; - use tvix_castore::proto::FileNode; + use tvix_castore::Node; use tvix_eval::generators::Gen; use tvix_eval::{NixContext, NixContextElement, NixString}; - use tvix_store::proto::{NarInfo, PathInfo}; + use tvix_store::pathinfoservice::PathInfo; #[builtin("placeholder")] async fn builtin_placeholder(co: GenCo, input: Value) -> Result<Value, ErrorKind> { @@ -302,7 +300,7 @@ pub(crate) mod derivation_builtins { // Remove the original default `out` output. drv.outputs.clear(); - let mut output_names = vec![]; + let mut output_names = Vec::with_capacity(outputs.len()); for output in outputs { let output_name = generators::request_force(&co, output) @@ -381,11 +379,7 @@ pub(crate) mod derivation_builtins { return Ok(val); } - let (val_json, context) = match val.into_contextful_json(&co).await? { - Ok(v) => v, - Err(cek) => return Ok(Value::from(cek)), - }; - + let (val_json, context) = val.into_contextful_json(&co).await?; input_context.extend(context.into_iter()); // No need to check for dups, we only iterate over every attribute name once @@ -570,21 +564,11 @@ pub(crate) mod derivation_builtins { let blob_digest = blob_writer.close().await?; let ca_hash = CAHash::Text(Sha256::digest(&content).into()); - let store_path = - build_ca_path(name.to_str()?, &ca_hash, content.iter_ctx_plain(), false) - .map_err(|_e| { - nix_compat::derivation::DerivationError::InvalidOutputName( - name.to_str_lossy().into_owned(), - ) - }) - .map_err(DerivationError::InvalidDerivation)?; - - let root_node = Node::File(FileNode { - name: store_path.to_string().into(), - digest: blob_digest.into(), + let root_node = Node::File { + digest: blob_digest, size: blob_size, executable: false, - }); + }; // calculate the nar hash let (nar_size, nar_sha256) = state @@ -593,40 +577,38 @@ pub(crate) mod derivation_builtins { .await .map_err(|e| ErrorKind::TvixError(Rc::new(e)))?; - // assemble references from plain context. - let reference_paths: Vec<StorePathRef> = content - .iter_ctx_plain() - .map(|elem| StorePathRef::from_absolute_path(elem.as_bytes())) - .collect::<Result<_, _>>() - .map_err(|e| ErrorKind::TvixError(Rc::new(e)))?; - // persist via pathinfo service. state .path_info_service .put(PathInfo { - node: Some(castorepb::Node { - node: Some(root_node), - }), - references: reference_paths - .iter() - .map(|x| bytes::Bytes::copy_from_slice(x.digest())) - .collect(), - narinfo: Some(NarInfo { - nar_size, - nar_sha256: nar_sha256.to_vec().into(), - signatures: vec![], - reference_names: reference_paths - .into_iter() - .map(|x| x.to_string()) - .collect(), - deriver: None, - ca: Some(ca_hash.into()), - }), + store_path: build_ca_path( + name.to_str()?, + &ca_hash, + content.iter_ctx_plain(), + false, + ) + .map_err(|_e| { + nix_compat::derivation::DerivationError::InvalidOutputName( + name.to_str_lossy().into_owned(), + ) + }) + .map_err(DerivationError::InvalidDerivation)?, + node: root_node, + // assemble references from plain context. + references: content + .iter_ctx_plain() + .map(|elem| StorePath::from_absolute_path(elem.as_bytes())) + .collect::<Result<_, _>>() + .map_err(|e| ErrorKind::TvixError(Rc::new(e)))?, + nar_size, + nar_sha256, + signatures: vec![], + deriver: None, + ca: Some(ca_hash), }) .await - .map_err(|e| ErrorKind::TvixError(Rc::new(e)))?; - - Ok::<_, ErrorKind>(store_path) + .map_err(|e| ErrorKind::TvixError(Rc::new(e))) + .map(|path_info| path_info.store_path) })?; let abs_path = store_path.to_absolute_path(); |