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