diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-05-06T12·54+0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-05-06T12·54+0200 |
commit | 6519f06f397448c3f1677e87e385012e2507164b (patch) | |
tree | d09ef46afe5e8a60b84def346a14b696ecdf1a3d /src | |
parent | 0705d04dfab60b0c98fbd170b9cc3fcd073918bb (diff) |
nix-env/nix-instantiate/nix-build: Support URIs
For instance, you can install Firefox from a specific Nixpkgs revision like this: $ nix-env -f https://github.com/NixOS/nixpkgs/archive/63def04891a0abc328b1b0b3a78ec02c58f48583.tar.gz -iA firefox Or build a package from the latest nixpkgs-unstable channel: $ nix-build https://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz -A hello
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/common-opts.cc | 7 | ||||
-rw-r--r-- | src/libexpr/download.cc | 9 | ||||
-rw-r--r-- | src/libexpr/download.hh | 2 | ||||
-rw-r--r-- | src/libexpr/parser.y | 9 | ||||
-rw-r--r-- | src/nix-instantiate/nix-instantiate.cc | 6 |
5 files changed, 19 insertions, 14 deletions
diff --git a/src/libexpr/common-opts.cc b/src/libexpr/common-opts.cc index c03d720bde82..13760490d9c4 100644 --- a/src/libexpr/common-opts.cc +++ b/src/libexpr/common-opts.cc @@ -1,5 +1,6 @@ #include "common-opts.hh" -#include "../libmain/shared.hh" +#include "shared.hh" +#include "download.hh" #include "util.hh" @@ -53,7 +54,9 @@ bool parseSearchPathArg(Strings::iterator & i, Path lookupFileArg(EvalState & state, string s) { - if (s.size() > 2 && s.at(0) == '<' && s.at(s.size() - 1) == '>') { + if (isUri(s)) + return downloadFileCached(s, true); + else if (s.size() > 2 && s.at(0) == '<' && s.at(s.size() - 1) == '>') { Path p = s.substr(1, s.size() - 2); return state.findFile(p); } else diff --git a/src/libexpr/download.cc b/src/libexpr/download.cc index e3c6c505c543..18ab6fbcda73 100644 --- a/src/libexpr/download.cc +++ b/src/libexpr/download.cc @@ -223,4 +223,13 @@ Path downloadFileCached(const string & url, bool unpack) } +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"; +} + + } diff --git a/src/libexpr/download.hh b/src/libexpr/download.hh index 36fa183d68f9..28c9117e4227 100644 --- a/src/libexpr/download.hh +++ b/src/libexpr/download.hh @@ -17,4 +17,6 @@ Path downloadFileCached(const string & url, bool unpack); MakeError(DownloadError, Error) +bool isUri(const string & s); + } diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index e3f2f09b20bd..26168b2ed420 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -601,15 +601,6 @@ 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('='); diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc index 973a34ec1495..bea04180e513 100644 --- a/src/nix-instantiate/nix-instantiate.cc +++ b/src/nix-instantiate/nix-instantiate.cc @@ -183,10 +183,10 @@ int main(int argc, char * * argv) } else if (files.empty() && !fromArgs) files.push_back("./default.nix"); - foreach (Strings::iterator, i, files) { + for (auto & i : files) { Expr * e = fromArgs - ? state.parseExprFromString(*i, absPath(".")) - : state.parseExprFromFile(resolveExprPath(lookupFileArg(state, *i))); + ? state.parseExprFromString(i, absPath(".")) + : state.parseExprFromFile(resolveExprPath(lookupFileArg(state, i))); processExpr(state, attrPaths, parseOnly, strict, autoArgs, evalOnly, outputKind, xmlOutputSourceLocation, e); } |