Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions pkg/cache/upstream/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,6 @@ func (c *Cache) GetNarInfo(ctx context.Context, hash string) (*narinfo.NarInfo,
ni.FileSize = ni.NarSize
}

// nix-serve serves the NarURL with the narinfo hash included in the URL as
// prefix to the NAR Hash. Trim that out, we don't need it.
ni.URL = strings.ReplaceAll(ni.URL, hash+"-", "")

return ni, nil
}

Expand Down
2 changes: 1 addition & 1 deletion testdata/nar7.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var Nar7 = Entry{
NarInfoHash: "c12lxpykv6sld7a0sakcnr3y0la70x8w",
NarInfoPath: filepath.Join("c", "c1", "c12lxpykv6sld7a0sakcnr3y0la70x8w.narinfo"),
NarInfoText: `StorePath: /nix/store/c12lxpykv6sld7a0sakcnr3y0la70x8w-hello-2.12.2
URL: nar/c12lxpykv6sld7a0sakcnr3y0la70x8w-09xizkfyvigl5fqs0dhkn46nghfwwijbpdzzl4zg6kx90prjmsg0.nar
URL: nar/09xizkfyvigl5fqs0dhkn46nghfwwijbpdzzl4zg6kx90prjmsg0.nar
Compression: none
NarHash: sha256:1yf3p87fsqig07crd9sj9wh7i9jpsa0x86a22fqbls7c81lc7ws2
NarSize: 113256
Expand Down
32 changes: 31 additions & 1 deletion testdata/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/klauspost/compress/zstd"

"github.com/kalbasit/ncps/pkg/helper"
"github.com/kalbasit/ncps/pkg/nar"
)

type Server struct {
Expand Down Expand Up @@ -122,14 +123,43 @@ func (s *Server) handler() http.Handler {
bs = []byte(entry.NarInfoText)
}

// Support fetching narinfo by NAR hash (used by cache when only NAR hash is available)
if r.URL.Path == "/"+entry.NarHash+".narinfo" {
bs = []byte(entry.NarInfoText)
}

if r.URL.Path == "/nar/"+entry.NarHash+".nar" {
bs = []byte(entry.NarText)
}

if r.URL.Path == "/nar/"+entry.NarHash+".nar."+entry.NarCompression.ToFileExtension() {
// Build path with compression extension, only adding dot if extension is not empty
narPath := "/nar/" + entry.NarHash + ".nar"
if ext := entry.NarCompression.ToFileExtension(); ext != "" {
narPath += "." + ext
}

if r.URL.Path == narPath {
bs = []byte(entry.NarText)
}

// Support fetching by normalized hash (with prefix stripped)
normalizedHash := (&nar.URL{Hash: entry.NarHash}).Normalize().Hash
if normalizedHash != entry.NarHash {
if r.URL.Path == "/nar/"+normalizedHash+".nar" {
bs = []byte(entry.NarText)
}

// Build normalized path with compression extension
normalizedNarPath := "/nar/" + normalizedHash + ".nar"
if ext := entry.NarCompression.ToFileExtension(); ext != "" {
normalizedNarPath += "." + ext
}

if r.URL.Path == normalizedNarPath {
bs = []byte(entry.NarText)
}
}

if len(bs) > 0 {
if s := r.URL.Query().Get("fakesize"); s != "" {
size, err := strconv.Atoi(s)
Expand Down