packageInstallErrorHandler checks for two kinds of errors to print custom messages for so that Devbox users can work around them: 1. Packages that cannot be installed on the current system, but may be installable on other systems.packageInstallErrorHandler 2. Packages marked insecure by nix
(err error, pkg *Package, installableOrEmpty string)
| 792 | // 1. Packages that cannot be installed on the current system, but may be installable on other systems.packageInstallErrorHandler |
| 793 | // 2. Packages marked insecure by nix |
| 794 | func packageInstallErrorHandler(err error, pkg *Package, installableOrEmpty string) error { |
| 795 | if err == nil { |
| 796 | return nil |
| 797 | } |
| 798 | |
| 799 | // Check if the user is installing a package that cannot be installed on their platform. |
| 800 | // For example, glibcLocales on MacOS will give the following error: |
| 801 | // flake output attribute 'legacyPackages.x86_64-darwin.glibcLocales' is not a derivation or path |
| 802 | // This is because glibcLocales is only available on Linux. |
| 803 | // The user should try `devbox add` again with `--exclude-platform` |
| 804 | errMessage := strings.TrimSpace(err.Error()) |
| 805 | |
| 806 | // Sample error from `devbox add glibcLocales` on a mac: |
| 807 | // error: flake output attribute 'legacyPackages.x86_64-darwin.glibcLocales' is not a derivation or path |
| 808 | maybePackageSystemCompatibilityErrorType1 := strings.Contains(errMessage, "error: flake output attribute") && |
| 809 | strings.Contains(errMessage, "is not a derivation or path") |
| 810 | // Sample error from `devbox add sublime4` on a mac: |
| 811 | // error: Package ‘sublimetext4-4169’ in /nix/store/nlbjx0mp83p2qzf1rkmzbgvq1wxfir81-source/pkgs/applications/editors/sublime/4/common.nix:168 is not available on the requested hostPlatform: |
| 812 | // hostPlatform.config = "x86_64-apple-darwin" |
| 813 | // package.meta.platforms = [ |
| 814 | // "aarch64-linux" |
| 815 | // "x86_64-linux" |
| 816 | // ] |
| 817 | maybePackageSystemCompatibilityErrorType2 := strings.Contains(errMessage, "is not available on the requested hostPlatform") |
| 818 | |
| 819 | if maybePackageSystemCompatibilityErrorType1 || maybePackageSystemCompatibilityErrorType2 { |
| 820 | platform := nix.System() |
| 821 | return usererr.WithUserMessage( |
| 822 | err, |
| 823 | "package %s cannot be installed on your platform %s.\n"+ |
| 824 | "If you know this package is incompatible with %[2]s, then "+ |
| 825 | "you could run `devbox add %[1]s --exclude-platform %[2]s` and re-try.\n"+ |
| 826 | "If you think this package should be compatible with %[2]s, then "+ |
| 827 | "it's possible this particular version is not available yet from the nix registry. "+ |
| 828 | "You could try `devbox add` with a different version for this package.\n\n"+ |
| 829 | "Underlying Error from nix is:", |
| 830 | pkg.Versioned(), |
| 831 | platform, |
| 832 | ) |
| 833 | } |
| 834 | |
| 835 | if isInsecureErr, userErr := nix.IsExitErrorInsecurePackage(err, pkg.Versioned(), installableOrEmpty); isInsecureErr { |
| 836 | return userErr |
| 837 | } |
| 838 | |
| 839 | return usererr.WithUserMessage(err, "error installing package %s", pkg.Raw) |
| 840 | } |
| 841 | |
| 842 | func (p *Package) ResolvedVersion() (string, error) { |
| 843 | if err := p.resolve(); err != nil { |
no test coverage detected