Skip to content
Open
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
18 changes: 14 additions & 4 deletions internal/shellgen/nixpkgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"os"
"time"
"log/slog"

"go.jetify.com/devbox/internal/envir"
)
Expand All @@ -19,17 +20,26 @@ type NixpkgsInfo struct {
}

func getNixpkgsInfo(commitHash string) *NixpkgsInfo {
// Default URLs pointing to GitHub
url := fmt.Sprintf("github:NixOS/nixpkgs/%s", commitHash)
tarURL := fmt.Sprintf("https://github.com/nixos/nixpkgs/archive/%s.tar.gz", commitHash)

// Check if a local/internal mirror is available via DEVBOX_CACHE
if mirror := nixpkgsMirrorURL(commitHash); mirror != "" {
url = mirror
url = mirror // flakes use this URL
tarURL = mirror // devbox shell uses this tarball URL
slog.Debug("Using local/internal mirror for nixpkgs", "commit", commitHash, "url", url, "tarURL", tarURL)
} else {
slog.Debug("No local mirror found, falling back to GitHub", "commit", commitHash, "url", url, "tarURL", tarURL)
}

return &NixpkgsInfo{
URL: url,
// legacy, used for shell.nix (which is no longer used, but some direnv users still need it)
TarURL: fmt.Sprintf("https://github.com/nixos/nixpkgs/archive/%s.tar.gz", commitHash),
URL: url,
TarURL: tarURL,
}
}


func nixpkgsMirrorURL(commitHash string) string {
baseURL := os.Getenv(envir.DevboxCache)
if baseURL == "" {
Expand Down