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-10-30 12:33:40 +01:00
|
|
|
|
#include "compression.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. */
|
2016-02-29 18:15:20 +01:00
|
|
|
|
options.showProgress = DownloadOptions::yes;
|
2015-10-21 15:03:29 +02:00
|
|
|
|
|
2016-02-29 18:15:20 +01:00
|
|
|
|
auto data = makeDownloader()->download(url->second, options);
|
2016-04-15 15:11:34 +02:00
|
|
|
|
assert(data.data);
|
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") {
|
2016-04-15 15:11:34 +02:00
|
|
|
|
if (string(*data.data, 0, 6) == string("\xfd" "7zXZ\0", 6))
|
|
|
|
|
data.data = decompressXZ(*data.data);
|
|
|
|
|
StringSource source(*data.data);
|
2015-10-30 11:27:47 +01:00
|
|
|
|
restorePath(storePath, source);
|
|
|
|
|
} else
|
2016-04-15 15:11:34 +02:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|