diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-09-12 15:37:09 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2022-12-12 14:05:35 +0100 |
commit | ae5f62a894190e0075eb60ae4537ba81ca2a0a8d (patch) | |
tree | d6b3d856a8c7b6e4e32d54b3f1c3f0cc5b2d2d3c /src/libexpr/eval.cc | |
parent | 7396844676651ea8ee017b9c7578581c5885e0f9 (diff) |
Move isUri() and resolveUri() out of filetransfer.cc
These are purely related to NIX_PATH / -I command line parsing, so put
them in libexpr.
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r-- | src/libexpr/eval.cc | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index b67ed853e..ca8d634da 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -402,7 +402,7 @@ static Strings parseNixPath(const std::string & s) } if (*p == ':') { - if (isUri(std::string(start2, s.end()))) { + if (EvalSettings::isPseudoUrl(std::string(start2, s.end()))) { ++p; while (p != s.end() && *p != ':') ++p; } @@ -2583,6 +2583,23 @@ Strings EvalSettings::getDefaultNixPath() return res; } +bool EvalSettings::isPseudoUrl(std::string_view s) +{ + if (s.compare(0, 8, "channel:") == 0) return true; + size_t pos = s.find("://"); + if (pos == std::string::npos) return false; + std::string scheme(s, 0, pos); + return scheme == "http" || scheme == "https" || scheme == "file" || scheme == "channel" || scheme == "git" || scheme == "s3" || scheme == "ssh"; +} + +std::string EvalSettings::resolvePseudoUrl(std::string_view url) +{ + if (hasPrefix(url, "channel:")) + return "https://nixos.org/channels/" + std::string(url.substr(8)) + "/nixexprs.tar.xz"; + else + return std::string(url); +} + EvalSettings evalSettings; static GlobalConfig::Register rEvalSettings(&evalSettings); |