diff --git a/tvix/nix-compat/src/store_path/utils.rs b/tvix/nix-compat/src/store_path/utils.rs index 2e10c33dc..af593d27a 100644 --- a/tvix/nix-compat/src/store_path/utils.rs +++ b/tvix/nix-compat/src/store_path/utils.rs @@ -61,29 +61,28 @@ pub fn build_ca_path<'a, S: AsRef, I: IntoIterator>( references: I, self_reference: bool, ) -> Result, BuildStorePathError> { - let (ty, hash) = match &ca_hash { - CAHash::Text(ref digest) => { - if self_reference { - return Err(BuildStorePathError::InvalidReference()); - } + // self references are only allowed for CAHash::Nar(NixHash::Sha256(_)). + if self_reference { + let CAHash::Nar(NixHash::Sha256(_)) = ca_hash else { + return Err(BuildStorePathError::InvalidReference()); + }; + } - ( - make_references_string("text", references, false), - NixHash::Sha256(*digest), - ) - } + let (ty, hash) = match &ca_hash { + CAHash::Text(ref digest) => ( + make_references_string("text", references, false), + NixHash::Sha256(*digest), + ), CAHash::Nar(NixHash::Sha256(ref digest)) => ( make_references_string("source", references, self_reference), NixHash::Sha256(*digest), ), + // for all other CAHash::Nar, another custom scheme is used. CAHash::Nar(ref hash) => { if references.into_iter().next().is_some() { return Err(BuildStorePathError::InvalidReference()); } - if self_reference { - return Err(BuildStorePathError::InvalidReference()); - } ( "output:out".to_string(), @@ -99,9 +98,6 @@ pub fn build_ca_path<'a, S: AsRef, I: IntoIterator>( if references.into_iter().next().is_some() { return Err(BuildStorePathError::InvalidReference()); } - if self_reference { - return Err(BuildStorePathError::InvalidReference()); - } ( "output:out".to_string(),