at master 6.0 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchurl, 5 apple-sdk_12, 6 tzdata, 7 replaceVars, 8 iana-etc, 9 mailcap, 10 buildPackages, 11 pkgsBuildTarget, 12 targetPackages, 13 testers, 14 skopeo, 15 buildGo125Module, 16}: 17 18let 19 goBootstrap = buildPackages.callPackage ./bootstrap122.nix { }; 20 21 skopeoTest = skopeo.override { buildGoModule = buildGo125Module; }; 22 23 # We need a target compiler which is still runnable at build time, 24 # to handle the cross-building case where build != host == target 25 targetCC = pkgsBuildTarget.targetPackages.stdenv.cc; 26 27 isCross = stdenv.buildPlatform != stdenv.targetPlatform; 28in 29stdenv.mkDerivation (finalAttrs: { 30 pname = "go"; 31 version = "1.25.0"; 32 33 src = fetchurl { 34 url = "https://go.dev/dl/go${finalAttrs.version}.src.tar.gz"; 35 hash = "sha256-S9AekSlyB7+kUOpA1NWpOxtTGl5DhHOyoG4Y4HciciU="; 36 }; 37 38 strictDeps = true; 39 buildInputs = 40 [ ] 41 ++ lib.optionals stdenv.hostPlatform.isLinux [ stdenv.cc.libc.out ] 42 ++ lib.optionals (stdenv.hostPlatform.libc == "glibc") [ stdenv.cc.libc.static ]; 43 44 depsTargetTargetPropagated = lib.optionals stdenv.targetPlatform.isDarwin [ 45 apple-sdk_12 46 ]; 47 48 depsBuildTarget = lib.optional isCross targetCC; 49 50 depsTargetTarget = lib.optional stdenv.targetPlatform.isMinGW targetPackages.threads.package; 51 52 postPatch = '' 53 patchShebangs . 54 ''; 55 56 patches = [ 57 (replaceVars ./iana-etc-1.25.patch { 58 iana = iana-etc; 59 }) 60 # Patch the mimetype database location which is missing on NixOS. 61 # but also allow static binaries built with NixOS to run outside nix 62 (replaceVars ./mailcap-1.17.patch { 63 inherit mailcap; 64 }) 65 # prepend the nix path to the zoneinfo files but also leave the original value for static binaries 66 # that run outside a nix server 67 (replaceVars ./tzdata-1.19.patch { 68 inherit tzdata; 69 }) 70 ./remove-tools-1.11.patch 71 ./go_no_vendor_checks-1.23.patch 72 ]; 73 74 inherit (stdenv.targetPlatform.go) GOOS GOARCH GOARM; 75 # GOHOSTOS/GOHOSTARCH must match the building system, not the host system. 76 # Go will nevertheless build a for host system that we will copy over in 77 # the install phase. 78 GOHOSTOS = stdenv.buildPlatform.go.GOOS; 79 GOHOSTARCH = stdenv.buildPlatform.go.GOARCH; 80 81 # {CC,CXX}_FOR_TARGET must be only set for cross compilation case as go expect those 82 # to be different from CC/CXX 83 CC_FOR_TARGET = if isCross then "${targetCC}/bin/${targetCC.targetPrefix}cc" else null; 84 CXX_FOR_TARGET = if isCross then "${targetCC}/bin/${targetCC.targetPrefix}c++" else null; 85 86 GO386 = "softfloat"; # from Arch: don't assume sse2 on i686 87 # Wasi does not support CGO 88 # ppc64/linux CGO is incomplete/borked, and will likely not receive any further improvements 89 # https://github.com/golang/go/issues/8912 90 # https://github.com/golang/go/issues/13192 91 CGO_ENABLED = 92 if 93 ( 94 stdenv.targetPlatform.isWasi 95 || (stdenv.targetPlatform.isPower64 && stdenv.targetPlatform.isBigEndian) 96 ) 97 then 98 0 99 else 100 1; 101 102 GOROOT_BOOTSTRAP = "${goBootstrap}/share/go"; 103 104 buildPhase = '' 105 runHook preBuild 106 export GOCACHE=$TMPDIR/go-cache 107 108 export PATH=$(pwd)/bin:$PATH 109 110 ${lib.optionalString isCross '' 111 # Independent from host/target, CC should produce code for the building system. 112 # We only set it when cross-compiling. 113 export CC=${buildPackages.stdenv.cc}/bin/cc 114 ''} 115 ulimit -a 116 117 pushd src 118 ./make.bash 119 popd 120 runHook postBuild 121 ''; 122 123 preInstall = '' 124 # Contains the wrong perl shebang when cross compiling, 125 # since it is not used for anything we can deleted as well. 126 rm src/regexp/syntax/make_perl_groups.pl 127 '' 128 + ( 129 if (stdenv.buildPlatform.system != stdenv.hostPlatform.system) then 130 '' 131 mv bin/*_*/* bin 132 rmdir bin/*_* 133 ${lib.optionalString 134 (!(finalAttrs.GOHOSTARCH == finalAttrs.GOARCH && finalAttrs.GOOS == finalAttrs.GOHOSTOS)) 135 '' 136 rm -rf pkg/${finalAttrs.GOHOSTOS}_${finalAttrs.GOHOSTARCH} pkg/tool/${finalAttrs.GOHOSTOS}_${finalAttrs.GOHOSTARCH} 137 '' 138 } 139 '' 140 else 141 lib.optionalString (stdenv.hostPlatform.system != stdenv.targetPlatform.system) '' 142 rm -rf bin/*_* 143 ${lib.optionalString 144 (!(finalAttrs.GOHOSTARCH == finalAttrs.GOARCH && finalAttrs.GOOS == finalAttrs.GOHOSTOS)) 145 '' 146 rm -rf pkg/${finalAttrs.GOOS}_${finalAttrs.GOARCH} pkg/tool/${finalAttrs.GOOS}_${finalAttrs.GOARCH} 147 '' 148 } 149 '' 150 ); 151 152 installPhase = '' 153 runHook preInstall 154 mkdir -p $out/share/go 155 cp -a bin pkg src lib misc api doc go.env VERSION $out/share/go 156 mkdir -p $out/bin 157 ln -s $out/share/go/bin/* $out/bin 158 runHook postInstall 159 ''; 160 161 disallowedReferences = [ goBootstrap ]; 162 163 passthru = { 164 inherit goBootstrap skopeoTest; 165 tests = { 166 skopeo = testers.testVersion { package = skopeoTest; }; 167 version = testers.testVersion { 168 package = finalAttrs.finalPackage; 169 command = "go version"; 170 version = "go${finalAttrs.version}"; 171 }; 172 }; 173 }; 174 175 meta = with lib; { 176 changelog = "https://go.dev/doc/devel/release#go${lib.versions.majorMinor finalAttrs.version}"; 177 description = "Go Programming language"; 178 homepage = "https://go.dev/"; 179 license = licenses.bsd3; 180 teams = [ teams.golang ]; 181 platforms = platforms.darwin ++ platforms.linux ++ platforms.wasi ++ platforms.freebsd; 182 badPlatforms = [ 183 # Support for big-endian POWER < 8 was dropped in 1.9, but POWER8 users have less of a reason to run in big-endian mode than pre-POWER8 ones 184 # So non-LE ppc64 is effectively unsupported, and Go SIGILLs on affordable ppc64 hardware 185 # https://github.com/golang/go/issues/19074 - Dropped support for big-endian POWER < 8, with community pushback 186 # https://github.com/golang/go/issues/73349 - upstream will not accept submissions to fix this 187 "powerpc64-linux" 188 ]; 189 mainProgram = "go"; 190 }; 191})