Skip to content

Commit 1f0aead

Browse files
committed
improve error handling for exclude-platform scenario
1 parent b0dd286 commit 1f0aead

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

internal/devbox/packages.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -450,18 +450,33 @@ func (d *Devbox) installNixPackagesToStore(ctx context.Context) error {
450450
fmt.Fprintf(d.stderr, "%s: ", stepMsg)
451451
color.New(color.FgRed).Fprintf(d.stderr, "Fail\n")
452452

453-
platform := nix.System()
454-
return usererr.WithUserMessage(
455-
err,
456-
"package %s cannot be installed on your platform %s.\n"+
457-
"If you know this package is incompatible with %[2]s, then "+
458-
"you could run `devbox add %[1]s --exclude-platform %[2]s` and re-try.\n"+
459-
"If you think this package should be compatible with %[2]s, then "+
460-
"it's possible this particular version is not available yet from the nix registry. "+
461-
"You could try `devbox add` with a different version for this package.\n",
462-
pkg.Raw,
463-
platform,
464-
)
453+
// Check if the user is installing a package that cannot be installed on their platform.
454+
// For example, glibcLocales on MacOS will give the following error:
455+
// flake output attribute 'legacyPackages.x86_64-darwin.glibcLocales' is not a derivation or path
456+
// This is because glibcLocales is only available on Linux.
457+
// The user should try `devbox add` again with `--exclude-platform`
458+
errMessage := strings.TrimSpace(err.Error())
459+
fmt.Printf("errMessage is %s\n", errMessage)
460+
maybePackageSystemCompatibilityError := strings.Contains(errMessage, "error: flake output attribute") &&
461+
strings.Contains(errMessage, "is not a derivation or path")
462+
463+
if maybePackageSystemCompatibilityError {
464+
platform := nix.System()
465+
return usererr.WithUserMessage(
466+
err,
467+
"package %s cannot be installed on your platform %s.\n"+
468+
"If you know this package is incompatible with %[2]s, then "+
469+
"you could run `devbox add %[1]s --exclude-platform %[2]s` and re-try.\n"+
470+
"If you think this package should be compatible with %[2]s, then "+
471+
"it's possible this particular version is not available yet from the nix registry. "+
472+
"You could try `devbox add` with a different version for this package.\n\n"+
473+
"Underlying Error from nix is:",
474+
pkg.Raw,
475+
platform,
476+
)
477+
}
478+
479+
return usererr.WithUserMessage(err, "error installing package %s", pkg.Raw)
465480
}
466481

467482
fmt.Fprintf(d.stderr, "%s: ", stepMsg)

0 commit comments

Comments
 (0)