I’m trying to download a private go repo files from GitHub, then build and run a program from one of the directories.
Here’s my nix file:
{ stdenv, config, lib, pkgs, fetchurl, buildGoModule, ... }:
let commit = "fffffffffffffffffffffffffffffffffffffffff";
in let token = "ffffffffffffffffffffffffffffffffffffffff";
in let
github = fetchurl {
url =
"https://api.github.com/repos/my_project/my_repo/tarball/${commit}?access_token=${token}";
sha256 = "fffffffffffffffffffffffffffffffffffffffff";
name = "my_repo.tar.gz";
};
in let
derivative = pkgs.runCommand "derivative" { } ''
mkdir $out
mkdir /tmp/junk
tar -zxf ${github} -C /tmp/junk --strip-components=2
# mv everything correct
find $out
'';
in buildGoModule rec {
name = "main-project";
version = "2";
src = "${derivative}";
modSha256 = "16vbps22dg50i25f6rwc82cvdhdk71i281a9v00wsa21g7bca4pa";
}
So I get …
/nix/store/ymx8gs5z7z4h4andrgg5iy0gxr6v53wd-derivative
/nix/store/ymx8gs5z7z4h4andrgg5iy0gxr6v53wd-derivative/mainFile.go
/nix/store/ymx8gs5z7z4h4andrgg5iy0gxr6v53wd-derivative/go.mod
/nix/store/ymx8gs5z7z4h4andrgg5iy0gxr6v53wd-derivative/go.sum
…
building ‘…’
…
unpacking sources
unpacking source archive …
source root is derivative
patching sources
configuring
building
installing
cp: cannot stat '/build/go/pkg/mod/cache/download': No such file or directory
What I don’t understand is if I clone that repo on my main system, cd into that directory and run go build .
, everything works. Why doesn’t this work?