2021-06-06 07:54:09 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchurl
|
|
|
|
, tzdata
|
2022-09-09 14:08:57 +00:00
|
|
|
, substituteAll
|
2021-06-06 07:54:09 +00:00
|
|
|
, iana-etc
|
|
|
|
, Security
|
|
|
|
, Foundation
|
2022-02-10 20:34:41 +00:00
|
|
|
, xcbuild
|
2021-06-06 07:54:09 +00:00
|
|
|
, mailcap
|
2020-10-07 09:15:18 +00:00
|
|
|
, buildPackages
|
|
|
|
, pkgsBuildTarget
|
2022-08-12 12:06:08 +00:00
|
|
|
, threadsCross
|
2022-09-09 14:08:57 +00:00
|
|
|
, testers
|
|
|
|
, skopeo
|
|
|
|
, buildGo118Module
|
2020-07-18 16:06:22 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2022-09-09 14:08:57 +00:00
|
|
|
goBootstrap = buildPackages.callPackage ./bootstrap116.nix { };
|
2021-02-16 17:04:54 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
skopeoTest = skopeo.override { buildGoModule = buildGo118Module; };
|
2020-07-18 16:06:22 +00:00
|
|
|
|
|
|
|
goarch = platform: {
|
|
|
|
"aarch64" = "arm64";
|
|
|
|
"arm" = "arm";
|
|
|
|
"armv5tel" = "arm";
|
|
|
|
"armv6l" = "arm";
|
|
|
|
"armv7l" = "arm";
|
2022-08-12 12:06:08 +00:00
|
|
|
"i686" = "386";
|
2021-07-21 07:28:18 +00:00
|
|
|
"mips" = "mips";
|
2022-08-12 12:06:08 +00:00
|
|
|
"mips64el" = "mips64le";
|
2022-02-10 20:34:41 +00:00
|
|
|
"mipsel" = "mipsle";
|
2022-08-12 12:06:08 +00:00
|
|
|
"powerpc64le" = "ppc64le";
|
2022-02-10 20:34:41 +00:00
|
|
|
"riscv64" = "riscv64";
|
|
|
|
"s390x" = "s390x";
|
2022-08-12 12:06:08 +00:00
|
|
|
"x86_64" = "amd64";
|
2022-03-30 09:31:56 +00:00
|
|
|
}.${platform.parsed.cpu.name} or (throw "Unsupported system: ${platform.parsed.cpu.name}");
|
2020-07-18 16:06:22 +00:00
|
|
|
|
2020-10-07 09:15:18 +00:00
|
|
|
# We need a target compiler which is still runnable at build time,
|
|
|
|
# to handle the cross-building case where build != host == target
|
|
|
|
targetCC = pkgsBuildTarget.targetPackages.stdenv.cc;
|
2022-05-18 14:49:53 +00:00
|
|
|
|
|
|
|
isCross = stdenv.buildPlatform != stdenv.targetPlatform;
|
2020-07-18 16:06:22 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "go";
|
2022-12-17 10:02:37 +00:00
|
|
|
version = "1.18.9";
|
2020-07-18 16:06:22 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
2022-02-10 20:34:41 +00:00
|
|
|
url = "https://go.dev/dl/go${version}.src.tar.gz";
|
2022-12-17 10:02:37 +00:00
|
|
|
sha256 = "sha256-++fwm5aso9tvrq8YDai7Yyho7ASXMeNV/2FpUZfA4+o=";
|
2020-07-18 16:06:22 +00:00
|
|
|
};
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
strictDeps = true;
|
2022-09-09 14:08:57 +00:00
|
|
|
buildInputs = [ ]
|
2021-06-06 07:54:09 +00:00
|
|
|
++ lib.optionals stdenv.isLinux [ stdenv.cc.libc.out ]
|
|
|
|
++ lib.optionals (stdenv.hostPlatform.libc == "glibc") [ stdenv.cc.libc.static ];
|
2020-07-18 16:06:22 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
depsTargetTargetPropagated = lib.optionals stdenv.isDarwin [ Foundation Security xcbuild ];
|
2020-07-18 16:06:22 +00:00
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
depsBuildTarget = lib.optional isCross targetCC;
|
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
depsTargetTarget = lib.optional stdenv.targetPlatform.isWindows threadsCross.package;
|
2022-05-18 14:49:53 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
postPatch = ''
|
|
|
|
patchShebangs .
|
|
|
|
'';
|
2020-07-18 16:06:22 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
patches = [
|
|
|
|
(substituteAll {
|
|
|
|
src = ./iana-etc-1.17.patch;
|
|
|
|
iana = iana-etc;
|
|
|
|
})
|
2020-07-18 16:06:22 +00:00
|
|
|
# Patch the mimetype database location which is missing on NixOS.
|
|
|
|
# but also allow static binaries built with NixOS to run outside nix
|
2022-09-09 14:08:57 +00:00
|
|
|
(substituteAll {
|
|
|
|
src = ./mailcap-1.17.patch;
|
|
|
|
inherit mailcap;
|
|
|
|
})
|
2020-07-18 16:06:22 +00:00
|
|
|
# prepend the nix path to the zoneinfo files but also leave the original value for static binaries
|
|
|
|
# that run outside a nix server
|
2022-09-09 14:08:57 +00:00
|
|
|
(substituteAll {
|
|
|
|
src = ./tzdata-1.17.patch;
|
|
|
|
inherit tzdata;
|
|
|
|
})
|
2020-07-18 16:06:22 +00:00
|
|
|
./remove-tools-1.11.patch
|
2022-02-10 20:34:41 +00:00
|
|
|
./go_no_vendor_checks-1.16.patch
|
2020-07-18 16:06:22 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
GOOS = stdenv.targetPlatform.parsed.kernel.name;
|
|
|
|
GOARCH = goarch stdenv.targetPlatform;
|
|
|
|
# GOHOSTOS/GOHOSTARCH must match the building system, not the host system.
|
|
|
|
# Go will nevertheless build a for host system that we will copy over in
|
|
|
|
# the install phase.
|
|
|
|
GOHOSTOS = stdenv.buildPlatform.parsed.kernel.name;
|
|
|
|
GOHOSTARCH = goarch stdenv.buildPlatform;
|
|
|
|
|
|
|
|
# {CC,CXX}_FOR_TARGET must be only set for cross compilation case as go expect those
|
|
|
|
# to be different from CC/CXX
|
2021-06-06 07:54:09 +00:00
|
|
|
CC_FOR_TARGET =
|
2022-05-18 14:49:53 +00:00
|
|
|
if isCross then
|
2020-10-07 09:15:18 +00:00
|
|
|
"${targetCC}/bin/${targetCC.targetPrefix}cc"
|
2020-07-18 16:06:22 +00:00
|
|
|
else
|
|
|
|
null;
|
2021-06-06 07:54:09 +00:00
|
|
|
CXX_FOR_TARGET =
|
2022-05-18 14:49:53 +00:00
|
|
|
if isCross then
|
2020-10-07 09:15:18 +00:00
|
|
|
"${targetCC}/bin/${targetCC.targetPrefix}c++"
|
2020-07-18 16:06:22 +00:00
|
|
|
else
|
|
|
|
null;
|
|
|
|
|
2021-06-06 07:54:09 +00:00
|
|
|
GOARM = toString (lib.intersectLists [ (stdenv.hostPlatform.parsed.cpu.version or "") ] [ "5" "6" "7" ]);
|
2022-02-10 20:34:41 +00:00
|
|
|
GO386 = "softfloat"; # from Arch: don't assume sse2 on i686
|
2020-07-18 16:06:22 +00:00
|
|
|
CGO_ENABLED = 1;
|
|
|
|
|
2021-06-06 07:54:09 +00:00
|
|
|
GOROOT_BOOTSTRAP = "${goBootstrap}/share/go";
|
2020-07-18 16:06:22 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
2020-07-18 16:06:22 +00:00
|
|
|
export GOCACHE=$TMPDIR/go-cache
|
|
|
|
# this is compiled into the binary
|
|
|
|
export GOROOT_FINAL=$out/share/go
|
|
|
|
|
|
|
|
export PATH=$(pwd)/bin:$PATH
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
${lib.optionalString isCross ''
|
2020-07-18 16:06:22 +00:00
|
|
|
# Independent from host/target, CC should produce code for the building system.
|
|
|
|
# We only set it when cross-compiling.
|
|
|
|
export CC=${buildPackages.stdenv.cc}/bin/cc
|
|
|
|
''}
|
|
|
|
ulimit -a
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
pushd src
|
|
|
|
./make.bash
|
|
|
|
popd
|
|
|
|
runHook postBuild
|
2020-07-18 16:06:22 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
preInstall = ''
|
|
|
|
rm -r pkg/obj
|
|
|
|
# Contains the wrong perl shebang when cross compiling,
|
|
|
|
# since it is not used for anything we can deleted as well.
|
|
|
|
rm src/regexp/syntax/make_perl_groups.pl
|
|
|
|
'' + (if (stdenv.buildPlatform != stdenv.hostPlatform) then ''
|
|
|
|
mv bin/*_*/* bin
|
|
|
|
rmdir bin/*_*
|
2021-06-06 07:54:09 +00:00
|
|
|
${lib.optionalString (!(GOHOSTARCH == GOARCH && GOOS == GOHOSTOS)) ''
|
2020-07-18 16:06:22 +00:00
|
|
|
rm -rf pkg/${GOHOSTOS}_${GOHOSTARCH} pkg/tool/${GOHOSTOS}_${GOHOSTARCH}
|
|
|
|
''}
|
|
|
|
'' else if (stdenv.hostPlatform != stdenv.targetPlatform) then ''
|
|
|
|
rm -rf bin/*_*
|
2021-06-06 07:54:09 +00:00
|
|
|
${lib.optionalString (!(GOHOSTARCH == GOARCH && GOOS == GOHOSTOS)) ''
|
2020-07-18 16:06:22 +00:00
|
|
|
rm -rf pkg/${GOOS}_${GOARCH} pkg/tool/${GOOS}_${GOARCH}
|
|
|
|
''}
|
|
|
|
'' else "");
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir -p $GOROOT_FINAL
|
|
|
|
cp -a bin pkg src lib misc api doc $GOROOT_FINAL
|
|
|
|
ln -s $GOROOT_FINAL/bin $out/bin
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
disallowedReferences = [ goBootstrap ];
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
passthru = {
|
|
|
|
inherit goBootstrap skopeoTest;
|
|
|
|
tests = {
|
|
|
|
skopeo = testers.testVersion { package = skopeoTest; };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-07-18 16:06:22 +00:00
|
|
|
description = "The Go Programming language";
|
2022-08-12 12:06:08 +00:00
|
|
|
homepage = "https://go.dev/";
|
2020-07-18 16:06:22 +00:00
|
|
|
license = licenses.bsd3;
|
|
|
|
maintainers = teams.golang.members;
|
2022-08-12 12:06:08 +00:00
|
|
|
platforms = platforms.darwin ++ platforms.linux;
|
2020-07-18 16:06:22 +00:00
|
|
|
};
|
|
|
|
}
|