MCPcopy Create free account
hub / github.com/NixOS/nix / fetchTree

Function fetchTree

src/libexpr/primops/fetchTree.cc:83–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81};
82
83static 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

Callers 3

prim_fetchTreeFunction · 0.85
prim_fetchFinalTreeFunction · 0.85
prim_fetchGitFunction · 0.85

Calls 15

fmtFunction · 0.85
fixGitURLFunction · 0.85
printValueAsJSONFunction · 0.85
showTypeFunction · 0.85
maybeGetBoolAttrFunction · 0.85
lookupInRegistriesFunction · 0.85
warnFunction · 0.85
ErrorEnum · 0.85
emitTreeAttrsFunction · 0.85
forceValueMethod · 0.80
forceAttrsMethod · 0.80
attrsMethod · 0.80

Tested by

no test coverage detected