about summary refs log tree commit diff
path: root/tvix/store/protos/pathinfo.go
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/store/protos/pathinfo.go')
-rw-r--r--tvix/store/protos/pathinfo.go31
1 files changed, 22 insertions, 9 deletions
diff --git a/tvix/store/protos/pathinfo.go b/tvix/store/protos/pathinfo.go
index 2c718c6245d5..9b51b5266cdc 100644
--- a/tvix/store/protos/pathinfo.go
+++ b/tvix/store/protos/pathinfo.go
@@ -60,42 +60,55 @@ func (p *PathInfo) Validate() (*storepath.StorePath, error) {
 	// for all three node types, ensure the name properly parses to a store path,
 	// and in case it refers to a digest, ensure it has the right length.
 
+	var storePath *storepath.StorePath
+	var err error
+
 	if node := rootNode.GetDirectory(); node != nil {
 		if len(node.Digest) != 32 {
 			return nil, fmt.Errorf("invalid digest size for %s, expected %d, got %d", node.Name, 32, len(node.Digest))
 		}
 
-		storePath, err := storepath.FromString(string(node.GetName()))
+		storePath, err = storepath.FromString(string(node.GetName()))
 
 		if err != nil {
 			return nil, fmt.Errorf("unable to parse %s as StorePath: %w", node.Name, err)
 		}
 
-		return storePath, nil
-
 	} else if node := rootNode.GetFile(); node != nil {
 		if len(node.Digest) != 32 {
 			return nil, fmt.Errorf("invalid digest size for %s, expected %d, got %d", node.Name, 32, len(node.Digest))
 		}
 
-		storePath, err := storepath.FromString(string(node.GetName()))
+		storePath, err = storepath.FromString(string(node.GetName()))
 		if err != nil {
 			return nil, fmt.Errorf("unable to parse %s as StorePath: %w", node.Name, err)
 		}
 
-		return storePath, nil
-
 	} else if node := rootNode.GetSymlink(); node != nil {
-		storePath, err := storepath.FromString(string(node.GetName()))
+		storePath, err = storepath.FromString(string(node.GetName()))
 
 		if err != nil {
 			return nil, fmt.Errorf("unable to parse %s as StorePath: %w", node.Name, err)
 		}
 
-		return storePath, nil
-
 	} else {
 		// this would only happen if we introduced a new type
 		panic("unreachable")
 	}
+
+	// If the Deriver field is populated, ensure it parses to a StorePath.
+	// We can't check for it to *not* end with .drv, as the .drv files produced by
+	// recursive Nix end with multiple .drv suffixes, and only one is popped when
+	// converting to this field.
+	if p.Deriver != nil {
+		storePath := storepath.StorePath{
+			Name:   string(p.Deriver.GetName()),
+			Digest: p.Deriver.GetDigest(),
+		}
+		if err := storePath.Validate(); err != nil {
+			return nil, fmt.Errorf("invalid deriver field: %w", err)
+		}
+	}
+
+	return storePath, nil
 }