Skip to content

Commit 61903ef

Browse files
authored
[per-OS Packages] Suggest --platform/--exclude-platform upon error with installing package that is uninstallable on user's platform (#1364)
## Summary Changes the error message to suggest using `--platform/--exclude-platform` with `devbox add`. I wish we had a way to recommend the platforms that are supported for the exact package being installed, but we don't. The heavy lifting for this was done in #1279. Thanks @mikeland73! ## How was it tested? ``` > devbox add glibcLocales Installing package: glibcLocales. Error: package glibcLocales cannot be installed on your platform x86_64-darwin. Consider using `--platform` or `--exclude-platform` with `devbox add` to install on a supported platform. Other available platforms are: aarch64-darwin, aarch64-linux, i686-linux, x86_64-linux, armv7l-linux. ``` <img width="949" alt="Screenshot 2023-08-10 at 4 20 18 PM" src="https://github.com/jetpack-io/devbox/assets/676452/95ddff88-793b-4c09-9e65-be344d303c2a">
1 parent aaace72 commit 61903ef

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

internal/nix/nix.go

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

198-
// ensureValidPlatform returns an error if the platform is not supported by nix.
198+
// EnsureValidPlatform returns an error if the platform is not supported by nix.
199199
// https://nixos.org/manual/nix/stable/installation/supported-platforms.html
200200
func EnsureValidPlatform(platforms ...string) error {
201201
ensureValid := func(platform string) error {

internal/nix/nixprofile/profile.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,17 @@ func ProfileInstall(args *ProfileInstallArgs) error {
265265
if exists, err := input.ValidateInstallsOnSystem(); err != nil {
266266
return err
267267
} else if !exists {
268+
platform, err := nix.System()
269+
if err != nil {
270+
platform = ""
271+
} else {
272+
platform = " " + platform
273+
}
268274
return usererr.New(
269-
"package %s cannot be installed on your system. It may be installable on other systems.",
270-
input.String(),
275+
"package %s cannot be installed on your platform%s. "+
276+
"Run `devbox add %[1]s --exclude-platform%[2]s` and re-try.",
277+
input.Raw,
278+
platform,
271279
)
272280
}
273281
}

0 commit comments

Comments
 (0)