19 goBootstrap = buildPackages.callPackage ./bootstrap121.nix { };
21 skopeoTest = skopeo.override { buildGoModule = buildGo123Module; };
31 "mips64el" = "mips64le";
33 "powerpc64" = "ppc64";
34 "powerpc64le" = "ppc64le";
35 "riscv64" = "riscv64";
39 }.${platform.parsed.cpu.name} or (throw "Unsupported system: ${platform.parsed.cpu.name}");
41 # We need a target compiler which is still runnable at build time,
42 # to handle the cross-building case where build != host == target
43 targetCC = pkgsBuildTarget.targetPackages.stdenv.cc;
45 isCross = stdenv.buildPlatform != stdenv.targetPlatform;
47 stdenv.mkDerivation (finalAttrs: {
52 url = "https://go.dev/dl/go${finalAttrs.version}.src.tar.gz";
53 hash = "sha256-jWp3MySHVXxq+iQhExtQ+D20rjxXnDvHLmcO4faWhZk=";
58 ++ lib.optionals stdenv.hostPlatform.isLinux [ stdenv.cc.libc.out ]
59 ++ lib.optionals (stdenv.hostPlatform.libc == "glibc") [ stdenv.cc.libc.static ];
61 depsTargetTargetPropagated = lib.optionals stdenv.targetPlatform.isDarwin [ apple-sdk_11 xcbuild ];
63 depsBuildTarget = lib.optional isCross targetCC;
65 depsTargetTarget = lib.optional stdenv.targetPlatform.isWindows threadsCross.package;
73 src = ./iana-etc-1.17.patch;
76 # Patch the mimetype database location which is missing on NixOS.
77 # but also allow static binaries built with NixOS to run outside nix
79 src = ./mailcap-1.17.patch;
82 # prepend the nix path to the zoneinfo files but also leave the original value for static binaries
83 # that run outside a nix server
85 src = ./tzdata-1.19.patch;
88 ./remove-tools-1.11.patch
89 ./go_no_vendor_checks-1.22.patch
92 GOOS = if stdenv.targetPlatform.isWasi then "wasip1" else stdenv.targetPlatform.parsed.kernel.name;
93 GOARCH = goarch stdenv.targetPlatform;
94 # GOHOSTOS/GOHOSTARCH must match the building system, not the host system.
95 # Go will nevertheless build a for host system that we will copy over in
97 GOHOSTOS = stdenv.buildPlatform.parsed.kernel.name;
98 GOHOSTARCH = goarch stdenv.buildPlatform;
100 # {CC,CXX}_FOR_TARGET must be only set for cross compilation case as go expect those
101 # to be different from CC/CXX
104 "${targetCC}/bin/${targetCC.targetPrefix}cc"
109 "${targetCC}/bin/${targetCC.targetPrefix}c++"
113 GOARM = toString (lib.intersectLists [ (stdenv.hostPlatform.parsed.cpu.version or "") ] [ "5" "6" "7" ]);
114 GO386 = "softfloat"; # from Arch: don't assume sse2 on i686
115 # Wasi does not support CGO
116 CGO_ENABLED = if stdenv.targetPlatform.isWasi then 0 else 1;
118 GOROOT_BOOTSTRAP = "${goBootstrap}/share/go";
122 export GOCACHE=$TMPDIR/go-cache
124 export PATH=$(pwd)/bin:$PATH
126 ${lib.optionalString isCross ''
127 # Independent from host/target, CC should produce code for the building system.
128 # We only set it when cross-compiling.
129 export CC=${buildPackages.stdenv.cc}/bin/cc
140 # Contains the wrong perl shebang when cross compiling,
141 # since it is not used for anything we can deleted as well.
142 rm src/regexp/syntax/make_perl_groups.pl
143 '' + (if (stdenv.buildPlatform.system != stdenv.hostPlatform.system) then ''
146 ${lib.optionalString (!(finalAttrs.GOHOSTARCH == finalAttrs.GOARCH && finalAttrs.GOOS == finalAttrs.GOHOSTOS)) ''
147 rm -rf pkg/${finalAttrs.GOHOSTOS}_${finalAttrs.GOHOSTARCH} pkg/tool/${finalAttrs.GOHOSTOS}_${finalAttrs.GOHOSTARCH}
149 '' else lib.optionalString (stdenv.hostPlatform.system != stdenv.targetPlatform.system) ''
151 ${lib.optionalString (!(finalAttrs.GOHOSTARCH == finalAttrs.GOARCH && finalAttrs.GOOS == finalAttrs.GOHOSTOS)) ''
152 rm -rf pkg/${finalAttrs.GOOS}_${finalAttrs.GOARCH} pkg/tool/${finalAttrs.GOOS}_${finalAttrs.GOARCH}
158 mkdir -p $out/share/go
159 cp -a bin pkg src lib misc api doc go.env $out/share/go
161 ln -s $out/share/go/bin/* $out/bin
165 disallowedReferences = [ goBootstrap ];
168 inherit goBootstrap skopeoTest;
170 skopeo = testers.testVersion { package = skopeoTest; };
171 version = testers.testVersion {
172 package = finalAttrs.finalPackage;
173 command = "go version";
174 version = "go${finalAttrs.version}";
180 changelog = "https://go.dev/doc/devel/release#go${lib.versions.majorMinor finalAttrs.version}";
181 description = "Go Programming language";
182 homepage = "https://go.dev/";
183 license = licenses.bsd3;
184 maintainers = teams.golang.members;
185 platforms = platforms.darwin ++ platforms.linux ++ platforms.wasi ++ platforms.freebsd;