1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-30 15:48:00 +02:00

Support netrc in <nix/fetchurl.nix>

This allows <nix/fetchurl.nix> to fetch private Git/Mercurial
repositories, e.g.

  import <nix/fetchurl.nix> {
    url = 80a14018da.tar.bz2;
    sha256 = "1mgqzn7biqkq3hf2697b0jc4wabkqhmzq2srdymjfa6sb9zb6qs7";
  }

where /etc/nix/netrc contains:

  machine bitbucket.org
  login edolstra
  password blabla...

This works even when sandboxing is enabled.

To do: add unpacking support (i.e. fetchzip functionality).
This commit is contained in:
Eelco Dolstra 2017-02-16 15:42:49 +01:00
parent cde4b60919
commit 302386f775
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
5 changed files with 25 additions and 7 deletions

View file

@ -2307,6 +2307,14 @@ void DerivationGoal::runChild()
bool setUser = true;
/* Make the contents of netrc available to builtin:fetchurl
(which may run under a different uid and/or in a sandbox). */
std::string netrcData;
try {
if (drv->isBuiltin() && drv->builder == "builtin:fetchurl")
netrcData = readFile(settings.netrcFile);
} catch (SysError &) { }
#if __linux__
if (useChroot) {
@ -2675,7 +2683,7 @@ void DerivationGoal::runChild()
if (drv->isBuiltin()) {
try {
if (drv->builder == "builtin:fetchurl")
builtinFetchurl(*drv);
builtinFetchurl(*drv, netrcData);
else
throw Error(format("unsupported builtin function %1%") % string(drv->builder, 8));
_exit(0);
@ -3072,7 +3080,9 @@ void DerivationGoal::closeLogFile()
void DerivationGoal::deleteTmpDir(bool force)
{
if (tmpDir != "") {
if (settings.keepFailed && !force) {
/* Don't keep temporary directories for builtins because they
might have privileged stuff (like a copy of netrc). */
if (settings.keepFailed && !force && !drv->isBuiltin()) {
printError(
format("note: keeping build directory %2%")
% drvPath % tmpDir);