2015-07-20 05:30:16 +03:00
|
|
|
|
#include "builtins.hh"
|
|
|
|
|
#include "download.hh"
|
2015-10-30 12:27:47 +02:00
|
|
|
|
#include "store-api.hh"
|
|
|
|
|
#include "archive.hh"
|
2015-10-30 13:33:40 +02:00
|
|
|
|
#include "compression.hh"
|
2015-07-20 05:30:16 +03: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 15:59:01 +03:00
|
|
|
|
|
|
|
|
|
/* No need to do TLS verification, because we check the hash of
|
|
|
|
|
the result anyway. */
|
|
|
|
|
DownloadOptions options;
|
|
|
|
|
options.verifyTLS = false;
|
|
|
|
|
|
2015-10-21 16:03:29 +03:00
|
|
|
|
/* Show a progress indicator, even though stderr is not a tty. */
|
2016-02-29 19:15:20 +02:00
|
|
|
|
options.showProgress = DownloadOptions::yes;
|
2015-10-21 16:03:29 +03:00
|
|
|
|
|
2016-02-29 19:15:20 +02:00
|
|
|
|
auto data = makeDownloader()->download(url->second, options);
|
2016-04-15 16:11:34 +03:00
|
|
|
|
assert(data.data);
|
2015-07-20 05:30:16 +03:00
|
|
|
|
|
|
|
|
|
auto out = drv.env.find("out");
|
2016-06-01 17:56:22 +03:00
|
|
|
|
if (out == drv.env.end()) throw Error("attribute ‘out’ missing");
|
2015-10-30 12:27:47 +02:00
|
|
|
|
|
|
|
|
|
Path storePath = out->second;
|
|
|
|
|
|
|
|
|
|
auto unpack = drv.env.find("unpack");
|
|
|
|
|
if (unpack != drv.env.end() && unpack->second == "1") {
|
2016-04-15 16:11:34 +03:00
|
|
|
|
if (string(*data.data, 0, 6) == string("\xfd" "7zXZ\0", 6))
|
2016-05-04 14:36:54 +03:00
|
|
|
|
data.data = decompress("xz", *data.data);
|
2016-04-15 16:11:34 +03:00
|
|
|
|
StringSource source(*data.data);
|
2015-10-30 12:27:47 +02:00
|
|
|
|
restorePath(storePath, source);
|
|
|
|
|
} else
|
2016-04-15 16:11:34 +03:00
|
|
|
|
writeFile(storePath, *data.data);
|
2015-07-20 05:30:16 +03:00
|
|
|
|
|
2015-07-23 23:25:04 +03:00
|
|
|
|
auto executable = drv.env.find("executable");
|
2015-07-20 05:30:16 +03:00
|
|
|
|
if (executable != drv.env.end() && executable->second == "1") {
|
2015-10-30 12:27:47 +02:00
|
|
|
|
if (chmod(storePath.c_str(), 0755) == -1)
|
|
|
|
|
throw SysError(format("making ‘%1%’ executable") % storePath);
|
2015-07-20 05:30:16 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|