at 23.05-pre 1.2 kB view raw
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 }.${platform.parsed.cpu.name} or (throw "Unsupported CPU ${platform.parsed.cpu.name}"); 15 16 toGoPlatform = platform: "${toGoKernel platform}-${toGoCPU platform}"; 17 18 platform = toGoPlatform stdenv.hostPlatform; 19in 20stdenv.mkDerivation rec { 21 name = "go-${version}-${platform}-bootstrap"; 22 23 src = fetchurl { 24 url = "https://go.dev/dl/go${version}.${platform}.tar.gz"; 25 sha256 = hashes.${platform} or (throw "Missing Go bootstrap hash for platform ${platform}"); 26 }; 27 28 nativeBuildInputs = lib.optionals stdenv.isLinux [ autoPatchelfHook ]; 29 30 # We must preserve the signature on Darwin 31 dontStrip = stdenv.hostPlatform.isDarwin; 32 33 installPhase = '' 34 runHook preInstall 35 mkdir -p $out/share/go $out/bin 36 cp -r . $out/share/go 37 ln -s $out/share/go/bin/go $out/bin/go 38 runHook postInstall 39 ''; 40}