Support channel:<channel-name> URIs
For convenience, you can now say $ nix-env -f channel:nixos-16.03 -iA hello instead of $ nix-env -f https://nixos.org/channels/nixos-16.03/nixexprs.tar.xz -iA hello Similarly, $ nix-shell -I channel:nixpkgs-unstable -p hello $ nix-build channel:nixos-15.09 -A hello Abstracting over the NixOS/Nixpkgs channels location also allows us to use a more efficient transport (e.g. Git) in the future.
This commit is contained in:
parent
363f37d084
commit
c045630522
1 changed files with 14 additions and 5 deletions
|
@ -18,6 +18,14 @@ double getTime()
|
||||||
return tv.tv_sec + (tv.tv_usec / 1000000.0);
|
return tv.tv_sec + (tv.tv_usec / 1000000.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string resolveUri(const std::string & uri)
|
||||||
|
{
|
||||||
|
if (uri.compare(0, 8, "channel:") == 0)
|
||||||
|
return "https://nixos.org/channels/" + std::string(uri, 8) + "/nixexprs.tar.xz";
|
||||||
|
else
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
struct CurlDownloader : public Downloader
|
struct CurlDownloader : public Downloader
|
||||||
{
|
{
|
||||||
CURL * curl;
|
CURL * curl;
|
||||||
|
@ -197,7 +205,7 @@ struct CurlDownloader : public Downloader
|
||||||
DownloadResult download(string url, const DownloadOptions & options) override
|
DownloadResult download(string url, const DownloadOptions & options) override
|
||||||
{
|
{
|
||||||
DownloadResult res;
|
DownloadResult res;
|
||||||
if (fetch(url, options)) {
|
if (fetch(resolveUri(url), options)) {
|
||||||
res.cached = false;
|
res.cached = false;
|
||||||
res.data = data;
|
res.data = data;
|
||||||
} else
|
} else
|
||||||
|
@ -207,15 +215,15 @@ struct CurlDownloader : public Downloader
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ref<Downloader> makeDownloader()
|
ref<Downloader> makeDownloader()
|
||||||
{
|
{
|
||||||
return make_ref<CurlDownloader>();
|
return make_ref<CurlDownloader>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpack)
|
||||||
Path Downloader::downloadCached(ref<Store> store, const string & url, bool unpack)
|
|
||||||
{
|
{
|
||||||
|
auto url = resolveUri(url_);
|
||||||
|
|
||||||
Path cacheDir = getEnv("XDG_CACHE_HOME", getEnv("HOME", "") + "/.cache") + "/nix/tarballs";
|
Path cacheDir = getEnv("XDG_CACHE_HOME", getEnv("HOME", "") + "/.cache") + "/nix/tarballs";
|
||||||
createDirs(cacheDir);
|
createDirs(cacheDir);
|
||||||
|
|
||||||
|
@ -300,10 +308,11 @@ Path Downloader::downloadCached(ref<Store> store, const string & url, bool unpac
|
||||||
|
|
||||||
bool isUri(const string & s)
|
bool isUri(const string & s)
|
||||||
{
|
{
|
||||||
|
if (s.compare(0, 8, "channel:") == 0) return true;
|
||||||
size_t pos = s.find("://");
|
size_t pos = s.find("://");
|
||||||
if (pos == string::npos) return false;
|
if (pos == string::npos) return false;
|
||||||
string scheme(s, 0, pos);
|
string scheme(s, 0, pos);
|
||||||
return scheme == "http" || scheme == "https" || scheme == "file";
|
return scheme == "http" || scheme == "https" || scheme == "file" || scheme == "channel";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue