@@ -0,0 +1,161 @@
1+{ stdenv, lib, fetchFromGitHub, tzdata, iana_etc, go_1_4, runCommand
2+, perl, which, pkgconfig, patch, fetchpatch
3+, pcre
4+, Security, Foundation, bash }:
5+
6+let
7+ goBootstrap = runCommand "go-bootstrap" {} ''
8+ mkdir $out
9+ cp -rf ${go_1_4}/* $out/
10+ chmod -R u+w $out
11+ find $out -name "*.c" -delete
12+ cp -rf $out/bin/* $out/share/go/bin/
13+ '';
14+in
15+
16+stdenv.mkDerivation rec {
17+ name = "go-${version}";
18+ version = "1.7";
19+
20+ src = fetchFromGitHub {
21+ owner = "golang";
22+ repo = "go";
23+ rev = "go${version}";
24+ sha256 = "03wc4r5pgxrlh3lp8l0hb1bhsrwv4hfq1fcj8n82bfk3hvj43am2";
25+ };
26+
27+ # perl is used for testing go vet
28+ nativeBuildInputs = [ perl which pkgconfig patch ];
29+ buildInputs = [ pcre ];
30+ propagatedBuildInputs = lib.optionals stdenv.isDarwin [
31+ Security Foundation
32+ ];
33+
34+ # I'm not sure what go wants from its 'src', but the go installation manual
35+ # describes an installation keeping the src.
36+ preUnpack = ''
37+ topdir=$PWD
38+ mkdir -p $out/share
39+ cd $out/share
40+ '';
41+
42+ prePatch = ''
43+ # Ensure that the source directory is named go
44+ cd ..
45+ if [ ! -d go ]; then
46+ mv * go
47+ fi
48+
49+ cd go
50+ patchShebangs ./ # replace /bin/bash
51+
52+ # This source produces shell script at run time,
53+ # and thus it is not corrected by patchShebangs.
54+ substituteInPlace misc/cgo/testcarchive/carchive_test.go \
55+ --replace '#!/usr/bin/env bash' '#!${stdenv.shell}'
56+
57+ # Disabling the 'os/http/net' tests (they want files not available in
58+ # chroot builds)
59+ rm src/net/{listen,parse}_test.go
60+ rm src/syscall/exec_linux_test.go
61+ # !!! substituteInPlace does not seems to be effective.
62+ # The os test wants to read files in an existing path. Just don't let it be /usr/bin.
63+ sed -i 's,/usr/bin,'"`pwd`", src/os/os_test.go
64+ sed -i 's,/bin/pwd,'"`type -P pwd`", src/os/os_test.go
65+ # Disable the unix socket test
66+ sed -i '/TestShutdownUnix/areturn' src/net/net_test.go
67+ # Disable the hostname test
68+ sed -i '/TestHostname/areturn' src/os/os_test.go
69+ # ParseInLocation fails the test
70+ sed -i '/TestParseInSydney/areturn' src/time/format_test.go
71+ # Remove the api check as it never worked
72+ sed -i '/src\/cmd\/api\/run.go/ireturn nil' src/cmd/dist/test.go
73+ # Remove the coverage test as we have removed this utility
74+ sed -i '/TestCoverageWithCgo/areturn' src/cmd/go/go_test.go
75+
76+ sed -i 's,/etc/protocols,${iana_etc}/etc/protocols,' src/net/lookup_unix.go
77+ sed -i 's,/etc/services,${iana_etc}/etc/services,' src/net/port_unix.go
78+
79+ # Disable cgo lookup tests not works, they depend on resolver
80+ rm src/net/cgo_unix_test.go
81+
82+ '' + lib.optionalString stdenv.isLinux ''
83+ sed -i 's,/usr/share/zoneinfo/,${tzdata}/share/zoneinfo/,' src/time/zoneinfo_unix.go
84+ '' + lib.optionalString stdenv.isDarwin ''
85+ substituteInPlace src/race.bash --replace \
86+ "sysctl machdep.cpu.extfeatures | grep -qv EM64T" true
87+ sed -i 's,strings.Contains(.*sysctl.*,true {,' src/cmd/dist/util.go
88+ sed -i 's,"/etc","'"$TMPDIR"'",' src/os/os_test.go
89+ sed -i 's,/_go_os_test,'"$TMPDIR"'/_go_os_test,' src/os/path_test.go
90+
91+ sed -i '/TestChdirAndGetwd/areturn' src/os/os_test.go
92+ sed -i '/TestRead0/areturn' src/os/os_test.go
93+ sed -i '/TestNohup/areturn' src/os/signal/signal_test.go
94+ sed -i '/TestSystemRoots/areturn' src/crypto/x509/root_darwin_test.go
95+
96+ sed -i '/TestGoInstallRebuildsStalePackagesInOtherGOPATH/areturn' src/cmd/go/go_test.go
97+ sed -i '/TestBuildDashIInstallsDependencies/areturn' src/cmd/go/go_test.go
98+
99+ sed -i '/TestDisasmExtld/areturn' src/cmd/objdump/objdump_test.go
100+
101+ touch $TMPDIR/group $TMPDIR/hosts $TMPDIR/passwd
102+
103+ sed -i '1 a\exit 0' misc/cgo/errors/test.bash
104+
105+ mkdir $topdir/dirtyhacks
106+ cat <<EOF > $topdir/dirtyhacks/clang
107+ #!${bash}/bin/bash
108+ $(type -P clang) "\$@" 2> >(sed '/ld: warning:.*ignoring unexpected dylib file/ d' 1>&2)
109+ exit $?
110+ EOF
111+ chmod +x $topdir/dirtyhacks/clang
112+ PATH=$topdir/dirtyhacks:$PATH
113+ '';
114+
115+ patches = [
116+ ./remove-tools-1.7.patch
117+ ];
118+
119+ GOOS = if stdenv.isDarwin then "darwin" else "linux";
120+ GOARCH = if stdenv.isDarwin then "amd64"
121+ else if stdenv.system == "i686-linux" then "386"
122+ else if stdenv.system == "x86_64-linux" then "amd64"
123+ else if stdenv.isArm then "arm"
124+ else throw "Unsupported system";
125+ GOARM = stdenv.lib.optionalString (stdenv.system == "armv5tel-linux") "5";
126+ GO386 = 387; # from Arch: don't assume sse2 on i686
127+ CGO_ENABLED = 1;
128+ GOROOT_BOOTSTRAP = "${goBootstrap}/share/go";
129+
130+ # The go build actually checks for CC=*/clang and does something different, so we don't
131+ # just want the generic `cc` here.
132+ CC = if stdenv.isDarwin then "clang" else "cc";
133+
134+ installPhase = ''
135+ mkdir -p "$out/bin"
136+ export GOROOT="$(pwd)/"
137+ export GOBIN="$out/bin"
138+ export PATH="$GOBIN:$PATH"
139+ cd ./src
140+ echo Building
141+ ./all.bash
142+ '';
143+
144+ preFixup = ''
145+ rm -r $out/share/go/pkg/bootstrap
146+ rmdir $out/bin && mv $out/share/go/bin $out/bin
147+ '';
148+
149+ setupHook = ./setup-hook.sh;
150+
151+ disallowedReferences = [ go_1_4 ];
152+
153+ meta = with stdenv.lib; {
154+ branch = "1.7";
155+ homepage = http://golang.org/;
156+ description = "The Go Programming language";
157+ license = licenses.bsd3;
158+ maintainers = with maintainers; [ cstrahan wkennington ];
159+ platforms = platforms.linux ++ platforms.darwin;
160+ };
161+}