Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / compilers / go / binary.nix
blob3b4e8010d27ecf1f8d25611041ec55be7f148bb9
1 { lib, stdenv, fetchurl, version, hashes, autoPatchelfHook }:
2 let
3   toGoKernel = platform:
4     if platform.isDarwin then "darwin"
5     else platform.parsed.kernel.name;
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}");
17   toGoPlatform = platform: "${toGoKernel platform}-${toGoCPU platform}";
19   platform = toGoPlatform stdenv.hostPlatform;
21 stdenv.mkDerivation rec {
22   name = "go-${version}-${platform}-bootstrap";
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   };
29   nativeBuildInputs = lib.optionals stdenv.isLinux [ autoPatchelfHook ];
31   # We must preserve the signature on Darwin
32   dontStrip = stdenv.hostPlatform.isDarwin;
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   '';