@@ -1,232 +0,0 @@
1−{ stdenv, fetchurl, tzdata, iana-etc, runCommand
2−, perl, which, pkgconfig, patch, procps, pcre, cacert, Security, Foundation
3−, mailcap, runtimeShell
4−, buildPackages, pkgsTargetTarget
5−}:
6−
7−let
8−
9− inherit (stdenv.lib) optionals optionalString;
10−
11− goBootstrap = runCommand "go-bootstrap" {} ''
12− mkdir $out
13− cp -rf ${buildPackages.go_bootstrap}/* $out/
14− chmod -R u+w $out
15− find $out -name "*.c" -delete
16− cp -rf $out/bin/* $out/share/go/bin/
17− '';
18−
19− goarch = platform: {
20− i686 = "386";
21− x86_64 = "amd64";
22− aarch64 = "arm64";
23− arm = "arm";
24− armv5tel = "arm";
25− armv6l = "arm";
26− armv7l = "arm";
27− }.${platform.parsed.cpu.name} or (throw "Unsupported system");
28−
29−in
30−
31−stdenv.mkDerivation rec {
32− pname = "go";
33− version = "1.11.13";
34−
35− src = fetchurl {
36− url = "https://dl.google.com/go/go${version}.src.tar.gz";
37− sha256 = "0xj0pbviikdf8g0sfz5hwxf7hwz8b8g5akqnrvyclhgnsdghjcjh";
38− };
39−
40− # perl is used for testing go vet
41− nativeBuildInputs = [ perl which pkgconfig patch procps ];
42− buildInputs = [ cacert pcre ]
43− ++ optionals stdenv.isLinux [ stdenv.cc.libc.out ]
44− ++ optionals (stdenv.hostPlatform.libc == "glibc") [ stdenv.cc.libc.static ];
45−
46−
47− propagatedBuildInputs = optionals stdenv.isDarwin [ Security Foundation ];
48−
49− hardeningDisable = [ "all" ];
50−
51− prePatch = ''
52− patchShebangs ./ # replace /bin/bash
53−
54− # This source produces shell script at run time,
55− # and thus it is not corrected by patchShebangs.
56− substituteInPlace misc/cgo/testcarchive/carchive_test.go \
57− --replace '#!/usr/bin/env bash' '#!${runtimeShell}'
58−
59− # Patch the mimetype database location which is missing on NixOS.
60− substituteInPlace src/mime/type_unix.go \
61− --replace '/etc/mime.types' '${mailcap}/etc/mime.types'
62−
63− # Disabling the 'os/http/net' tests (they want files not available in
64− # chroot builds)
65− rm src/net/{listen,parse}_test.go
66− rm src/syscall/exec_linux_test.go
67−
68− # !!! substituteInPlace does not seems to be effective.
69− # The os test wants to read files in an existing path. Just don't let it be /usr/bin.
70− sed -i 's,/usr/bin,'"`pwd`", src/os/os_test.go
71− sed -i 's,/bin/pwd,'"`type -P pwd`", src/os/os_test.go
72− # Disable the unix socket test
73− sed -i '/TestShutdownUnix/areturn' src/net/net_test.go
74− # Disable the hostname test
75− sed -i '/TestHostname/areturn' src/os/os_test.go
76− # ParseInLocation fails the test
77− sed -i '/TestParseInSydney/areturn' src/time/format_test.go
78− # Remove the api check as it never worked
79− sed -i '/src\/cmd\/api\/run.go/ireturn nil' src/cmd/dist/test.go
80− # Remove the coverage test as we have removed this utility
81− sed -i '/TestCoverageWithCgo/areturn' src/cmd/go/go_test.go
82− # Remove the timezone naming test
83− sed -i '/TestLoadFixed/areturn' src/time/time_test.go
84− # Remove disable setgid test
85− sed -i '/TestRespectSetgidDir/areturn' src/cmd/go/internal/work/build_test.go
86− # Remove cert tests that conflict with NixOS's cert resolution
87− sed -i '/TestEnvVars/areturn' src/crypto/x509/root_unix_test.go
88− # TestWritevError hangs sometimes
89− sed -i '/TestWritevError/areturn' src/net/writev_test.go
90− # TestVariousDeadlines fails sometimes
91− sed -i '/TestVariousDeadlines/areturn' src/net/timeout_test.go
92−
93− sed -i 's,/etc/protocols,${iana-etc}/etc/protocols,' src/net/lookup_unix.go
94− sed -i 's,/etc/services,${iana-etc}/etc/services,' src/net/port_unix.go
95−
96− # Disable cgo lookup tests not works, they depend on resolver
97− rm src/net/cgo_unix_test.go
98−
99− '' + optionalString stdenv.isLinux ''
100− sed -i 's,/usr/share/zoneinfo/,${tzdata}/share/zoneinfo/,' src/time/zoneinfo_unix.go
101− '' + optionalString stdenv.isAarch32 ''
102− echo '#!${runtimeShell}' > misc/cgo/testplugin/test.bash
103− '' + optionalString stdenv.isDarwin ''
104− substituteInPlace src/race.bash --replace \
105− "sysctl machdep.cpu.extfeatures | grep -qv EM64T" true
106− sed -i 's,strings.Contains(.*sysctl.*,true {,' src/cmd/dist/util.go
107− sed -i 's,"/etc","'"$TMPDIR"'",' src/os/os_test.go
108− sed -i 's,/_go_os_test,'"$TMPDIR"'/_go_os_test,' src/os/path_test.go
109−
110− sed -i '/TestChdirAndGetwd/areturn' src/os/os_test.go
111− sed -i '/TestCredentialNoSetGroups/areturn' src/os/exec/exec_posix_test.go
112− sed -i '/TestRead0/areturn' src/os/os_test.go
113− sed -i '/TestSystemRoots/areturn' src/crypto/x509/root_darwin_test.go
114−
115− sed -i '/TestGoInstallRebuildsStalePackagesInOtherGOPATH/areturn' src/cmd/go/go_test.go
116− sed -i '/TestBuildDashIInstallsDependencies/areturn' src/cmd/go/go_test.go
117−
118− sed -i '/TestDisasmExtld/areturn' src/cmd/objdump/objdump_test.go
119−
120− sed -i 's/unrecognized/unknown/' src/cmd/link/internal/ld/lib.go
121−
122− touch $TMPDIR/group $TMPDIR/hosts $TMPDIR/passwd
123− '';
124−
125− patches = [
126− ./remove-tools-1.11.patch
127− ./ssl-cert-file-1.12.1.patch
128− ./remove-test-pie.patch
129− ./creds-test.patch
130− ./go-1.9-skip-flaky-19608.patch
131− ./go-1.9-skip-flaky-20072.patch
132− ./remove-fhs-test-references.patch
133− ./skip-external-network-tests.patch
134− ./skip-nohup-tests.patch
135− # breaks under load: https://github.com/golang/go/issues/25628
136− ./skip-test-extra-files-on-386.patch
137− ];
138−
139− GOOS = stdenv.targetPlatform.parsed.kernel.name;
140− GOARCH = goarch stdenv.targetPlatform;
141− # GOHOSTOS/GOHOSTARCH must match the building system, not the host system.
142− # Go will nevertheless build a for host system that we will copy over in
143− # the install phase.
144− GOHOSTOS = stdenv.buildPlatform.parsed.kernel.name;
145− GOHOSTARCH = goarch stdenv.buildPlatform;
146−
147− # {CC,CXX}_FOR_TARGET must be only set for cross compilation case as go expect those
148− # to be different from CC/CXX
149− CC_FOR_TARGET = if (stdenv.buildPlatform != stdenv.targetPlatform) then
150− "${pkgsTargetTarget.stdenv.cc}/bin/${pkgsTargetTarget.stdenv.cc.targetPrefix}cc"
151− else
152− null;
153− CXX_FOR_TARGET = if (stdenv.buildPlatform != stdenv.targetPlatform) then
154− "${pkgsTargetTarget.stdenv.cc}/bin/${pkgsTargetTarget.stdenv.cc.targetPrefix}c++"
155− else
156− null;
157−
158− GOARM = toString (stdenv.lib.intersectLists [(stdenv.hostPlatform.parsed.cpu.version or "")] ["5" "6" "7"]);
159− GO386 = 387; # from Arch: don't assume sse2 on i686
160− CGO_ENABLED = 1;
161− # Hopefully avoids test timeouts on Hydra
162− GO_TEST_TIMEOUT_SCALE = 3;
163−
164− # Indicate that we are running on build infrastructure
165− # Some tests assume things like home directories and users exists
166− GO_BUILDER_NAME = "nix";
167−
168− GOROOT_BOOTSTRAP="${goBootstrap}/share/go";
169−
170− postConfigure = ''
171− export GOCACHE=$TMPDIR/go-cache
172− # this is compiled into the binary
173− export GOROOT_FINAL=$out/share/go
174−
175− export PATH=$(pwd)/bin:$PATH
176−
177− # Independent from host/target, CC should produce code for the building system.
178− export CC=${buildPackages.stdenv.cc}/bin/cc
179− ulimit -a
180− '';
181−
182− postBuild = ''
183− (cd src && ./make.bash)
184− '';
185−
186− doCheck = stdenv.hostPlatform == stdenv.targetPlatform && !stdenv.isDarwin;
187−
188− checkPhase = ''
189− runHook preCheck
190− (cd src && ./run.bash --no-rebuild)
191− runHook postCheck
192− '';
193−
194− preInstall = ''
195− rm -r pkg/{bootstrap,obj}
196− # Contains the wrong perl shebang when cross compiling,
197− # since it is not used for anything we can deleted as well.
198− rm src/regexp/syntax/make_perl_groups.pl
199− '' + (if (stdenv.buildPlatform != stdenv.hostPlatform) then ''
200− mv bin/*_*/* bin
201− rmdir bin/*_*
202− ${optionalString (!(GOHOSTARCH == GOARCH && GOOS == GOHOSTOS)) ''
203− rm -rf pkg/${GOHOSTOS}_${GOHOSTARCH} pkg/tool/${GOHOSTOS}_${GOHOSTARCH}
204− ''}
205− '' else if (stdenv.hostPlatform != stdenv.targetPlatform) then ''
206− rm -rf bin/*_*
207− ${optionalString (!(GOHOSTARCH == GOARCH && GOOS == GOHOSTOS)) ''
208− rm -rf pkg/${GOOS}_${GOARCH} pkg/tool/${GOOS}_${GOARCH}
209− ''}
210− '' else "");
211−
212− installPhase = ''
213− runHook preInstall
214− mkdir -p $GOROOT_FINAL
215− cp -a bin pkg src lib misc api doc $GOROOT_FINAL
216− ln -s $GOROOT_FINAL/bin $out/bin
217− runHook postInstall
218− '';
219−
220− setupHook = ./setup-hook.sh;
221−
222− disallowedReferences = [ goBootstrap ];
223−
224− meta = with stdenv.lib; {
225− branch = "1.11";
226− homepage = http://golang.org/;
227− description = "The Go Programming language";
228− license = licenses.bsd3;
229− maintainers = with maintainers; [ cstrahan orivej velovix mic92 rvolosatovs ];
230− platforms = platforms.linux ++ platforms.darwin;
231− };
232−}