|
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + fetchurl, |
| 5 | + apple-sdk_12, |
| 6 | + tzdata, |
| 7 | + replaceVars, |
| 8 | + iana-etc, |
| 9 | + mailcap, |
| 10 | + buildPackages, |
| 11 | + pkgsBuildTarget, |
| 12 | + targetPackages, |
| 13 | + testers, |
| 14 | + skopeo, |
| 15 | + buildGo125Module, |
| 16 | +}: |
| 17 | + |
| 18 | +let |
| 19 | + goBootstrap = buildPackages.callPackage ./bootstrap122.nix { }; |
| 20 | + |
| 21 | + skopeoTest = skopeo.override { buildGoModule = buildGo125Module; }; |
| 22 | + |
| 23 | + # We need a target compiler which is still runnable at build time, |
| 24 | + # to handle the cross-building case where build != host == target |
| 25 | + targetCC = pkgsBuildTarget.targetPackages.stdenv.cc; |
| 26 | + |
| 27 | + isCross = stdenv.buildPlatform != stdenv.targetPlatform; |
| 28 | +in |
| 29 | +stdenv.mkDerivation (finalAttrs: { |
| 30 | + pname = "go"; |
| 31 | + version = "1.25rc2"; |
| 32 | + |
| 33 | + src = fetchurl { |
| 34 | + url = "https://go.dev/dl/go${finalAttrs.version}.src.tar.gz"; |
| 35 | + hash = "sha256-5jFKMjTEwDuNAGvNHRRZTZKBcNGES23/3V+lojM0SeE="; |
| 36 | + }; |
| 37 | + |
| 38 | + strictDeps = true; |
| 39 | + buildInputs = |
| 40 | + [ ] |
| 41 | + ++ lib.optionals stdenv.hostPlatform.isLinux [ stdenv.cc.libc.out ] |
| 42 | + ++ lib.optionals (stdenv.hostPlatform.libc == "glibc") [ stdenv.cc.libc.static ]; |
| 43 | + |
| 44 | + depsTargetTargetPropagated = lib.optionals stdenv.targetPlatform.isDarwin [ |
| 45 | + apple-sdk_12 |
| 46 | + ]; |
| 47 | + |
| 48 | + depsBuildTarget = lib.optional isCross targetCC; |
| 49 | + |
| 50 | + depsTargetTarget = lib.optional stdenv.targetPlatform.isWindows targetPackages.threads.package; |
| 51 | + |
| 52 | + postPatch = '' |
| 53 | + patchShebangs . |
| 54 | + ''; |
| 55 | + |
| 56 | + patches = [ |
| 57 | + (replaceVars ./iana-etc-1.25.patch { |
| 58 | + iana = iana-etc; |
| 59 | + }) |
| 60 | + # Patch the mimetype database location which is missing on NixOS. |
| 61 | + # but also allow static binaries built with NixOS to run outside nix |
| 62 | + (replaceVars ./mailcap-1.17.patch { |
| 63 | + inherit mailcap; |
| 64 | + }) |
| 65 | + # prepend the nix path to the zoneinfo files but also leave the original value for static binaries |
| 66 | + # that run outside a nix server |
| 67 | + (replaceVars ./tzdata-1.19.patch { |
| 68 | + inherit tzdata; |
| 69 | + }) |
| 70 | + ./remove-tools-1.11.patch |
| 71 | + ./go_no_vendor_checks-1.23.patch |
| 72 | + ]; |
| 73 | + |
| 74 | + inherit (stdenv.targetPlatform.go) GOOS GOARCH GOARM; |
| 75 | + # GOHOSTOS/GOHOSTARCH must match the building system, not the host system. |
| 76 | + # Go will nevertheless build a for host system that we will copy over in |
| 77 | + # the install phase. |
| 78 | + GOHOSTOS = stdenv.buildPlatform.go.GOOS; |
| 79 | + GOHOSTARCH = stdenv.buildPlatform.go.GOARCH; |
| 80 | + |
| 81 | + # {CC,CXX}_FOR_TARGET must be only set for cross compilation case as go expect those |
| 82 | + # to be different from CC/CXX |
| 83 | + CC_FOR_TARGET = if isCross then "${targetCC}/bin/${targetCC.targetPrefix}cc" else null; |
| 84 | + CXX_FOR_TARGET = if isCross then "${targetCC}/bin/${targetCC.targetPrefix}c++" else null; |
| 85 | + |
| 86 | + GO386 = "softfloat"; # from Arch: don't assume sse2 on i686 |
| 87 | + # Wasi does not support CGO |
| 88 | + CGO_ENABLED = if stdenv.targetPlatform.isWasi then 0 else 1; |
| 89 | + |
| 90 | + GOROOT_BOOTSTRAP = "${goBootstrap}/share/go"; |
| 91 | + |
| 92 | + buildPhase = '' |
| 93 | + runHook preBuild |
| 94 | + export GOCACHE=$TMPDIR/go-cache |
| 95 | +
|
| 96 | + export PATH=$(pwd)/bin:$PATH |
| 97 | +
|
| 98 | + ${lib.optionalString isCross '' |
| 99 | + # Independent from host/target, CC should produce code for the building system. |
| 100 | + # We only set it when cross-compiling. |
| 101 | + export CC=${buildPackages.stdenv.cc}/bin/cc |
| 102 | + ''} |
| 103 | + ulimit -a |
| 104 | +
|
| 105 | + pushd src |
| 106 | + ./make.bash |
| 107 | + popd |
| 108 | + runHook postBuild |
| 109 | + ''; |
| 110 | + |
| 111 | + preInstall = |
| 112 | + '' |
| 113 | + # Contains the wrong perl shebang when cross compiling, |
| 114 | + # since it is not used for anything we can deleted as well. |
| 115 | + rm src/regexp/syntax/make_perl_groups.pl |
| 116 | + '' |
| 117 | + + ( |
| 118 | + if (stdenv.buildPlatform.system != stdenv.hostPlatform.system) then |
| 119 | + '' |
| 120 | + mv bin/*_*/* bin |
| 121 | + rmdir bin/*_* |
| 122 | + ${lib.optionalString |
| 123 | + (!(finalAttrs.GOHOSTARCH == finalAttrs.GOARCH && finalAttrs.GOOS == finalAttrs.GOHOSTOS)) |
| 124 | + '' |
| 125 | + rm -rf pkg/${finalAttrs.GOHOSTOS}_${finalAttrs.GOHOSTARCH} pkg/tool/${finalAttrs.GOHOSTOS}_${finalAttrs.GOHOSTARCH} |
| 126 | + '' |
| 127 | + } |
| 128 | + '' |
| 129 | + else |
| 130 | + lib.optionalString (stdenv.hostPlatform.system != stdenv.targetPlatform.system) '' |
| 131 | + rm -rf bin/*_* |
| 132 | + ${lib.optionalString |
| 133 | + (!(finalAttrs.GOHOSTARCH == finalAttrs.GOARCH && finalAttrs.GOOS == finalAttrs.GOHOSTOS)) |
| 134 | + '' |
| 135 | + rm -rf pkg/${finalAttrs.GOOS}_${finalAttrs.GOARCH} pkg/tool/${finalAttrs.GOOS}_${finalAttrs.GOARCH} |
| 136 | + '' |
| 137 | + } |
| 138 | + '' |
| 139 | + ); |
| 140 | + |
| 141 | + installPhase = '' |
| 142 | + runHook preInstall |
| 143 | + mkdir -p $out/share/go |
| 144 | + cp -a bin pkg src lib misc api doc go.env VERSION $out/share/go |
| 145 | + mkdir -p $out/bin |
| 146 | + ln -s $out/share/go/bin/* $out/bin |
| 147 | + runHook postInstall |
| 148 | + ''; |
| 149 | + |
| 150 | + disallowedReferences = [ goBootstrap ]; |
| 151 | + |
| 152 | + passthru = { |
| 153 | + inherit goBootstrap skopeoTest; |
| 154 | + tests = { |
| 155 | + skopeo = testers.testVersion { package = skopeoTest; }; |
| 156 | + version = testers.testVersion { |
| 157 | + package = finalAttrs.finalPackage; |
| 158 | + command = "go version"; |
| 159 | + version = "go${finalAttrs.version}"; |
| 160 | + }; |
| 161 | + }; |
| 162 | + }; |
| 163 | + |
| 164 | + meta = with lib; { |
| 165 | + changelog = "https://go.dev/doc/devel/release#go${lib.versions.majorMinor finalAttrs.version}"; |
| 166 | + description = "Go Programming language"; |
| 167 | + homepage = "https://go.dev/"; |
| 168 | + license = licenses.bsd3; |
| 169 | + teams = [ teams.golang ]; |
| 170 | + platforms = platforms.darwin ++ platforms.linux ++ platforms.wasi ++ platforms.freebsd; |
| 171 | + mainProgram = "go"; |
| 172 | + }; |
| 173 | +}) |
0 commit comments