@@ -450,18 +450,33 @@ 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 := 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 )
465
480
}
466
481
467
482
fmt .Fprintf (d .stderr , "%s: " , stepMsg )
0 commit comments