From 6cd67ec48f22a1c4fd58a6fe92da7d91d32911c7 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Wed, 13 May 2020 14:34:10 -0400 Subject: [PATCH 01/12] go: stop setting GOPATH The compiler does not need it anymore, has not needed it for many years iirc. This just goes in and pollutes the environment overriding the users GOPATH and causing grief. Go even warns about it itself, without vs with this commit: ```sh ~> go env GOPATH /home/manny/go ~> nix-shell -p go ~> go env GOPATH warning: GOPATH set to GOROOT (/nix/store/gvw1mfpdrk7i82884yhxf9lf5j3c12zm-go-1.14.1/share/go) has no effect /nix/store/gvw1mfpdrk7i82884yhxf9lf5j3c12zm-go-1.14.1/share/go ~> exit ~> nix-shell -I nixpkgs=cloned/NixOS/nixpkgs -p go ~> go env GOPATH /home/manny/go ~> exit ``` (cherry picked from commit a1e13f6140a568b73c1c36bb9ef79d7876ccaae3) --- pkgs/development/compilers/go/1.14.nix | 2 -- pkgs/development/compilers/go/1.4.nix | 2 -- pkgs/development/compilers/go/setup-hook.sh | 5 ----- 3 files changed, 9 deletions(-) delete mode 100644 pkgs/development/compilers/go/setup-hook.sh diff --git a/pkgs/development/compilers/go/1.14.nix b/pkgs/development/compilers/go/1.14.nix index b11bb61c6379e..07d2450ecceaf 100644 --- a/pkgs/development/compilers/go/1.14.nix +++ b/pkgs/development/compilers/go/1.14.nix @@ -230,8 +230,6 @@ stdenv.mkDerivation rec { runHook postInstall ''; - setupHook = ./setup-hook.sh; - disallowedReferences = [ goBootstrap ]; meta = with stdenv.lib; { diff --git a/pkgs/development/compilers/go/1.4.nix b/pkgs/development/compilers/go/1.4.nix index 0dd852a1ef168..7f0b2ba9ceb89 100644 --- a/pkgs/development/compilers/go/1.4.nix +++ b/pkgs/development/compilers/go/1.4.nix @@ -151,8 +151,6 @@ stdenv.mkDerivation rec { ./all.bash ''; - setupHook = ./setup-hook.sh; - meta = with stdenv.lib; { branch = "1.4"; homepage = http://golang.org/; diff --git a/pkgs/development/compilers/go/setup-hook.sh b/pkgs/development/compilers/go/setup-hook.sh deleted file mode 100644 index 7dce15eeb1025..0000000000000 --- a/pkgs/development/compilers/go/setup-hook.sh +++ /dev/null @@ -1,5 +0,0 @@ -addToGoPath() { - addToSearchPath GOPATH $1/share/go -} - -addEnvHooks "$targetOffset" addToGoPath From 296e584a00e9590b8d2c67c53921ab081374b2b5 Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Sat, 16 May 2020 10:21:58 +1000 Subject: [PATCH 02/12] go_1_13: stop setting GOPATH a1e13f6140a568b73c1c36bb9ef79d7876ccaae3 (cherry picked from commit 469f14ceecf94dd13527c9153c25984d674768a7) --- pkgs/development/compilers/go/1.13.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkgs/development/compilers/go/1.13.nix b/pkgs/development/compilers/go/1.13.nix index 58786a94efe59..a1052e387ef13 100644 --- a/pkgs/development/compilers/go/1.13.nix +++ b/pkgs/development/compilers/go/1.13.nix @@ -230,8 +230,6 @@ stdenv.mkDerivation rec { runHook postInstall ''; - setupHook = ./setup-hook.sh; - disallowedReferences = [ goBootstrap ]; meta = with stdenv.lib; { From c9965e2df7cf17777581e25067fab75a83dd7529 Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Sat, 13 Jun 2020 13:22:07 +1000 Subject: [PATCH 03/12] go_1_12: stop setting GOPATH --- pkgs/development/compilers/go/1.12.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkgs/development/compilers/go/1.12.nix b/pkgs/development/compilers/go/1.12.nix index a48c733631098..0caddc65c9b5c 100644 --- a/pkgs/development/compilers/go/1.12.nix +++ b/pkgs/development/compilers/go/1.12.nix @@ -233,8 +233,6 @@ stdenv.mkDerivation rec { runHook postInstall ''; - setupHook = ./setup-hook.sh; - disallowedReferences = [ goBootstrap ]; meta = with stdenv.lib; { From 382b2dbad796a3bc8371179a15f72857dd6de4e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 5 May 2020 17:58:20 +0100 Subject: [PATCH 04/12] go: 1.14.1 -> 1.14.2 (cherry picked from commit 416caeb6dbd59d5c53da542dcf3184f11141f354) --- pkgs/development/compilers/go/1.14.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/go/1.14.nix b/pkgs/development/compilers/go/1.14.nix index 07d2450ecceaf..8a2ff280c0c12 100644 --- a/pkgs/development/compilers/go/1.14.nix +++ b/pkgs/development/compilers/go/1.14.nix @@ -30,11 +30,11 @@ in stdenv.mkDerivation rec { pname = "go"; - version = "1.14.1"; + version = "1.14.2"; src = fetchurl { url = "https://dl.google.com/go/go${version}.src.tar.gz"; - sha256 = "0xkna02clggcdgl5xxwani62krnf64x6p3hk9k5v9ldh2lhmglia"; + sha256 = "0z3zxsnhmsxplnwfw1l9gr6jgglwp50sr3p5njknv9i6jzk89plq"; }; # perl is used for testing go vet From 2a1c67cb2dbe535d0d8f08be620860a1f6b65213 Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Fri, 15 May 2020 09:54:39 +1000 Subject: [PATCH 05/12] go: 1.14.2 -> 1.14.3 https://golang.org/doc/devel/release.html#go1.14.minor (cherry picked from commit 8d41f9f281a8317faa45c4270e8d48bf657cc1a0) --- pkgs/development/compilers/go/1.14.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/go/1.14.nix b/pkgs/development/compilers/go/1.14.nix index 8a2ff280c0c12..94e6cf98c81fd 100644 --- a/pkgs/development/compilers/go/1.14.nix +++ b/pkgs/development/compilers/go/1.14.nix @@ -30,11 +30,11 @@ in stdenv.mkDerivation rec { pname = "go"; - version = "1.14.2"; + version = "1.14.3"; src = fetchurl { url = "https://dl.google.com/go/go${version}.src.tar.gz"; - sha256 = "0z3zxsnhmsxplnwfw1l9gr6jgglwp50sr3p5njknv9i6jzk89plq"; + sha256 = "0mmgf74snprdiajgh99jjliwjl5im71qcgm5qrxpnyfisiw3f0lk"; }; # perl is used for testing go vet From 203fcbada9d49d2bf4b5899dafa2473791c58cbf Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Sat, 16 May 2020 10:23:00 +1000 Subject: [PATCH 06/12] go_1_13: 1.13.8 -> 1.13.11 (cherry picked from commit d1e7b0049ca5bfb48a3fd597278acdc5b97b700f) --- pkgs/development/compilers/go/1.13.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/go/1.13.nix b/pkgs/development/compilers/go/1.13.nix index a1052e387ef13..0731b5082a1eb 100644 --- a/pkgs/development/compilers/go/1.13.nix +++ b/pkgs/development/compilers/go/1.13.nix @@ -30,11 +30,11 @@ in stdenv.mkDerivation rec { pname = "go"; - version = "1.13.8"; + version = "1.13.11"; src = fetchurl { url = "https://dl.google.com/go/go${version}.src.tar.gz"; - sha256 = "0d7cxffk72568h46srzswrxd0bsdip7amgkf499wzn6l6d3g0fxi"; + sha256 = "0y86q2k00lh8c7wj3lha43g804iwr61nap8j3i907l2sway1mvc9"; }; # perl is used for testing go vet From b1cbd0870337da098feb6887a8891299727e9857 Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Tue, 2 Jun 2020 09:29:55 +1000 Subject: [PATCH 07/12] go_1_13: 1.13.11 -> 1.13.12 https://golang.org/doc/devel/release.html#go1.13.minor (cherry picked from commit 7da08afd273f13124ab708a2c969e426f70fa08e) --- pkgs/development/compilers/go/1.13.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/go/1.13.nix b/pkgs/development/compilers/go/1.13.nix index 0731b5082a1eb..1e1f53746c5df 100644 --- a/pkgs/development/compilers/go/1.13.nix +++ b/pkgs/development/compilers/go/1.13.nix @@ -30,11 +30,11 @@ in stdenv.mkDerivation rec { pname = "go"; - version = "1.13.11"; + version = "1.13.12"; src = fetchurl { url = "https://dl.google.com/go/go${version}.src.tar.gz"; - sha256 = "0y86q2k00lh8c7wj3lha43g804iwr61nap8j3i907l2sway1mvc9"; + sha256 = "0d5s5rqyzp6ykj4x1dz8infcsmj3gy8djnf63ji971ypwi6jrfhp"; }; # perl is used for testing go vet From 16a461d1471df4f599dba6e7da6aca086af7ba71 Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Tue, 2 Jun 2020 09:32:40 +1000 Subject: [PATCH 08/12] go: 1.14.3 -> 1.14.4 https://golang.org/doc/devel/release.html#go1.14.minor (cherry picked from commit 9f978147f826c55d01db6d2aeeeff2a71f80b932) --- pkgs/development/compilers/go/1.14.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/go/1.14.nix b/pkgs/development/compilers/go/1.14.nix index 94e6cf98c81fd..1435b36fbc762 100644 --- a/pkgs/development/compilers/go/1.14.nix +++ b/pkgs/development/compilers/go/1.14.nix @@ -30,11 +30,11 @@ in stdenv.mkDerivation rec { pname = "go"; - version = "1.14.3"; + version = "1.14.4"; src = fetchurl { url = "https://dl.google.com/go/go${version}.src.tar.gz"; - sha256 = "0mmgf74snprdiajgh99jjliwjl5im71qcgm5qrxpnyfisiw3f0lk"; + sha256 = "1105qk2l4kfy1ki9n9gh8j4gfqrfgfwapa1fp38hih9aphxsy4bh"; }; # perl is used for testing go vet From 4094b363c394d346e696b856bfd5431e334dec7c Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:35:08 +1000 Subject: [PATCH 09/12] go: fix TestDontCacheBrokenHTTP2Conn failure (cherry picked from commit aae680cd5d508b4696252368b72490b96c101277) --- pkgs/development/compilers/go/1.14.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/compilers/go/1.14.nix b/pkgs/development/compilers/go/1.14.nix index 1435b36fbc762..f35c339ebd072 100644 --- a/pkgs/development/compilers/go/1.14.nix +++ b/pkgs/development/compilers/go/1.14.nix @@ -2,6 +2,7 @@ , perl, which, pkgconfig, patch, procps, pcre, cacert, Security, Foundation , mailcap, runtimeShell , buildPackages, pkgsTargetTarget +, fetchpatch }: let @@ -138,6 +139,12 @@ stdenv.mkDerivation rec { ./go-1.9-skip-flaky-20072.patch ./skip-external-network-tests.patch ./skip-nohup-tests.patch + + # fix rare TestDontCacheBrokenHTTP2Conn failure + (fetchpatch { + url = "https://github.com/golang/go/commit/ea1437a8cdf6bb3c2d2447833a5d06dbd75f7ae4.patch"; + sha256 = "1lyzy4nf8c34a966vw45j3j7hzpvncq2gqspfxffzkyh17xd8sgy"; + }) ] ++ [ # breaks under load: https://github.com/golang/go/issues/25628 (if stdenv.isAarch32 From 9ae22e3409ab151ab0f0161d909608e49083b47a Mon Sep 17 00:00:00 2001 From: Benjamin Hipple Date: Wed, 11 Mar 2020 02:04:46 -0400 Subject: [PATCH 10/12] buildGoModule: passthru the modSha256 (#82027) The builder does not technically need the modSha256 of the vendor dir, and even though we pass it the entire vendor dir it makes sense not to risk having an accidental dependency on that variable. However, tools like [nixpkgs-update](https://github.com/ryantm/nixpkgs-update) need to inspect the `modSha256` of a package in order to be able to update them, and since this is a real part of the package (describes info about its dependencies) let's add it to `passthru`. Specifically, this allows us to run a cmd like `nix eval -f . tflint.modSha256` to get the current value, which is how the bot finds it to replace with the new version in the Rust ecosystem. (cherry picked from commit 5f77ff63849396c2b0dd243c0bb9fdae13c0fab6) --- pkgs/development/go-modules/generic/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix index 1bffb71e8f9db..1bf13c18821e8 100644 --- a/pkgs/development/go-modules/generic/default.nix +++ b/pkgs/development/go-modules/generic/default.nix @@ -210,7 +210,7 @@ let disallowedReferences = lib.optional (!allowGoReference) go; - passthru = passthru // { inherit go go-modules; }; + passthru = passthru // { inherit go go-modules modSha256; }; meta = { # Add default meta information From 470d55587f4e6383341f3eeac823092690cf6776 Mon Sep 17 00:00:00 2001 From: Colin L Rice Date: Wed, 29 Apr 2020 23:08:21 -0400 Subject: [PATCH 11/12] go-modules: Augment builds w/ vendor src This is done in response to complaints that the module format is not human readable. The vendor source blob is flat files and should be extremely readable. (cherry picked from commit 9761128d2da7bf4d878982918242e43ae28f9b94) --- .../go-modules/generic/default.nix | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix index 1bf13c18821e8..3184937adaa67 100644 --- a/pkgs/development/go-modules/generic/default.nix +++ b/pkgs/development/go-modules/generic/default.nix @@ -13,12 +13,15 @@ # path to go.mod and go.sum directory , modRoot ? "./" -# modSha256 is the sha256 of the vendored dependencies +# vendorSha256 is the sha256 of the vendored dependencies # -# CAUTION: if `null` is used as a value, the derivation won't be a -# fixed-output derivation but disable the build sandbox instead. Don't use -# this in nixpkgs as Hydra won't build those packages. -, modSha256 +# if vendorSha256 is null, then we won't fetch any dependencies and +# rely on the vendor folder within the source. +, vendorSha256 ? null +# Whether to delete the vendor folder supplied with the source. +, deleteVendor ? false + +, modSha256 ? null # We want parallel builds by default , enableParallelBuilding ? true @@ -37,21 +40,26 @@ with builtins; let - args = removeAttrs args' [ "overrideModAttrs" "modSha256" "disabled" ]; + args = removeAttrs args' [ "overrideModAttrs" "vendorSha256" "disabled" ]; removeReferences = [ ] ++ lib.optional (!allowGoReference) go; removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}''; - go-modules = go.stdenv.mkDerivation (let modArgs = { + deleteFlag = if deleteVendor then "true" else "false"; + + go-modules = if vendorSha256 != null then go.stdenv.mkDerivation (let modArgs = { + name = "${name}-go-modules"; - nativeBuildInputs = [ go git cacert ]; + nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ go git cacert ]; inherit (args) src; inherit (go) GOOS GOARCH; patches = args.patches or []; + preBuild = args.preBuild or ""; + sourceRoot = args.sourceRoot or ""; GO111MODULE = "on"; @@ -64,7 +72,6 @@ let export GOCACHE=$TMPDIR/go-cache export GOPATH="$TMPDIR/go" - mkdir -p "''${GOPATH}/pkg/mod/cache/download" cd "${modRoot}" runHook postConfigure ''; @@ -72,7 +79,16 @@ let buildPhase = args.modBuildPhase or '' runHook preBuild - go mod download + if [ ${deleteFlag} == "true" ]; then + rm -rf vendor + fi + + if [ -e vendor ]; then + echo "vendor folder exists, please set 'vendorSha256=null;' or 'deleteVendor=true;' in your expression" + exit 10 + fi + go mod vendor + mkdir -p vendor runHook postBuild ''; @@ -81,23 +97,19 @@ let runHook preInstall # remove cached lookup results and tiles - rm -rf "''${GOPATH}/pkg/mod/cache/download/sumdb" - cp -r "''${GOPATH}/pkg/mod/cache/download" $out + cp -r --reflink=auto vendor $out runHook postInstall ''; dontFixup = true; }; in modArgs // ( - if modSha256 == null then - { __noChroot = true; } - else { outputHashMode = "recursive"; outputHashAlgo = "sha256"; - outputHash = modSha256; + outputHash = vendorSha256; } - ) // overrideModAttrs modArgs); + ) // overrideModAttrs modArgs) else ""; package = go.stdenv.mkDerivation (args // { nativeBuildInputs = [ removeReferencesTo go ] ++ nativeBuildInputs; @@ -105,6 +117,7 @@ let inherit (go) GOOS GOARCH; GO111MODULE = "on"; + GOFLAGS = "-mod=vendor"; configurePhase = args.configurePhase or '' runHook preConfigure @@ -112,9 +125,12 @@ let export GOCACHE=$TMPDIR/go-cache export GOPATH="$TMPDIR/go" export GOSUMDB=off - export GOPROXY=file://${go-modules} - + export GOPROXY=off cd "$modRoot" + if [ -n "${go-modules}" ]; then + rm -rf vendor + ln -s ${go-modules} vendor + fi runHook postConfigure ''; @@ -210,7 +226,7 @@ let disallowedReferences = lib.optional (!allowGoReference) go; - passthru = passthru // { inherit go go-modules modSha256; }; + passthru = passthru // { inherit go go-modules vendorSha256 ; }; meta = { # Add default meta information @@ -223,5 +239,7 @@ let }); in if disabled then throw "${package.name} not supported for go ${go.meta.branch}" +else if modSha256 != null then + throw "${package.name} should use vendorSha256 not modSha256" else package From 124d70cc9d146738f0342e5a3dbdefecc6902d0b Mon Sep 17 00:00:00 2001 From: Colin L Rice Date: Sat, 2 May 2020 02:22:14 -0400 Subject: [PATCH 12/12] go-modules: Add in old modsha256 w/ warning (removed warning for 20.03) (cherry picked from commit a0ddea1d6a9f07b0631e0dbcd3b7240d2eb82ef7) --- .../go-modules/generic/default.nix | 2 +- pkgs/development/go-modules/generic/old.nix | 229 ++++++++++++++++++ 2 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/go-modules/generic/old.nix diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix index 3184937adaa67..4f36b3fed32cc 100644 --- a/pkgs/development/go-modules/generic/default.nix +++ b/pkgs/development/go-modules/generic/default.nix @@ -240,6 +240,6 @@ let in if disabled then throw "${package.name} not supported for go ${go.meta.branch}" else if modSha256 != null then - throw "${package.name} should use vendorSha256 not modSha256" + (import ./old.nix { inherit go cacert git lib removeReferencesTo stdenv; } args') else package diff --git a/pkgs/development/go-modules/generic/old.nix b/pkgs/development/go-modules/generic/old.nix new file mode 100644 index 0000000000000..42b446b9fa862 --- /dev/null +++ b/pkgs/development/go-modules/generic/old.nix @@ -0,0 +1,229 @@ +{ go, cacert, git, lib, removeReferencesTo, stdenv }: + +{ name ? "${args'.pname}-${args'.version}" +, src +, buildInputs ? [] +, nativeBuildInputs ? [] +, passthru ? {} +, patches ? [] + +# A function to override the go-modules derivation +, overrideModAttrs ? (_oldAttrs : {}) + +# path to go.mod and go.sum directory +, modRoot ? "./" + +# modSha256 is the sha256 of the vendored dependencies +# +# CAUTION: if `null` is used as a value, the derivation won't be a +# fixed-output derivation but disable the build sandbox instead. Don't use +# this in nixpkgs as Hydra won't build those packages. +, modSha256 + +# We want parallel builds by default +, enableParallelBuilding ? true + +# Disabled flag +, disabled ? false + +# Do not enable this without good reason +# IE: programs coupled with the compiler +, allowGoReference ? false + +, meta ? {} + +, ... }@args': + +with builtins; + +let + args = removeAttrs args' [ "overrideModAttrs" "modSha256" "disabled" ]; + + removeReferences = [ ] ++ lib.optional (!allowGoReference) go; + + removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}''; + + go-modules = go.stdenv.mkDerivation (let modArgs = { + name = "${name}-go-modules"; + + nativeBuildInputs = [ go git cacert ]; + + inherit (args) src; + inherit (go) GOOS GOARCH; + + patches = args.patches or []; + + GO111MODULE = "on"; + + impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ + "GIT_PROXY_COMMAND" "SOCKS_SERVER" + ]; + + configurePhase = args.modConfigurePhase or '' + runHook preConfigure + + export GOCACHE=$TMPDIR/go-cache + export GOPATH="$TMPDIR/go" + mkdir -p "''${GOPATH}/pkg/mod/cache/download" + cd "${modRoot}" + runHook postConfigure + ''; + + buildPhase = args.modBuildPhase or '' + runHook preBuild + + go mod download + + runHook postBuild + ''; + + installPhase = args.modInstallPhase or '' + runHook preInstall + + # remove cached lookup results and tiles + rm -rf "''${GOPATH}/pkg/mod/cache/download/sumdb" + cp -r "''${GOPATH}/pkg/mod/cache/download" $out + + runHook postInstall + ''; + + dontFixup = true; + }; in modArgs // ( + if modSha256 == null then + { __noChroot = true; } + else + { + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; + outputHash = modSha256; + } + ) // overrideModAttrs modArgs); + + package = go.stdenv.mkDerivation (args // { + nativeBuildInputs = [ removeReferencesTo go ] ++ nativeBuildInputs; + + inherit (go) GOOS GOARCH; + + GO111MODULE = "on"; + + configurePhase = args.configurePhase or '' + runHook preConfigure + + export GOCACHE=$TMPDIR/go-cache + export GOPATH="$TMPDIR/go" + export GOSUMDB=off + export GOPROXY=file://${go-modules} + + cd "$modRoot" + + runHook postConfigure + ''; + + buildPhase = args.buildPhase or '' + runHook preBuild + + buildGoDir() { + local d; local cmd; + cmd="$1" + d="$2" + . $TMPDIR/buildFlagsArray + echo "$d" | grep -q "\(/_\|examples\|Godeps\|testdata\)" && return 0 + [ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && return 0 + local OUT + if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" -v -p $NIX_BUILD_CORES $d 2>&1)"; then + if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then + echo "$OUT" >&2 + return 1 + fi + fi + if [ -n "$OUT" ]; then + echo "$OUT" >&2 + fi + return 0 + } + + getGoDirs() { + local type; + type="$1" + if [ -n "$subPackages" ]; then + echo "$subPackages" | sed "s,\(^\| \),\1./,g" + else + find . -type f -name \*$type.go -exec dirname {} \; | grep -v "/vendor/" | sort --unique + fi + } + + if (( "''${NIX_DEBUG:-0}" >= 1 )); then + buildFlagsArray+=(-x) + fi + + if [ ''${#buildFlagsArray[@]} -ne 0 ]; then + declare -p buildFlagsArray > $TMPDIR/buildFlagsArray + else + touch $TMPDIR/buildFlagsArray + fi + if [ -z "$enableParallelBuilding" ]; then + export NIX_BUILD_CORES=1 + fi + for pkg in $(getGoDirs ""); do + echo "Building subPackage $pkg" + buildGoDir install "$pkg" + done + '' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' + # normalize cross-compiled builds w.r.t. native builds + ( + dir=$GOPATH/bin/${go.GOOS}_${go.GOARCH} + if [[ -n "$(shopt -s nullglob; echo $dir/*)" ]]; then + mv $dir/* $dir/.. + fi + if [[ -d $dir ]]; then + rmdir $dir + fi + ) + '' + '' + runHook postBuild + ''; + + doCheck = args.doCheck or false; + checkPhase = args.checkPhase or '' + runHook preCheck + + for pkg in $(getGoDirs test); do + buildGoDir test "$pkg" + done + + runHook postCheck + ''; + + installPhase = args.installPhase or '' + runHook preInstall + + mkdir -p $out + dir="$GOPATH/bin" + [ -e "$dir" ] && cp -r $dir $out + + runHook postInstall + ''; + + preFixup = (args.preFixup or "") + '' + find $out/bin -type f -exec ${removeExpr removeReferences} '{}' + || true + ''; + + strictDeps = true; + + disallowedReferences = lib.optional (!allowGoReference) go; + + passthru = passthru // { inherit go go-modules modSha256; }; + + meta = { + # Add default meta information + platforms = go.meta.platforms or lib.platforms.all; + } // meta // { + # add an extra maintainer to every package + maintainers = (meta.maintainers or []) ++ + [ lib.maintainers.kalbasit ]; + }; + }); +in if disabled then + throw "${package.name} not supported for go ${go.meta.branch}" +else + package