Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[packages] Recommend go from devbox index #1059

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
17 changes: 4 additions & 13 deletions internal/initrec/recommenders/golang/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package golang

import (
"fmt"
"os"
"path/filepath"

Expand All @@ -13,14 +14,7 @@ import (
"go.jetpack.io/devbox/internal/initrec/recommenders"
)

var versionMap = map[string]string{
// Map go versions to the corresponding nixpkgs:
"1.19": "go_1_19",
"1.18": "go",
"1.17": "go_1_17",
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason we had these versions was that in nixpkgs, these versions were available. Right now we also index older hashes of nixpkgs as far back as go@1.13 you can see that by doing devbox search go.
If we don't have this versionMap, there will be an (unlikely) edge case where a user can have go version 1.12 which gets parsed but will see an error package not found.
So, imo, we should have a map of supported versions (1.20 to 1.13) and default to 1.20 in the case of the user's goVersion not being in the map.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we can also handle this by showing a specific error message (e.g., "go version not supported please use devbox search go to see a list of supported versions)"


const defaultPkg = "go_1_19" // Default to "latest" for cases where we can't determine a version.
const defaultPkg = "go@1.20" // Default to "latest" for cases where we can't determine a version.

type Recommender struct {
SrcDir string
Expand All @@ -42,12 +36,9 @@ func (r *Recommender) Packages() []string {
func getGoPackage(srcDir string) string {
goModPath := filepath.Join(srcDir, "go.mod")
goVersion := parseGoVersion(goModPath)
v, ok := versionMap[goVersion]
if ok {
return v
if goVersion != "" {
return fmt.Sprintf("go@%s", goVersion)
}
// Should we be throwing an error instead, if we don't have a nix package
// for the specified version of go?
return defaultPkg
}

Expand Down