Skip to content

Commit 1800f1f

Browse files
committed
[Config Packages] Suggest --platform/--exclude-platform upon error with installing package that is uninstallable on user's platform
1 parent aaace72 commit 1800f1f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

internal/nix/nix.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ var nixPlatforms = []string{
195195
"armv7l-linux",
196196
}
197197

198-
// ensureValidPlatform returns an error if the platform is not supported by nix.
198+
func SupportedPlatforms() []string {
199+
return nixPlatforms
200+
}
201+
202+
// EnsureValidPlatform returns an error if the platform is not supported by nix.
199203
// https://nixos.org/manual/nix/stable/installation/supported-platforms.html
200204
func EnsureValidPlatform(platforms ...string) error {
201205
ensureValid := func(platform string) error {

internal/nix/nixprofile/profile.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/fatih/color"
1515
"github.com/pkg/errors"
16+
"github.com/samber/lo"
1617
"go.jetpack.io/devbox/internal/boxcli/usererr"
1718
"go.jetpack.io/devbox/internal/devpkg"
1819
"go.jetpack.io/devbox/internal/lock"
@@ -265,9 +266,22 @@ func ProfileInstall(args *ProfileInstallArgs) error {
265266
if exists, err := input.ValidateInstallsOnSystem(); err != nil {
266267
return err
267268
} else if !exists {
269+
platform, err := nix.System()
270+
if err != nil {
271+
platform = ""
272+
} else {
273+
platform = " " + platform
274+
}
275+
otherPlatforms := lo.Filter(nix.SupportedPlatforms(), func(p string, _ int) bool {
276+
return p != strings.TrimSpace(platform)
277+
})
268278
return usererr.New(
269-
"package %s cannot be installed on your system. It may be installable on other systems.",
279+
"package %s cannot be installed on your platform%s. "+
280+
"Consider using `--platform` or `--exclude-platform` with `devbox add` to install on a supported"+
281+
" platform. Other available platforms are: %s.",
270282
input.String(),
283+
platform,
284+
strings.Join(otherPlatforms, ", "),
271285
)
272286
}
273287
}

0 commit comments

Comments
 (0)