about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
Diffstat (limited to 'tvix')
-rw-r--r--tvix/nix-compat/src/store_path/utils.rs28
1 files changed, 12 insertions, 16 deletions
diff --git a/tvix/nix-compat/src/store_path/utils.rs b/tvix/nix-compat/src/store_path/utils.rs
index 2e10c33dcdaa..af593d27affd 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<str>, I: IntoIterator<Item = S>>(
     references: I,
     self_reference: bool,
 ) -> Result<StorePathRef<'a>, 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<str>, I: IntoIterator<Item = S>>(
             if references.into_iter().next().is_some() {
                 return Err(BuildStorePathError::InvalidReference());
             }
-            if self_reference {
-                return Err(BuildStorePathError::InvalidReference());
-            }
 
             (
                 "output:out".to_string(),