From 7cdaae6b9cc3ef5b64bbd7fd2776fa5e7572aa8d Mon Sep 17 00:00:00 2001 From: Viktor Kronvall Date: Thu, 29 Jul 2021 01:44:19 +0900 Subject: [PATCH] Support SCP-like URLs in builtins.fetchGit attrs This extends https://github.com/NixOS/nix/pull/4978 with supporting the SCP-like urls in expressions like ```nix builtins.fetchGit { url = "git@github.com:NixOS/nix.git"; ref = "master"; } ``` --- src/libexpr/primops/fetchTree.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc index 730db84ed..9ffd1c856 100644 --- a/src/libexpr/primops/fetchTree.cc +++ b/src/libexpr/primops/fetchTree.cc @@ -76,10 +76,24 @@ std::string fixURIForGit(std::string uri, EvalState & state) return fixURI(uri, state); } -void addURI(EvalState &state, fetchers::Attrs &attrs, Symbol name, std::string v) -{ +void addURI( + EvalState &state, + fetchers::Attrs &attrs, + Symbol name, + std::string v, + const std::optional type +) { string n(name); - attrs.emplace(name, n == "url" ? fixURI(v, state) : v); + if (n == "url") { + if (type == "git") { + attrs.emplace("type", "git"); + attrs.emplace(name, fixURIForGit(v, state)); + } else { + attrs.emplace(name, fixURI(v, state)); + } + } else { + attrs.emplace(name, v); + } } struct FetchTreeParams { @@ -112,10 +126,9 @@ static void fetchTree( state, attrs, attr.name, - state.coerceToString(*attr.pos, *attr.value, context, false, false) + state.coerceToString(*attr.pos, *attr.value, context, false, false), + type ); - else if (attr.value->type() == nString) - addURI(state, attrs, attr.name, attr.value->string.s); else if (attr.value->type() == nBool) attrs.emplace(attr.name, Explicit{attr.value->boolean}); else if (attr.value->type() == nInt)