1{ lib, stdenv, fetchurl, version, hashes, autoPatchelfHook }:
2let
3 toGoKernel = platform:
4 if platform.isDarwin then "darwin"
5 else platform.parsed.kernel.name;
6
7 toGoCPU = platform: {
8 "i686" = "386";
9 "x86_64" = "amd64";
10 "aarch64" = "arm64";
11 "armv6l" = "armv6l";
12 "armv7l" = "armv6l";
13 "powerpc64le" = "ppc64le";
14 "riscv64" = "riscv64";
15 }.${platform.parsed.cpu.name} or (throw "Unsupported CPU ${platform.parsed.cpu.name}");
16
17 toGoPlatform = platform: "${toGoKernel platform}-${toGoCPU platform}";
18
19 platform = toGoPlatform stdenv.hostPlatform;
20in
21stdenv.mkDerivation rec {
22 name = "go-${version}-${platform}-bootstrap";
23
24 src = fetchurl {
25 url = "https://go.dev/dl/go${version}.${platform}.tar.gz";
26 sha256 = hashes.${platform} or (throw "Missing Go bootstrap hash for platform ${platform}");
27 };
28
29 nativeBuildInputs = lib.optionals stdenv.isLinux [ autoPatchelfHook ];
30
31 # We must preserve the signature on Darwin
32 dontStrip = stdenv.hostPlatform.isDarwin;
33
34 installPhase = ''
35 runHook preInstall
36 mkdir -p $out/share/go $out/bin
37 cp -r . $out/share/go
38 ln -s $out/share/go/bin/go $out/bin/go
39 runHook postInstall
40 '';
41}