| 81 | }; |
| 82 | |
| 83 | static void fetchTree( |
| 84 | EvalState & state, const PosIdx pos, Value ** args, Value & v, const FetchTreeParams & params = FetchTreeParams{}) |
| 85 | { |
| 86 | fetchers::Input input{}; |
| 87 | NixStringContext context; |
| 88 | std::optional<std::string> type; |
| 89 | auto fetcher = params.isFetchGit ? "fetchGit" : "fetchTree"; |
| 90 | if (params.isFetchGit) |
| 91 | type = "git"; |
| 92 | |
| 93 | state.forceValue(*args[0], pos); |
| 94 | |
| 95 | if (args[0]->type() == nAttrs) { |
| 96 | state.forceAttrs(*args[0], pos, fmt("while evaluating the argument passed to '%s'", fetcher)); |
| 97 | |
| 98 | fetchers::Attrs attrs; |
| 99 | |
| 100 | if (auto aType = args[0]->attrs()->get(state.s.type)) { |
| 101 | if (type) |
| 102 | state.error<EvalError>("unexpected argument 'type'").atPos(pos).debugThrow(); |
| 103 | type = state.forceStringNoCtx( |
| 104 | *aType->value, aType->pos, fmt("while evaluating the `type` argument passed to '%s'", fetcher)); |
| 105 | } else if (!type) |
| 106 | state.error<EvalError>("argument 'type' is missing in call to '%s'", fetcher).atPos(pos).debugThrow(); |
| 107 | |
| 108 | attrs.emplace("type", type.value()); |
| 109 | |
| 110 | for (auto & attr : *args[0]->attrs()) { |
| 111 | if (attr.name == state.s.type) |
| 112 | continue; |
| 113 | state.forceValue(*attr.value, attr.pos); |
| 114 | if (attr.value->type() == nPath || attr.value->type() == nString) { |
| 115 | auto s = state.coerceToString(attr.pos, *attr.value, context, "", false, false).toOwned(); |
| 116 | attrs.emplace( |
| 117 | state.symbols[attr.name], |
| 118 | params.isFetchGit && state.symbols[attr.name] == "url" ? fixGitURL(s).to_string() : s); |
| 119 | } else if (attr.value->type() == nBool) |
| 120 | attrs.emplace(state.symbols[attr.name], Explicit<bool>{attr.value->boolean()}); |
| 121 | else if (attr.value->type() == nInt) { |
| 122 | auto intValue = attr.value->integer().value; |
| 123 | |
| 124 | if (intValue < 0) |
| 125 | state |
| 126 | .error<EvalError>( |
| 127 | "negative value given for '%s' argument '%s': %d", |
| 128 | fetcher, |
| 129 | state.symbols[attr.name], |
| 130 | intValue) |
| 131 | .atPos(pos) |
| 132 | .debugThrow(); |
| 133 | |
| 134 | attrs.emplace(state.symbols[attr.name], uint64_t(intValue)); |
| 135 | } else if (state.symbols[attr.name] == "publicKeys") { |
| 136 | experimentalFeatureSettings.require(Xp::VerifiedFetches); |
| 137 | attrs.emplace( |
| 138 | state.symbols[attr.name], printValueAsJSON(state, true, *attr.value, pos, context).dump()); |
| 139 | } else |
| 140 | state |
no test coverage detected