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