about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/go-modules/generic/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/go-modules/generic/default.nix')
-rw-r--r--nixpkgs/pkgs/development/go-modules/generic/default.nix39
1 files changed, 33 insertions, 6 deletions
diff --git a/nixpkgs/pkgs/development/go-modules/generic/default.nix b/nixpkgs/pkgs/development/go-modules/generic/default.nix
index cda43ebf0ed6..ff6df85e5ae9 100644
--- a/nixpkgs/pkgs/development/go-modules/generic/default.nix
+++ b/nixpkgs/pkgs/development/go-modules/generic/default.nix
@@ -12,6 +12,9 @@ let
     # Go linker flags, passed to go via -ldflags
     , ldflags ? []
 
+    # Go tags, passed to go via -tag
+    , tags ? []
+
     # A function to override the go-modules derivation
     , overrideModAttrs ? (_oldAttrs : {})
 
@@ -28,6 +31,10 @@ let
     # Whether to run the vend tool to regenerate the vendor directory.
     # This is useful if any dependency contain C files.
     , runVend ? false
+    # Whether to fetch (go mod download) and proxy the vendor directory.
+    # This is useful if any dependency has case-insensitive conflicts
+    # which will produce platform dependant `vendorSha256` checksums.
+    , proxyVendor ? false
 
     # We want parallel builds by default
     , enableParallelBuilding ? true
@@ -41,10 +48,16 @@ let
     # Not needed with buildGoModule
     , goPackagePath ? ""
 
+    # needed for buildFlags{,Array} warning
+    , buildFlags ? ""
+    , buildFlagsArray ? ""
+
     , ... }@args':
 
     with builtins;
 
+    assert (runVend == true && proxyVendor == true) -> throw "can't use `runVend` and `proxyVendor` together";
+
     assert goPackagePath != "" -> throw "`goPackagePath` is not needed with `buildGoModule`";
 
     let
@@ -96,6 +109,9 @@ let
         ${if runVend then ''
           echo "running 'vend' to rewrite vendor folder"
           ${vend}/bin/vend
+        '' else if proxyVendor then ''
+          mkdir -p "''${GOPATH}/pkg/mod/cache/download"
+          go mod download
         '' else ''
           go mod vendor
         ''}
@@ -108,8 +124,12 @@ let
         installPhase = args.modInstallPhase or ''
           runHook preInstall
 
-          # remove cached lookup results and tiles
+        ${if proxyVendor then ''
+          rm -rf "''${GOPATH}/pkg/mod/cache/download/sumdb"
+          cp -r --reflink=auto "''${GOPATH}/pkg/mod/cache/download" $out
+        '' else ''
           cp -r --reflink=auto vendor $out
+        ''}
 
           runHook postInstall
         '';
@@ -129,7 +149,7 @@ let
         inherit (go) GOOS GOARCH;
 
         GO111MODULE = "on";
-        GOFLAGS = [ "-mod=vendor" ] ++ lib.optionals (!allowGoReference) [ "-trimpath" ];
+        GOFLAGS = lib.optionals (!proxyVendor) [ "-mod=vendor" ] ++ lib.optionals (!allowGoReference) [ "-trimpath" ];
 
         configurePhase = args.configurePhase or ''
           runHook preConfigure
@@ -137,11 +157,15 @@ let
           export GOCACHE=$TMPDIR/go-cache
           export GOPATH="$TMPDIR/go"
           export GOSUMDB=off
-          export GOPROXY=off
           cd "$modRoot"
         '' + lib.optionalString (go-modules != "") ''
-          rm -rf vendor
-          cp -r --reflink=auto ${go-modules} vendor
+          ${if proxyVendor then ''
+            export GOPROXY=file://${go-modules}
+          '' else ''
+            export GOPROXY=off
+            rm -rf vendor
+            cp -r --reflink=auto ${go-modules} vendor
+          ''}
         '' + ''
 
           runHook postConfigure
@@ -158,7 +182,7 @@ let
             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[@]}" ''${ldflags:+-ldflags="$ldflags"} -v -p $NIX_BUILD_CORES $d 2>&1)"; then
+            if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" ''${tags:+-tags=${lib.concatStringsSep "," tags}} ''${ldflags:+-ldflags="$ldflags"} -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
@@ -252,6 +276,9 @@ let
         overrideGoAttrs = f: buildGoPackage (args' // (f args'));
       };
     in
+    lib.warnIf (buildFlags != "" || buildFlagsArray != "")
+      "Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`"
       package;
 in
   buildGoPackage
+