Make unsupported flake attributes a fatal error
This commit is contained in:
parent
6636808e90
commit
c356d034f3
|
@ -327,7 +327,9 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
|
||||||
|
|
||||||
state.forceAttrs(vInfo);
|
state.forceAttrs(vInfo);
|
||||||
|
|
||||||
if (auto epoch = vInfo.attrs->get(state.symbols.create("epoch"))) {
|
auto sEpoch = state.symbols.create("epoch");
|
||||||
|
|
||||||
|
if (auto epoch = vInfo.attrs->get(sEpoch)) {
|
||||||
flake.epoch = state.forceInt(*(**epoch).value, *(**epoch).pos);
|
flake.epoch = state.forceInt(*(**epoch).value, *(**epoch).pos);
|
||||||
if (flake.epoch > 2019)
|
if (flake.epoch > 2019)
|
||||||
throw Error("flake '%s' requires unsupported epoch %d; please upgrade Nix", flakeRef, flake.epoch);
|
throw Error("flake '%s' requires unsupported epoch %d; please upgrade Nix", flakeRef, flake.epoch);
|
||||||
|
@ -342,14 +344,18 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
|
||||||
if (auto description = vInfo.attrs->get(state.sDescription))
|
if (auto description = vInfo.attrs->get(state.sDescription))
|
||||||
flake.description = state.forceStringNoCtx(*(**description).value, *(**description).pos);
|
flake.description = state.forceStringNoCtx(*(**description).value, *(**description).pos);
|
||||||
|
|
||||||
if (auto requires = vInfo.attrs->get(state.symbols.create("requires"))) {
|
auto sRequires = state.symbols.create("requires");
|
||||||
|
|
||||||
|
if (auto requires = vInfo.attrs->get(sRequires)) {
|
||||||
state.forceList(*(**requires).value, *(**requires).pos);
|
state.forceList(*(**requires).value, *(**requires).pos);
|
||||||
for (unsigned int n = 0; n < (**requires).value->listSize(); ++n)
|
for (unsigned int n = 0; n < (**requires).value->listSize(); ++n)
|
||||||
flake.requires.push_back(FlakeRef(state.forceStringNoCtx(
|
flake.requires.push_back(FlakeRef(state.forceStringNoCtx(
|
||||||
*(**requires).value->listElems()[n], *(**requires).pos)));
|
*(**requires).value->listElems()[n], *(**requires).pos)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::optional<Attr *> nonFlakeRequires = vInfo.attrs->get(state.symbols.create("nonFlakeRequires"))) {
|
auto sNonFlakeRequires = state.symbols.create("nonFlakeRequires");
|
||||||
|
|
||||||
|
if (std::optional<Attr *> nonFlakeRequires = vInfo.attrs->get(sNonFlakeRequires)) {
|
||||||
state.forceAttrs(*(**nonFlakeRequires).value, *(**nonFlakeRequires).pos);
|
state.forceAttrs(*(**nonFlakeRequires).value, *(**nonFlakeRequires).pos);
|
||||||
for (Attr attr : *(*(**nonFlakeRequires).value).attrs) {
|
for (Attr attr : *(*(**nonFlakeRequires).value).attrs) {
|
||||||
std::string myNonFlakeUri = state.forceStringNoCtx(*attr.value, *attr.pos);
|
std::string myNonFlakeUri = state.forceStringNoCtx(*attr.value, *attr.pos);
|
||||||
|
@ -358,12 +364,25 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto provides = vInfo.attrs->get(state.symbols.create("provides"))) {
|
auto sProvides = state.symbols.create("provides");
|
||||||
|
|
||||||
|
if (auto provides = vInfo.attrs->get(sProvides)) {
|
||||||
state.forceFunction(*(**provides).value, *(**provides).pos);
|
state.forceFunction(*(**provides).value, *(**provides).pos);
|
||||||
flake.vProvides = (**provides).value;
|
flake.vProvides = (**provides).value;
|
||||||
} else
|
} else
|
||||||
throw Error("flake '%s' lacks attribute 'provides'", flakeRef);
|
throw Error("flake '%s' lacks attribute 'provides'", flakeRef);
|
||||||
|
|
||||||
|
for (auto & attr : *vInfo.attrs) {
|
||||||
|
if (attr.name != sEpoch &&
|
||||||
|
attr.name != state.sName &&
|
||||||
|
attr.name != state.sDescription &&
|
||||||
|
attr.name != sRequires &&
|
||||||
|
attr.name != sNonFlakeRequires &&
|
||||||
|
attr.name != sProvides)
|
||||||
|
throw Error("flake '%s' has an unsupported attribute '%s', at %s",
|
||||||
|
flakeRef, attr.name, *attr.pos);
|
||||||
|
}
|
||||||
|
|
||||||
return flake;
|
return flake;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue