diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2021-10-06 17:39:02 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2021-10-06 17:39:02 +0200 |
commit | 57a8eb4c018ff69304835b0bbbfd01294df07058 (patch) | |
tree | dad5575f52644c52cbfd6745441a970c690cfdad /src | |
parent | 83d86cc1b007fc9cac5e9fd64a211cf8d78c9365 (diff) |
fetchTree(): Parse type attribute first
The 'url' attribute depends on whether type == 'git', so this is needed for
builtins.fetchTree {url = "git@github.com:NixOS/nix.git"; type = "git";}
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/primops/fetchTree.cc | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc index d598febbe..1a69fe4e4 100644 --- a/src/libexpr/primops/fetchTree.cc +++ b/src/libexpr/primops/fetchTree.cc @@ -91,7 +91,7 @@ static void fetchTree( const Pos & pos, Value * * args, Value & v, - const std::optional<std::string> & type, + std::optional<std::string> type, const FetchTreeParams & params = FetchTreeParams{} ) { fetchers::Input input; @@ -104,7 +104,23 @@ static void fetchTree( fetchers::Attrs attrs; + if (auto aType = args[0]->attrs->get(state.sType)) { + if (type) + throw Error({ + .msg = hintfmt("unexpected attribute 'type'"), + .errPos = pos + }); + type = state.forceStringNoCtx(*aType->value, *aType->pos); + } else if (!type) + throw Error({ + .msg = hintfmt("attribute 'type' is missing in call to 'fetchTree'"), + .errPos = pos + }); + + attrs.emplace("type", type.value()); + for (auto & attr : *args[0]->attrs) { + if (attr.name == state.sType) continue; state.forceValue(*attr.value); if (attr.value->type() == nPath || attr.value->type() == nString) { auto s = state.coerceToString(*attr.pos, *attr.value, context, false, false); @@ -124,15 +140,6 @@ static void fetchTree( attr.name, showType(*attr.value)); } - if (type) - attrs.emplace("type", type.value()); - - if (!attrs.count("type")) - throw Error({ - .msg = hintfmt("attribute 'type' is missing in call to 'fetchTree'"), - .errPos = pos - }); - if (!params.allowNameArgument) if (auto nameIter = attrs.find("name"); nameIter != attrs.end()) throw Error({ |