diff options
author | Florian Klink <flokli@flokli.de> | 2024-10-10T21·45+0300 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2024-10-11T17·19+0000 |
commit | 48fa320cf49fee159d8cdd031c21ae6d17dbb7b3 (patch) | |
tree | 01bf98442ba94923f87d50be5265643c05246bbc /tvix | |
parent | e8040ec61f2119ece2d396704576973f704607f3 (diff) |
refactor(nix-compat/store_path): consistently use SP as type param r/8788
We also use S in other places in the same file, but that's for the string-like references. SP is now consistently used as the type parameter for StorePath<_> (and build_output_path) gets support for it). By being a bit more careful in the order of assignments in nix-compat/ src/derivation, we can nudge the compiler to use the type we want. Change-Id: Ia7c298e110dff98d3b113d2388674ce9e22b80e8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12590 Reviewed-by: flokli <flokli@flokli.de> Reviewed-by: Marijan Petričević <marijan.petricevic94@gmail.com> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/nix-compat/src/derivation/mod.rs | 8 | ||||
-rw-r--r-- | tvix/nix-compat/src/store_path/mod.rs | 2 | ||||
-rw-r--r-- | tvix/nix-compat/src/store_path/utils.rs | 13 |
3 files changed, 13 insertions, 10 deletions
diff --git a/tvix/nix-compat/src/derivation/mod.rs b/tvix/nix-compat/src/derivation/mod.rs index 6baeaba38299..445e9cb43143 100644 --- a/tvix/nix-compat/src/derivation/mod.rs +++ b/tvix/nix-compat/src/derivation/mod.rs @@ -257,8 +257,8 @@ impl Derivation { // For fixed output derivation we use [build_ca_path], otherwise we // use [build_output_path] with [hash_derivation_modulo]. - let abs_store_path = if let Some(ref hwm) = output.ca_hash { - build_ca_path(&path_name, hwm, Vec::<String>::new(), false).map_err(|e| { + let store_path = if let Some(ref hwm) = output.ca_hash { + build_ca_path(&path_name, hwm, Vec::<&str>::new(), false).map_err(|e| { DerivationError::InvalidOutputDerivationPath(output_name.to_string(), e) })? } else { @@ -270,11 +270,11 @@ impl Derivation { })? }; - output.path = Some(abs_store_path.to_owned()); self.environment.insert( output_name.to_string(), - abs_store_path.to_absolute_path().into(), + store_path.to_absolute_path().into(), ); + output.path = Some(store_path); } Ok(()) diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs index 177cc96ce20f..546c34d93615 100644 --- a/tvix/nix-compat/src/store_path/mod.rs +++ b/tvix/nix-compat/src/store_path/mod.rs @@ -139,7 +139,7 @@ where S: From<&'a str>, { Ok(Self { - name: validate_name(name.as_bytes())?.into(), + name: validate_name(name)?.into(), digest, }) } diff --git a/tvix/nix-compat/src/store_path/utils.rs b/tvix/nix-compat/src/store_path/utils.rs index 4bfbb72fcdde..3cf3ba06308f 100644 --- a/tvix/nix-compat/src/store_path/utils.rs +++ b/tvix/nix-compat/src/store_path/utils.rs @@ -134,11 +134,14 @@ pub fn build_nar_based_store_path<'a>( /// /// Input-addresed store paths are always derivation outputs, the "input" in question is the /// derivation and its closure. -pub fn build_output_path<'a>( +pub fn build_output_path<'a, SP>( drv_sha256: &[u8; 32], output_name: &str, output_path_name: &'a str, -) -> Result<StorePathRef<'a>, Error> { +) -> Result<StorePath<SP>, Error> +where + SP: std::cmp::Eq + std::ops::Deref<Target = str> + std::convert::From<&'a str>, +{ build_store_path_from_fingerprint_parts( &(String::from("output:") + output_name), drv_sha256, @@ -156,13 +159,13 @@ pub fn build_output_path<'a>( /// bytes. /// Inside a StorePath, that digest is printed nixbase32-encoded /// (32 characters). -fn build_store_path_from_fingerprint_parts<'a, S>( +fn build_store_path_from_fingerprint_parts<'a, SP>( ty: &str, inner_digest: &[u8; 32], name: &'a str, -) -> Result<StorePath<S>, Error> +) -> Result<StorePath<SP>, Error> where - S: std::cmp::Eq + std::ops::Deref<Target = str> + std::convert::From<&'a str>, + SP: std::cmp::Eq + std::ops::Deref<Target = str> + std::convert::From<&'a str>, { let fingerprint = format!( "{ty}:sha256:{}:{STORE_DIR}:{name}", |