mirror of
https://github.com/NixOS/nix
synced 2025-06-27 12:41:15 +02:00
Merge remote-tracking branch 'origin/master' into flakes
This commit is contained in:
commit
54712aaf8a
57 changed files with 746 additions and 356 deletions
|
@ -84,7 +84,7 @@ static void prim_scopedImport(EvalState & state, const Pos & pos, Value * * args
|
|||
} catch (InvalidPathError & e) {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("cannot import '%1%', since path '%2%' is not valid", path, e.path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ void prim_importNative(EvalState & state, const Pos & pos, Value * * args, Value
|
|||
.hint = hintfmt(
|
||||
"cannot import '%1%', since path '%2%' is not valid",
|
||||
path, e.path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
|||
if (count == 0) {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("at least one argument to 'exec' required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
}
|
||||
PathSet context;
|
||||
|
@ -218,7 +218,7 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
|||
throw EvalError({
|
||||
.hint = hintfmt("cannot execute '%1%', since path '%2%' is not valid",
|
||||
program, e.path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -227,13 +227,13 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
|||
try {
|
||||
parsed = state.parseExprFromString(output, pos.file);
|
||||
} catch (Error & e) {
|
||||
e.addPrefix(fmt("While parsing the output from '%1%', at %2%\n", program, pos));
|
||||
e.addTrace(pos, "While parsing the output from '%1%'", program);
|
||||
throw;
|
||||
}
|
||||
try {
|
||||
state.eval(parsed, v);
|
||||
} catch (Error & e) {
|
||||
e.addPrefix(fmt("While evaluating the output from '%1%', at %2%\n", program, pos));
|
||||
e.addTrace(pos, "While evaluating the output from '%1%'", program);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
|
|||
if (startSet == args[0]->attrs->end())
|
||||
throw EvalError({
|
||||
.hint = hintfmt("attribute 'startSet' required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
state.forceList(*startSet->value, pos);
|
||||
|
||||
|
@ -387,7 +387,7 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
|
|||
if (op == args[0]->attrs->end())
|
||||
throw EvalError({
|
||||
.hint = hintfmt("attribute 'operator' required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
state.forceValue(*op->value, pos);
|
||||
|
||||
|
@ -409,7 +409,7 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
|
|||
if (key == e->attrs->end())
|
||||
throw EvalError({
|
||||
.hint = hintfmt("attribute 'key' required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
state.forceValue(*key->value, pos);
|
||||
|
||||
|
@ -459,7 +459,7 @@ static void prim_addErrorContext(EvalState & state, const Pos & pos, Value * * a
|
|||
v = *args[1];
|
||||
} catch (Error & e) {
|
||||
PathSet context;
|
||||
e.addPrefix(format("%1%\n") % state.coerceToString(pos, *args[0], context));
|
||||
e.addTrace(std::nullopt, state.coerceToString(pos, *args[0], context));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
@ -544,14 +544,14 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
if (attr == args[0]->attrs->end())
|
||||
throw EvalError({
|
||||
.hint = hintfmt("required attribute 'name' missing"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
string drvName;
|
||||
Pos & posDrvName(*attr->pos);
|
||||
try {
|
||||
drvName = state.forceStringNoCtx(*attr->value, pos);
|
||||
} catch (Error & e) {
|
||||
e.addPrefix(fmt("while evaluating the derivation attribute 'name' at %1%:\n", posDrvName));
|
||||
e.addTrace(posDrvName, "while evaluating the derivation attribute 'name'");
|
||||
throw;
|
||||
}
|
||||
|
||||
|
@ -591,7 +591,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
else
|
||||
throw EvalError({
|
||||
.hint = hintfmt("invalid value '%s' for 'outputHashMode' attribute", s),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
.errPos = posDrvName
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -601,7 +601,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
if (outputs.find(j) != outputs.end())
|
||||
throw EvalError({
|
||||
.hint = hintfmt("duplicate derivation output '%1%'", j),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
.errPos = posDrvName
|
||||
});
|
||||
/* !!! Check whether j is a valid attribute
|
||||
name. */
|
||||
|
@ -611,14 +611,14 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
if (j == "drv")
|
||||
throw EvalError({
|
||||
.hint = hintfmt("invalid derivation output name 'drv'" ),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
.errPos = posDrvName
|
||||
});
|
||||
outputs.insert(j);
|
||||
}
|
||||
if (outputs.empty())
|
||||
throw EvalError({
|
||||
.hint = hintfmt("derivation cannot have an empty set of outputs"),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
.errPos = posDrvName
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -684,8 +684,9 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
}
|
||||
|
||||
} catch (Error & e) {
|
||||
e.addPrefix(format("while evaluating the attribute '%1%' of the derivation '%2%' at %3%:\n")
|
||||
% key % drvName % posDrvName);
|
||||
e.addTrace(posDrvName,
|
||||
"while evaluating the attribute '%1%' of the derivation '%2%'",
|
||||
key, drvName);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
@ -733,20 +734,20 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
if (drv.builder == "")
|
||||
throw EvalError({
|
||||
.hint = hintfmt("required attribute 'builder' missing"),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
.errPos = posDrvName
|
||||
});
|
||||
|
||||
if (drv.platform == "")
|
||||
throw EvalError({
|
||||
.hint = hintfmt("required attribute 'system' missing"),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
.errPos = posDrvName
|
||||
});
|
||||
|
||||
/* Check whether the derivation name is valid. */
|
||||
if (isDerivation(drvName))
|
||||
throw EvalError({
|
||||
.hint = hintfmt("derivation names are not allowed to end in '%s'", drvExtension),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
.errPos = posDrvName
|
||||
});
|
||||
|
||||
if (outputHash) {
|
||||
|
@ -754,7 +755,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
if (outputs.size() != 1 || *(outputs.begin()) != "out")
|
||||
throw Error({
|
||||
.hint = hintfmt("multiple outputs are not supported in fixed-output derivations"),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
.errPos = posDrvName
|
||||
});
|
||||
|
||||
std::optional<HashType> ht = parseHashTypeOpt(outputHashAlgo);
|
||||
|
@ -868,7 +869,7 @@ static void prim_storePath(EvalState & state, const Pos & pos, Value * * args, V
|
|||
if (!state.store->isInStore(path))
|
||||
throw EvalError({
|
||||
.hint = hintfmt("path '%1%' is not in the Nix store", path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
Path path2 = state.store->toStorePath(path);
|
||||
if (!settings.readOnlyMode)
|
||||
|
@ -889,7 +890,7 @@ static void prim_pathExists(EvalState & state, const Pos & pos, Value * * args,
|
|||
.hint = hintfmt(
|
||||
"cannot check the existence of '%1%', since path '%2%' is not valid",
|
||||
path, e.path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -935,7 +936,7 @@ static void prim_readFile(EvalState & state, const Pos & pos, Value * * args, Va
|
|||
} catch (InvalidPathError & e) {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("cannot read '%1%', since path '%2%' is not valid", path, e.path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
}
|
||||
string s = readFile(state.checkSourcePath(state.toRealPath(path, context)));
|
||||
|
@ -966,7 +967,7 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
|
|||
if (i == v2.attrs->end())
|
||||
throw EvalError({
|
||||
.hint = hintfmt("attribute 'path' missing"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
|
||||
PathSet context;
|
||||
|
@ -977,7 +978,7 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
|
|||
} catch (InvalidPathError & e) {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("cannot find '%1%', since path '%2%' is not valid", path, e.path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -997,7 +998,7 @@ static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Va
|
|||
if (!ht)
|
||||
throw Error({
|
||||
.hint = hintfmt("unknown hash type '%1%'", type),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
|
||||
PathSet context; // discarded
|
||||
|
@ -1016,7 +1017,7 @@ static void prim_readDir(EvalState & state, const Pos & pos, Value * * args, Val
|
|||
} catch (InvalidPathError & e) {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("cannot read '%1%', since path '%2%' is not valid", path, e.path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1092,7 +1093,7 @@ static void prim_toFile(EvalState & state, const Pos & pos, Value * * args, Valu
|
|||
"in 'toFile': the file named '%1%' must not contain a reference "
|
||||
"to a derivation but contains (%2%)",
|
||||
name, path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
refs.insert(state.store->parseStorePath(path));
|
||||
}
|
||||
|
@ -1163,7 +1164,7 @@ static void prim_filterSource(EvalState & state, const Pos & pos, Value * * args
|
|||
if (!context.empty())
|
||||
throw EvalError({
|
||||
.hint = hintfmt("string '%1%' cannot refer to other paths", path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
|
||||
state.forceValue(*args[0], pos);
|
||||
|
@ -1172,7 +1173,7 @@ static void prim_filterSource(EvalState & state, const Pos & pos, Value * * args
|
|||
.hint = hintfmt(
|
||||
"first argument in call to 'filterSource' is not a function but %1%",
|
||||
showType(*args[0])),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
|
||||
addPath(state, pos, std::string(baseNameOf(path)), path, args[0], FileIngestionMethod::Recursive, Hash(), v);
|
||||
|
@ -1195,7 +1196,7 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
|
|||
if (!context.empty())
|
||||
throw EvalError({
|
||||
.hint = hintfmt("string '%1%' cannot refer to other paths", path),
|
||||
.nixCode = NixCode { .errPos = *attr.pos }
|
||||
.errPos = *attr.pos
|
||||
});
|
||||
} else if (attr.name == state.sName)
|
||||
name = state.forceStringNoCtx(*attr.value, *attr.pos);
|
||||
|
@ -1209,13 +1210,13 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
|
|||
else
|
||||
throw EvalError({
|
||||
.hint = hintfmt("unsupported argument '%1%' to 'addPath'", attr.name),
|
||||
.nixCode = NixCode { .errPos = *attr.pos }
|
||||
.errPos = *attr.pos
|
||||
});
|
||||
}
|
||||
if (path.empty())
|
||||
throw EvalError({
|
||||
.hint = hintfmt("'path' required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
if (name.empty())
|
||||
name = baseNameOf(path);
|
||||
|
@ -1276,7 +1277,7 @@ void prim_getAttr(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
|||
if (i == args[1]->attrs->end())
|
||||
throw EvalError({
|
||||
.hint = hintfmt("attribute '%1%' missing", attr),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
// !!! add to stack trace?
|
||||
if (state.countCalls && i->pos) state.attrSelects[*i->pos]++;
|
||||
|
@ -1359,7 +1360,7 @@ static void prim_listToAttrs(EvalState & state, const Pos & pos, Value * * args,
|
|||
if (j == v2.attrs->end())
|
||||
throw TypeError({
|
||||
.hint = hintfmt("'name' attribute missing in a call to 'listToAttrs'"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
string name = state.forceStringNoCtx(*j->value, pos);
|
||||
|
||||
|
@ -1369,7 +1370,7 @@ static void prim_listToAttrs(EvalState & state, const Pos & pos, Value * * args,
|
|||
if (j2 == v2.attrs->end())
|
||||
throw TypeError({
|
||||
.hint = hintfmt("'value' attribute missing in a call to 'listToAttrs'"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
v.attrs->push_back(Attr(sym, j2->value, j2->pos));
|
||||
}
|
||||
|
@ -1445,7 +1446,7 @@ static void prim_functionArgs(EvalState & state, const Pos & pos, Value * * args
|
|||
if (args[0]->type != tLambda)
|
||||
throw TypeError({
|
||||
.hint = hintfmt("'functionArgs' requires a function"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
|
||||
if (!args[0]->lambda.fun->matchAttrs) {
|
||||
|
@ -1501,7 +1502,7 @@ static void elemAt(EvalState & state, const Pos & pos, Value & list, int n, Valu
|
|||
if (n < 0 || (unsigned int) n >= list.listSize())
|
||||
throw Error({
|
||||
.hint = hintfmt("list index %1% is out of bounds", n),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
state.forceValue(*list.listElems()[n], pos);
|
||||
v = *list.listElems()[n];
|
||||
|
@ -1531,7 +1532,7 @@ static void prim_tail(EvalState & state, const Pos & pos, Value * * args, Value
|
|||
if (args[0]->listSize() == 0)
|
||||
throw Error({
|
||||
.hint = hintfmt("'tail' called on an empty list"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
|
||||
state.mkList(v, args[0]->listSize() - 1);
|
||||
|
@ -1676,7 +1677,7 @@ static void prim_genList(EvalState & state, const Pos & pos, Value * * args, Val
|
|||
if (len < 0)
|
||||
throw EvalError({
|
||||
.hint = hintfmt("cannot create list of size %1%", len),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
|
||||
state.mkList(v, len);
|
||||
|
@ -1838,7 +1839,7 @@ static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value &
|
|||
if (f2 == 0)
|
||||
throw EvalError({
|
||||
.hint = hintfmt("division by zero"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
|
||||
if (args[0]->type == tFloat || args[1]->type == tFloat) {
|
||||
|
@ -1850,7 +1851,7 @@ static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value &
|
|||
if (i1 == std::numeric_limits<NixInt>::min() && i2 == -1)
|
||||
throw EvalError({
|
||||
.hint = hintfmt("overflow in integer division"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
|
||||
mkInt(v, i1 / i2);
|
||||
|
@ -1911,7 +1912,7 @@ static void prim_substring(EvalState & state, const Pos & pos, Value * * args, V
|
|||
if (start < 0)
|
||||
throw EvalError({
|
||||
.hint = hintfmt("negative start position in 'substring'"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
|
||||
mkString(v, (unsigned int) start >= s.size() ? "" : string(s, start, len), context);
|
||||
|
@ -1934,7 +1935,7 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args,
|
|||
if (!ht)
|
||||
throw Error({
|
||||
.hint = hintfmt("unknown hash type '%1%'", type),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
|
||||
PathSet context; // discarded
|
||||
|
@ -1980,12 +1981,12 @@ void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
|||
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
|
||||
throw EvalError({
|
||||
.hint = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
} else {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("invalid regular expression '%s'", re),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2053,12 +2054,12 @@ static void prim_split(EvalState & state, const Pos & pos, Value * * args, Value
|
|||
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
|
||||
throw EvalError({
|
||||
.hint = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
} else {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("invalid regular expression '%s'", re),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2092,7 +2093,7 @@ static void prim_replaceStrings(EvalState & state, const Pos & pos, Value * * ar
|
|||
if (args[0]->listSize() != args[1]->listSize())
|
||||
throw EvalError({
|
||||
.hint = hintfmt("'from' and 'to' arguments to 'replaceStrings' have different lengths"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
.errPos = pos
|
||||
});
|
||||
|
||||
vector<string> from;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue