diff options
author | Colin L Rice <colin@daedrum.net> | 2020-04-29 23:08:21 -0400 |
---|---|---|
committer | Jörg Thalheim <joerg@thalheim.io> | 2020-05-14 07:21:49 +0100 |
commit | 9761128d2da7bf4d878982918242e43ae28f9b94 (patch) | |
tree | 121512b295fb0f8b1b0150a6817e3c19a0223d74 /pkgs/development/go-modules | |
parent | ce9ed9baed6e8761ac83e5c86f340195bc856395 (diff) | |
download | nixpkgs-9761128d2da7bf4d878982918242e43ae28f9b94.tar nixpkgs-9761128d2da7bf4d878982918242e43ae28f9b94.tar.gz nixpkgs-9761128d2da7bf4d878982918242e43ae28f9b94.tar.bz2 nixpkgs-9761128d2da7bf4d878982918242e43ae28f9b94.tar.lz nixpkgs-9761128d2da7bf4d878982918242e43ae28f9b94.tar.xz nixpkgs-9761128d2da7bf4d878982918242e43ae28f9b94.tar.zst nixpkgs-9761128d2da7bf4d878982918242e43ae28f9b94.zip |
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.
Diffstat (limited to 'pkgs/development/go-modules')
-rw-r--r-- | pkgs/development/go-modules/generic/default.nix | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix index 42b446b9fa8..dc4958bfadd 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 ''; @@ -212,7 +228,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 @@ -225,5 +241,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 |