Added support for private github repositories

This commit is contained in:
Nick Van den Broeck 2019-04-10 12:12:44 +02:00
parent b4e367bf4a
commit b3d33b02e3
2 changed files with 7 additions and 2 deletions

View file

@ -226,13 +226,15 @@ static FlakeSourceInfo fetchFlake(EvalState & state, const FlakeRef flakeRef, bo
// FIXME: use regular /archive URLs instead? api.github.com
// might have stricter rate limits.
// FIXME: support passing auth tokens for private repos.
auto url = fmt("https://api.github.com/repos/%s/%s/tarball/%s",
refData->owner, refData->repo,
fRef.rev ? fRef.rev->to_string(Base16, false)
: fRef.ref ? *fRef.ref : "master");
std::string accessToken = settings.githubAccessToken.get();
if (accessToken != "")
url += "?access_token=" + accessToken;
auto result = getDownloader()->downloadCached(state.store, url, true, "source",
Hash(), nullptr, fRef.rev ? 1000000000 : settings.tarballTtl);

View file

@ -344,6 +344,9 @@ public:
Setting<Paths> pluginFiles{this, {}, "plugin-files",
"Plugins to dynamically load at nix initialization time."};
Setting<std::string> githubAccessToken{this, "", "github-acces-token",
"GitHub access token to get access to GitHub data through the GitHub API for github:<..> flakes."};
};