mirror of
https://github.com/NixOS/nix
synced 2025-06-28 17:51:15 +02:00
Allow URLs in the Nix search path
E.g. to install "hello" from the latest Nixpkgs:
$ nix-build '<nixpkgs>' -A hello -I nixpkgs=https://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz
Or to install a specific version of NixOS:
$ nixos-rebuild switch -I nixpkgs=63def04891
.tar.gz
This commit is contained in:
parent
35d30d67eb
commit
9451ef3731
6 changed files with 123 additions and 99 deletions
|
@ -527,6 +527,8 @@ formal
|
|||
#include <unistd.h>
|
||||
|
||||
#include <eval.hh>
|
||||
#include <download.hh>
|
||||
#include <store-api.hh>
|
||||
|
||||
|
||||
namespace nix {
|
||||
|
@ -599,6 +601,15 @@ Expr * EvalState::parseExprFromString(const string & s, const Path & basePath)
|
|||
}
|
||||
|
||||
|
||||
bool isUri(const string & s)
|
||||
{
|
||||
size_t pos = s.find("://");
|
||||
if (pos == string::npos) return false;
|
||||
string scheme(s, 0, pos);
|
||||
return scheme == "http" || scheme == "https";
|
||||
}
|
||||
|
||||
|
||||
void EvalState::addToSearchPath(const string & s, bool warn)
|
||||
{
|
||||
size_t pos = s.find('=');
|
||||
|
@ -611,6 +622,9 @@ void EvalState::addToSearchPath(const string & s, bool warn)
|
|||
path = string(s, pos + 1);
|
||||
}
|
||||
|
||||
if (isUri(path))
|
||||
path = downloadFileCached(path, true);
|
||||
|
||||
path = absPath(path);
|
||||
if (pathExists(path)) {
|
||||
debug(format("adding path ‘%1%’ to the search path") % path);
|
||||
|
@ -629,16 +643,17 @@ Path EvalState::findFile(const string & path)
|
|||
|
||||
Path EvalState::findFile(SearchPath & searchPath, const string & path, const Pos & pos)
|
||||
{
|
||||
foreach (SearchPath::iterator, i, searchPath) {
|
||||
for (auto & i : searchPath) {
|
||||
assert(!isUri(i.second));
|
||||
Path res;
|
||||
if (i->first.empty())
|
||||
res = i->second + "/" + path;
|
||||
if (i.first.empty())
|
||||
res = i.second + "/" + path;
|
||||
else {
|
||||
if (path.compare(0, i->first.size(), i->first) != 0 ||
|
||||
(path.size() > i->first.size() && path[i->first.size()] != '/'))
|
||||
if (path.compare(0, i.first.size(), i.first) != 0 ||
|
||||
(path.size() > i.first.size() && path[i.first.size()] != '/'))
|
||||
continue;
|
||||
res = i->second +
|
||||
(path.size() == i->first.size() ? "" : "/" + string(path, i->first.size()));
|
||||
res = i.second +
|
||||
(path.size() == i.first.size() ? "" : "/" + string(path, i.first.size()));
|
||||
}
|
||||
if (pathExists(res)) return canonPath(res);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue