From 57a8eb4c018ff69304835b0bbbfd01294df07058 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 6 Oct 2021 17:39:02 +0200 Subject: [PATCH] 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";} --- src/libexpr/primops/fetchTree.cc | 27 +++++++++++++++++---------- 1 file 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 & type, + std::optional 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({