@@ -450,18 +450,34 @@ func (d *Devbox) installNixPackagesToStore(ctx context.Context) error {
450
450
fmt .Fprintf (d .stderr , "%s: " , stepMsg )
451
451
color .New (color .FgRed ).Fprintf (d .stderr , "Fail\n " )
452
452
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 :=
461
+ strings .Contains (errMessage , "error: flake output attribute" ) &&
462
+ strings .Contains (errMessage , "is not a derivation or path" )
463
+
464
+ if maybePackageSystemCompatibilityError {
465
+ platform := nix .System ()
466
+ return usererr .WithUserMessage (
467
+ err ,
468
+ "package %s cannot be installed on your platform %s.\n " +
469
+ "If you know this package is incompatible with %[2]s, then " +
470
+ "you could run `devbox add %[1]s --exclude-platform %[2]s` and re-try.\n " +
471
+ "If you think this package should be compatible with %[2]s, then " +
472
+ "it's possible this particular version is not available yet from the nix registry. " +
473
+ "You could try `devbox add` with a different version for this package.\n \n " +
474
+ "Underlying Error from nix is:" ,
475
+ pkg .Raw ,
476
+ platform ,
477
+ )
478
+ }
479
+
480
+ return usererr .WithUserMessage (err , "error installing package %s" , pkg .Raw )
465
481
}
466
482
467
483
fmt .Fprintf (d .stderr , "%s: " , stepMsg )
0 commit comments