21 useGccGoBootstrap = stdenv.buildPlatform.isMusl || stdenv.buildPlatform.isRiscV;
22 goBootstrap = if useGccGoBootstrap then buildPackages.gccgo12 else buildPackages.callPackage ./bootstrap116.nix { };
24 skopeoTest = skopeo.override { buildGoModule = buildGo119Module; };
34 "mips64el" = "mips64le";
36 "powerpc64le" = "ppc64le";
37 "riscv64" = "riscv64";
40 }.${platform.parsed.cpu.name} or (throw "Unsupported system: ${platform.parsed.cpu.name}");
42 # We need a target compiler which is still runnable at build time,
43 # to handle the cross-building case where build != host == target
44 targetCC = pkgsBuildTarget.targetPackages.stdenv.cc;
46 isCross = stdenv.buildPlatform != stdenv.targetPlatform;
48 stdenv.mkDerivation (finalAttrs: {
53 url = "https://go.dev/dl/go${finalAttrs.version}.src.tar.gz";
54 hash = "sha256-zPNrU/sAJKAXNTw92yLB8AvHqAc8aqx5BC2iTuNENNM=";
59 ++ lib.optionals stdenv.isLinux [ stdenv.cc.libc.out ]
60 ++ lib.optionals (stdenv.hostPlatform.libc == "glibc") [ stdenv.cc.libc.static ];
62 depsTargetTargetPropagated = lib.optionals stdenv.targetPlatform.isDarwin [ Foundation Security xcbuild ];
64 depsBuildTarget = lib.optional isCross targetCC;
66 depsTargetTarget = lib.optional stdenv.targetPlatform.isWindows threadsCross.package;
74 src = ./iana-etc-1.17.patch;
77 # Patch the mimetype database location which is missing on NixOS.
78 # but also allow static binaries built with NixOS to run outside nix
80 src = ./mailcap-1.17.patch;
83 # prepend the nix path to the zoneinfo files but also leave the original value for static binaries
84 # that run outside a nix server
86 src = ./tzdata-1.19.patch;
89 ./remove-tools-1.11.patch
90 ./go_no_vendor_checks-1.16.patch
92 # runtime: support riscv64 SV57 mode
94 url = "https://github.com/golang/go/commit/1e3c19f3fee12e5e2b7802a54908a4d4d03960da.patch";
95 sha256 = "sha256-mk/9gXwQEcAkiRemF6GiNU0c0fhDR29/YcKgQR7ONTA=";
99 GOOS = stdenv.targetPlatform.parsed.kernel.name;
100 GOARCH = goarch stdenv.targetPlatform;
101 # GOHOSTOS/GOHOSTARCH must match the building system, not the host system.
102 # Go will nevertheless build a for host system that we will copy over in
104 GOHOSTOS = stdenv.buildPlatform.parsed.kernel.name;
105 GOHOSTARCH = goarch stdenv.buildPlatform;
107 # {CC,CXX}_FOR_TARGET must be only set for cross compilation case as go expect those
108 # to be different from CC/CXX
111 "${targetCC}/bin/${targetCC.targetPrefix}cc"
116 "${targetCC}/bin/${targetCC.targetPrefix}c++"
120 GOARM = toString (lib.intersectLists [ (stdenv.hostPlatform.parsed.cpu.version or "") ] [ "5" "6" "7" ]);
121 GO386 = "softfloat"; # from Arch: don't assume sse2 on i686
124 GOROOT_BOOTSTRAP = if useGccGoBootstrap then goBootstrap else "${goBootstrap}/share/go";
128 export GOCACHE=$TMPDIR/go-cache
129 # this is compiled into the binary
130 export GOROOT_FINAL=$out/share/go
132 export PATH=$(pwd)/bin:$PATH
134 ${lib.optionalString isCross ''
135 # Independent from host/target, CC should produce code for the building system.
136 # We only set it when cross-compiling.
137 export CC=${buildPackages.stdenv.cc}/bin/cc
149 # Contains the wrong perl shebang when cross compiling,
150 # since it is not used for anything we can deleted as well.
151 rm src/regexp/syntax/make_perl_groups.pl
152 '' + (if (stdenv.buildPlatform.system != stdenv.hostPlatform.system) then ''
155 ${lib.optionalString (!(finalAttrs.GOHOSTARCH == finalAttrs.GOARCH && finalAttrs.GOOS == finalAttrs.GOHOSTOS)) ''
156 rm -rf pkg/${finalAttrs.GOHOSTOS}_${finalAttrs.GOHOSTARCH} pkg/tool/${finalAttrs.GOHOSTOS}_${finalAttrs.GOHOSTARCH}
158 '' else lib.optionalString (stdenv.hostPlatform.system != stdenv.targetPlatform.system) ''
160 ${lib.optionalString (!(finalAttrs.GOHOSTARCH == finalAttrs.GOARCH && finalAttrs.GOOS == finalAttrs.GOHOSTOS)) ''
161 rm -rf pkg/${finalAttrs.GOOS}_${finalAttrs.GOARCH} pkg/tool/${finalAttrs.GOOS}_${finalAttrs.GOARCH}
167 mkdir -p $GOROOT_FINAL
168 cp -a bin pkg src lib misc api doc $GOROOT_FINAL
170 ln -s $GOROOT_FINAL/bin/* $out/bin
174 disallowedReferences = [ goBootstrap ];
177 inherit goBootstrap skopeoTest;
179 skopeo = testers.testVersion { package = skopeoTest; };
180 version = testers.testVersion {
181 package = finalAttrs.finalPackage;
182 command = "go version";
183 version = "go${finalAttrs.version}";
189 changelog = "https://go.dev/doc/devel/release#go${lib.versions.majorMinor finalAttrs.version}";
190 description = "The Go Programming language";
191 homepage = "https://go.dev/";
192 license = licenses.bsd3;
193 maintainers = teams.golang.members;
194 platforms = platforms.darwin ++ platforms.linux;