@@ -1,185 +0,0 @@
1−{ stdenv, fetchFromGitHub, tzdata, iana-etc, go_bootstrap, runCommand, writeScriptBin
2−, perl, which, pkgconfig, patch, procps, pcre, cacert, llvm, Security, Foundation }:
3−
4−let
5−
6− inherit (stdenv.lib) optionals optionalString;
7−
8− clangHack = writeScriptBin "clang" ''
9− #!${stdenv.shell}
10− exec ${stdenv.cc}/bin/clang "$@" 2> >(sed '/ld: warning:.*ignoring unexpected dylib file/ d' 1>&2)
11− '';
12−
13− goBootstrap = runCommand "go-bootstrap" {} ''
14− mkdir $out
15− cp -rf ${go_bootstrap}/* $out/
16− chmod -R u+w $out
17− find $out -name "*.c" -delete
18− cp -rf $out/bin/* $out/share/go/bin/
19− '';
20−
21−in
22−
23−stdenv.mkDerivation rec {
24− name = "go-${version}";
25− version = "1.9.5";
26−
27− src = fetchFromGitHub {
28− owner = "golang";
29− repo = "go";
30− rev = "go${version}";
31− sha256 = "15dx1b71xv7b265gqk9nv02pirggpw7d83apikhrza2qkj64ydd0";
32− };
33−
34− # perl is used for testing go vet
35− nativeBuildInputs = [ perl which pkgconfig patch procps ];
36− buildInputs = [ cacert pcre ]
37− ++ optionals stdenv.isLinux [ stdenv.cc.libc.out ]
38− ++ optionals (stdenv.hostPlatform.libc == "glibc") [ stdenv.cc.libc.static ];
39− propagatedBuildInputs = optionals stdenv.isDarwin [ Security Foundation ];
40−
41− hardeningDisable = [ "all" ];
42−
43− prePatch = ''
44− patchShebangs ./ # replace /bin/bash
45−
46− # This source produces shell script at run time,
47− # and thus it is not corrected by patchShebangs.
48− substituteInPlace misc/cgo/testcarchive/carchive_test.go \
49− --replace '#!/usr/bin/env bash' '#!${stdenv.shell}'
50−
51− # Disabling the 'os/http/net' tests (they want files not available in
52− # chroot builds)
53− rm src/net/{listen,parse}_test.go
54− rm src/syscall/exec_linux_test.go
55−
56− # !!! substituteInPlace does not seems to be effective.
57− # The os test wants to read files in an existing path. Just don't let it be /usr/bin.
58− sed -i 's,/usr/bin,'"`pwd`", src/os/os_test.go
59− sed -i 's,/bin/pwd,'"`type -P pwd`", src/os/os_test.go
60− # Disable the unix socket test
61− sed -i '/TestShutdownUnix/areturn' src/net/net_test.go
62− # Disable the hostname test
63− sed -i '/TestHostname/areturn' src/os/os_test.go
64− # ParseInLocation fails the test
65− sed -i '/TestParseInSydney/areturn' src/time/format_test.go
66− # Remove the api check as it never worked
67− sed -i '/src\/cmd\/api\/run.go/ireturn nil' src/cmd/dist/test.go
68− # Remove the coverage test as we have removed this utility
69− sed -i '/TestCoverageWithCgo/areturn' src/cmd/go/go_test.go
70− # Remove the timezone naming test
71− sed -i '/TestLoadFixed/areturn' src/time/time_test.go
72− # Remove disable setgid test
73− sed -i '/TestRespectSetgidDir/areturn' src/cmd/go/internal/work/build_test.go
74− # Remove cert tests that conflict with NixOS's cert resolution
75− sed -i '/TestEnvVars/areturn' src/crypto/x509/root_unix_test.go
76− # TestWritevError hangs sometimes
77− sed -i '/TestWritevError/areturn' src/net/writev_test.go
78− # TestVariousDeadlines fails sometimes
79− sed -i '/TestVariousDeadlines/areturn' src/net/timeout_test.go
80−
81− sed -i 's,/etc/protocols,${iana-etc}/etc/protocols,' src/net/lookup_unix.go
82− sed -i 's,/etc/services,${iana-etc}/etc/services,' src/net/port_unix.go
83−
84− # Disable cgo lookup tests not works, they depend on resolver
85− rm src/net/cgo_unix_test.go
86−
87− '' + optionalString stdenv.isLinux ''
88− sed -i 's,/usr/share/zoneinfo/,${tzdata}/share/zoneinfo/,' src/time/zoneinfo_unix.go
89− '' + optionalString stdenv.isAarch32 ''
90− sed -i '/TestCurrent/areturn' src/os/user/user_test.go
91− echo '#!${stdenv.shell}' > misc/cgo/testplugin/test.bash
92− '' + optionalString stdenv.isDarwin ''
93− substituteInPlace src/race.bash --replace \
94− "sysctl machdep.cpu.extfeatures | grep -qv EM64T" true
95− sed -i 's,strings.Contains(.*sysctl.*,true {,' src/cmd/dist/util.go
96− sed -i 's,"/etc","'"$TMPDIR"'",' src/os/os_test.go
97− sed -i 's,/_go_os_test,'"$TMPDIR"'/_go_os_test,' src/os/path_test.go
98−
99− sed -i '/TestChdirAndGetwd/areturn' src/os/os_test.go
100− sed -i '/TestCredentialNoSetGroups/areturn' src/os/exec/exec_posix_test.go
101− sed -i '/TestCurrent/areturn' src/os/user/user_test.go
102− sed -i '/TestNohup/areturn' src/os/signal/signal_test.go
103− sed -i '/TestRead0/areturn' src/os/os_test.go
104− sed -i '/TestSystemRoots/areturn' src/crypto/x509/root_darwin_test.go
105−
106− sed -i '/TestGoInstallRebuildsStalePackagesInOtherGOPATH/areturn' src/cmd/go/go_test.go
107− sed -i '/TestBuildDashIInstallsDependencies/areturn' src/cmd/go/go_test.go
108−
109− sed -i '/TestDisasmExtld/areturn' src/cmd/objdump/objdump_test.go
110−
111− sed -i 's/unrecognized/unknown/' src/cmd/link/internal/ld/lib.go
112−
113− touch $TMPDIR/group $TMPDIR/hosts $TMPDIR/passwd
114−
115− sed -i '1 a\exit 0' misc/cgo/errors/test.bash
116− '';
117−
118− patches =
119− [ ./remove-tools-1.9.patch
120− ./ssl-cert-file-1.9.patch
121− ./creds-test-1.9.patch
122− ./remove-test-pie-1.9.patch
123− ./go-1.9-skip-flaky-19608.patch
124− ./go-1.9-skip-flaky-20072.patch
125− ];
126−
127− postPatch = optionalString stdenv.isDarwin ''
128− echo "substitute hardcoded dsymutil with ${llvm}/bin/llvm-dsymutil"
129− substituteInPlace "src/cmd/link/internal/ld/lib.go" --replace dsymutil ${llvm}/bin/llvm-dsymutil
130− '';
131−
132− GOOS = if stdenv.isDarwin then "darwin" else "linux";
133− GOARCH = if stdenv.isDarwin then "amd64"
134− else if stdenv.hostPlatform.system == "i686-linux" then "386"
135− else if stdenv.hostPlatform.system == "x86_64-linux" then "amd64"
136− else if stdenv.isAarch32 then "arm"
137− else if stdenv.isAarch64 then "arm64"
138− else throw "Unsupported system";
139− GOARM = optionalString (stdenv.hostPlatform.system == "armv5tel-linux") "5";
140− GO386 = 387; # from Arch: don't assume sse2 on i686
141− CGO_ENABLED = 1;
142− GOROOT_BOOTSTRAP = "${goBootstrap}/share/go";
143− # Hopefully avoids test timeouts on Hydra
144− GO_TEST_TIMEOUT_SCALE = 3;
145−
146− # The go build actually checks for CC=*/clang and does something different, so we don't
147− # just want the generic `cc` here.
148− CC = if stdenv.isDarwin then "clang" else "cc";
149−
150− configurePhase = ''
151− mkdir -p $out/share/go/bin
152− export GOROOT=$out/share/go
153− export GOBIN=$GOROOT/bin
154− export PATH=$GOBIN:$PATH
155− ulimit -a
156− '';
157−
158− postConfigure = optionalString stdenv.isDarwin ''
159− export PATH=${clangHack}/bin:$PATH
160− '';
161−
162− installPhase = ''
163− cp -r . $GOROOT
164− ( cd $GOROOT/src && ./all.bash )
165− '';
166−
167− preFixup = ''
168− rm -r $out/share/go/pkg/bootstrap
169− ln -s $out/share/go/bin $out/bin
170− '';
171−
172− setupHook = ./setup-hook.sh;
173−
174− disallowedReferences = [ go_bootstrap ];
175−
176− meta = with stdenv.lib; {
177− knownVulnerabilities = [ "CVE-2019-6486" ];
178− branch = "1.9";
179− homepage = http://golang.org/;
180− description = "The Go Programming language";
181− license = licenses.bsd3;
182− maintainers = with maintainers; [ cstrahan orivej ];
183− platforms = platforms.linux ++ platforms.darwin;
184− };
185−}