2015-07-20 04:30:16 +02:00
|
|
|
|
#include "builtins.hh"
|
|
|
|
|
#include "download.hh"
|
2015-10-30 11:27:47 +01:00
|
|
|
|
#include "store-api.hh"
|
|
|
|
|
#include "archive.hh"
|
2015-07-20 04:30:16 +02:00
|
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
void builtinFetchurl(const BasicDerivation & drv)
|
|
|
|
|
{
|
|
|
|
|
auto url = drv.env.find("url");
|
|
|
|
|
if (url == drv.env.end()) throw Error("attribute ‘url’ missing");
|
2015-10-21 14:59:01 +02:00
|
|
|
|
|
|
|
|
|
/* No need to do TLS verification, because we check the hash of
|
|
|
|
|
the result anyway. */
|
|
|
|
|
DownloadOptions options;
|
|
|
|
|
options.verifyTLS = false;
|
|
|
|
|
|
2015-10-21 15:03:29 +02:00
|
|
|
|
/* Show a progress indicator, even though stderr is not a tty. */
|
|
|
|
|
options.forceProgress = true;
|
|
|
|
|
|
|
|
|
|
auto data = downloadFile(url->second, options);
|
2015-07-20 04:30:16 +02:00
|
|
|
|
|
|
|
|
|
auto out = drv.env.find("out");
|
|
|
|
|
if (out == drv.env.end()) throw Error("attribute ‘url’ missing");
|
2015-10-30 11:27:47 +01:00
|
|
|
|
|
|
|
|
|
Path storePath = out->second;
|
|
|
|
|
assertStorePath(storePath);
|
|
|
|
|
|
|
|
|
|
auto unpack = drv.env.find("unpack");
|
|
|
|
|
if (unpack != drv.env.end() && unpack->second == "1") {
|
|
|
|
|
StringSource source(data.data);
|
|
|
|
|
restorePath(storePath, source);
|
|
|
|
|
} else
|
|
|
|
|
writeFile(storePath, data.data);
|
2015-07-20 04:30:16 +02:00
|
|
|
|
|
2015-07-23 22:25:04 +02:00
|
|
|
|
auto executable = drv.env.find("executable");
|
2015-07-20 04:30:16 +02:00
|
|
|
|
if (executable != drv.env.end() && executable->second == "1") {
|
2015-10-30 11:27:47 +01:00
|
|
|
|
if (chmod(storePath.c_str(), 0755) == -1)
|
|
|
|
|
throw SysError(format("making ‘%1%’ executable") % storePath);
|
2015-07-20 04:30:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|