diff --git a/lib/systems/default.nix b/lib/systems/default.nix index ce257d5307b6..eab2561678e3 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -531,6 +531,35 @@ let "-uefi" ]; }; + } + // { + go = { + # See https://pkg.go.dev/internal/platform for a list of known platforms + GOARCH = + { + "aarch64" = "arm64"; + "arm" = "arm"; + "armv5tel" = "arm"; + "armv6l" = "arm"; + "armv7l" = "arm"; + "i686" = "386"; + "loongarch64" = "loong64"; + "mips" = "mips"; + "mips64el" = "mips64le"; + "mipsel" = "mipsle"; + "powerpc64" = "ppc64"; + "powerpc64le" = "ppc64le"; + "riscv64" = "riscv64"; + "s390x" = "s390x"; + "x86_64" = "amd64"; + "wasm32" = "wasm"; + } + .${final.parsed.cpu.name} or (throw "Unknown CPU variant ${final.parsed.cpu.name} by Go"); + GOOS = if final.isWasi then "wasip1" else final.parsed.kernel.name; + + # See https://go.dev/wiki/GoArm + GOARM = toString (lib.intersectLists [ (final.parsed.cpu.version or "") ] [ "5" "6" "7" ]); + }; }; in assert final.useAndroidPrebuilt -> final.isAndroid; diff --git a/pkgs/development/compilers/go/1.23.nix b/pkgs/development/compilers/go/1.23.nix index 54ba330d6c7f..ba9cf4e3d8ff 100644 --- a/pkgs/development/compilers/go/1.23.nix +++ b/pkgs/development/compilers/go/1.23.nix @@ -19,28 +19,6 @@ let skopeoTest = skopeo.override { buildGoModule = buildGo123Module; }; - goarch = - platform: - { - "aarch64" = "arm64"; - "arm" = "arm"; - "armv5tel" = "arm"; - "armv6l" = "arm"; - "armv7l" = "arm"; - "i686" = "386"; - "loongarch64" = "loong64"; - "mips" = "mips"; - "mips64el" = "mips64le"; - "mipsel" = "mipsle"; - "powerpc64" = "ppc64"; - "powerpc64le" = "ppc64le"; - "riscv64" = "riscv64"; - "s390x" = "s390x"; - "x86_64" = "amd64"; - "wasm32" = "wasm"; - } - .${platform.parsed.cpu.name} or (throw "Unsupported system: ${platform.parsed.cpu.name}"); - # We need a target compiler which is still runnable at build time, # to handle the cross-building case where build != host == target targetCC = pkgsBuildTarget.targetPackages.stdenv.cc; @@ -88,22 +66,18 @@ stdenv.mkDerivation (finalAttrs: { ./go_no_vendor_checks-1.23.patch ]; - GOOS = if stdenv.targetPlatform.isWasi then "wasip1" else stdenv.targetPlatform.parsed.kernel.name; - GOARCH = goarch stdenv.targetPlatform; + inherit (stdenv.targetPlatform.go) GOOS GOARCH GOARM; # GOHOSTOS/GOHOSTARCH must match the building system, not the host system. # Go will nevertheless build a for host system that we will copy over in # the install phase. - GOHOSTOS = stdenv.buildPlatform.parsed.kernel.name; - GOHOSTARCH = goarch stdenv.buildPlatform; + GOHOSTOS = stdenv.buildPlatform.go.GOOS; + GOHOSTARCH = stdenv.buildPlatform.go.GOARCH; # {CC,CXX}_FOR_TARGET must be only set for cross compilation case as go expect those # to be different from CC/CXX CC_FOR_TARGET = if isCross then "${targetCC}/bin/${targetCC.targetPrefix}cc" else null; CXX_FOR_TARGET = if isCross then "${targetCC}/bin/${targetCC.targetPrefix}c++" else null; - GOARM = toString ( - lib.intersectLists [ (stdenv.hostPlatform.parsed.cpu.version or "") ] [ "5" "6" "7" ] - ); GO386 = "softfloat"; # from Arch: don't assume sse2 on i686 # Wasi does not support CGO CGO_ENABLED = if stdenv.targetPlatform.isWasi then 0 else 1; diff --git a/pkgs/development/compilers/go/1.24.nix b/pkgs/development/compilers/go/1.24.nix index a6c33a4a67d1..6991b06118b6 100644 --- a/pkgs/development/compilers/go/1.24.nix +++ b/pkgs/development/compilers/go/1.24.nix @@ -19,28 +19,6 @@ let skopeoTest = skopeo.override { buildGoModule = buildGo124Module; }; - goarch = - platform: - { - "aarch64" = "arm64"; - "arm" = "arm"; - "armv5tel" = "arm"; - "armv6l" = "arm"; - "armv7l" = "arm"; - "i686" = "386"; - "loongarch64" = "loong64"; - "mips" = "mips"; - "mips64el" = "mips64le"; - "mipsel" = "mipsle"; - "powerpc64" = "ppc64"; - "powerpc64le" = "ppc64le"; - "riscv64" = "riscv64"; - "s390x" = "s390x"; - "x86_64" = "amd64"; - "wasm32" = "wasm"; - } - .${platform.parsed.cpu.name} or (throw "Unsupported system: ${platform.parsed.cpu.name}"); - # We need a target compiler which is still runnable at build time, # to handle the cross-building case where build != host == target targetCC = pkgsBuildTarget.targetPackages.stdenv.cc; @@ -88,22 +66,18 @@ stdenv.mkDerivation (finalAttrs: { ./go_no_vendor_checks-1.23.patch ]; - GOOS = if stdenv.targetPlatform.isWasi then "wasip1" else stdenv.targetPlatform.parsed.kernel.name; - GOARCH = goarch stdenv.targetPlatform; + inherit (stdenv.targetPlatform.go) GOOS GOARCH GOARM; # GOHOSTOS/GOHOSTARCH must match the building system, not the host system. # Go will nevertheless build a for host system that we will copy over in # the install phase. - GOHOSTOS = stdenv.buildPlatform.parsed.kernel.name; - GOHOSTARCH = goarch stdenv.buildPlatform; + GOHOSTOS = stdenv.buildPlatform.go.GOOS; + GOHOSTARCH = stdenv.buildPlatform.go.GOARCH; # {CC,CXX}_FOR_TARGET must be only set for cross compilation case as go expect those # to be different from CC/CXX CC_FOR_TARGET = if isCross then "${targetCC}/bin/${targetCC.targetPrefix}cc" else null; CXX_FOR_TARGET = if isCross then "${targetCC}/bin/${targetCC.targetPrefix}c++" else null; - GOARM = toString ( - lib.intersectLists [ (stdenv.hostPlatform.parsed.cpu.version or "") ] [ "5" "6" "7" ] - ); GO386 = "softfloat"; # from Arch: don't assume sse2 on i686 # Wasi does not support CGO CGO_ENABLED = if stdenv.targetPlatform.isWasi then 0 else 1; diff --git a/pkgs/development/compilers/go/binary.nix b/pkgs/development/compilers/go/binary.nix index 8c6fbeddfbb3..b32b70a392ec 100644 --- a/pkgs/development/compilers/go/binary.nix +++ b/pkgs/development/compilers/go/binary.nix @@ -6,25 +6,7 @@ hashes, }: let - toGoKernel = platform: if platform.isDarwin then "darwin" else platform.parsed.kernel.name; - - toGoCPU = - platform: - { - "i686" = "386"; - "x86_64" = "amd64"; - "aarch64" = "arm64"; - "armv6l" = "armv6l"; - "armv7l" = "armv6l"; - "powerpc64le" = "ppc64le"; - "riscv64" = "riscv64"; - "loongarch64" = "loong64"; - } - .${platform.parsed.cpu.name} or (throw "Unsupported CPU ${platform.parsed.cpu.name}"); - - toGoPlatform = platform: "${toGoKernel platform}-${toGoCPU platform}"; - - platform = toGoPlatform stdenv.hostPlatform; + platform = with stdenv.hostPlatform.go; "${GOOS}-${if GOARCH == "arm" then "armv6l" else GOARCH}"; in stdenv.mkDerivation { name = "go-${version}-${platform}-bootstrap";