Skip to content

Commit

Permalink
[Config Packages] Suggest --platform/--exclude-platform upon error wi…
Browse files Browse the repository at this point in the history
…th installing package that is uninstallable on user's platform
  • Loading branch information
savil committed Aug 10, 2023
1 parent f65133a commit d9e54f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/nix/nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ var nixPlatforms = []string{
"armv7l-linux",
}

func SupportedPlatforms() []string {
return nixPlatforms
}

// EnsureValidPlatform returns an error if the platform is not supported by nix.
// https://nixos.org/manual/nix/stable/installation/supported-platforms.html
func EnsureValidPlatform(platform string) error {
Expand Down
16 changes: 15 additions & 1 deletion internal/nix/nixprofile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/fatih/color"
"github.com/pkg/errors"
"github.com/samber/lo"
"go.jetpack.io/devbox/internal/boxcli/usererr"
"go.jetpack.io/devbox/internal/devpkg"
"go.jetpack.io/devbox/internal/lock"
Expand Down Expand Up @@ -265,9 +266,22 @@ func ProfileInstall(args *ProfileInstallArgs) error {
if exists, err := input.ValidateInstallsOnSystem(); err != nil {
return err
} else if !exists {
platform, err := nix.System()
if err != nil {
platform = ""
} else {
platform = " " + platform
}
otherPlatforms := lo.Filter(nix.SupportedPlatforms(), func(p string, _ int) bool {
return p != strings.TrimSpace(platform)
})
return usererr.New(
"package %s cannot be installed on your system. It may be installable on other systems.",
"package %s cannot be installed on your platform%s. "+
"Consider using `--platform` or `--exclude-platform` with `devbox add` to install on a supported"+
" platform. Other available platforms are: %s.",
input.String(),
platform,
strings.Join(otherPlatforms, ", "),
)
}
}
Expand Down

0 comments on commit d9e54f0

Please sign in to comment.