Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nlewo committed Jun 4, 2020
1 parent c7eb16c commit 09ac010
Show file tree
Hide file tree
Showing 5 changed files with 2,575 additions and 5 deletions.
52 changes: 47 additions & 5 deletions pkgs/development/go-modules/generic/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ go, cacert, git, lib, removeReferencesTo, stdenv }:
{ go, cacert, git, lib, removeReferencesTo, stdenv, runCommand, fetchgit, rsync }:

{ name ? "${args'.pname}-${args'.version}"
, src
Expand All @@ -23,6 +23,8 @@

, modSha256 ? null

, goDeps ? null

# We want parallel builds by default
, enableParallelBuilding ? true

Expand All @@ -48,6 +50,48 @@ let

deleteFlag = if deleteVendor then "true" else "false";

dep2src = goDep:
{
inherit (goDep) goPackagePath;
src = if goDep.fetch.type == "git" then
fetchgit {
inherit (goDep.fetch) url rev sha256;
}
else if goDep.fetch.type == "hg" then
fetchhg {
inherit (goDep.fetch) url rev sha256;
}
else if goDep.fetch.type == "bzr" then
fetchbzr {
inherit (goDep.fetch) url rev sha256;
}
else if goDep.fetch.type == "FromGitHub" then
fetchFromGitHub {
inherit (goDep.fetch) owner repo rev sha256;
}
else abort "Unrecognized package fetch type: ${goDep.fetch.type}";
};

importGodeps = { depsFile }:
map dep2src (import depsFile);

go-modules-from-godeps = let
vendorize = {src, goPackagePath}: ''
mkdir -p $(dirname $out/${goPackagePath})
# rsync -a ${src}/ $out/${goPackagePath}
# chmod u+w -R $out/${goPackagePath}
# Create the directory tree
find ${src} -name "*.go" -printf "%P\n" | xargs dirname | sort | uniq | xargs -I {} mkdir -p $out/${goPackagePath}/{}
# Link all go files to these directories
find ${src} -name "*.go" -printf "%P\n" | xargs -I {} ln -sf ${src}/{} $out/${goPackagePath}/{}

This comment has been minimized.

Copy link
@blaggacao

blaggacao Nov 2, 2020

Did you consider https://github.com/go-modules-by-example/index/blob/master/012_modvendor/README.md?

It seems to me as if the proposed approach would:

  • not load any non-go files of a package
  • not load any subfolders that go mod vendor currently doesn't load neither which is the topic addressed by the above document.
'';
in runCommand "${name}-go-modules-from-godeps" { buildInputs = [ rsync ];} (''
mkdir $out
'' + (lib.concatMapStringsSep "\n" vendorize (importGodeps { depsFile = goDeps; })
)

);

go-modules = if vendorSha256 != null then go.stdenv.mkDerivation (let modArgs = {

name = "${name}-go-modules";
Expand Down Expand Up @@ -127,10 +171,8 @@ let
export GOSUMDB=off
export GOPROXY=off
cd "$modRoot"
if [ -n "${go-modules}" ]; then
rm -rf vendor
ln -s ${go-modules} vendor
fi
rm -rf vendor
ln -s ${go-modules-from-godeps} vendor
runHook postConfigure
'';
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/tools/cue/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ buildGoModule rec {
sha256 = "06kag5dwkq4zsh1b52b74g3slsxlwwiap2w3709qjhrgda8w2zn3";
};

goDeps = ./deps.nix;
vendorSha256 = "1lhjd98n9j1cq36b5lhscb7k32qmyqg7zs6zc8yab494bm8sz89g";

subPackages = [ "cmd/cue" ];
Expand Down
Loading

0 comments on commit 09ac010

Please sign in to comment.