Skip to content

Commit

Permalink
log all ifd
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverca22 committed Jan 24, 2022
1 parent e61c4bc commit de58e97
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public:
/* Realise the given context, and return a mapping from the placeholders
* used to construct the associated value to their final store path
*/
[[nodiscard]] StringMap realiseContext(const PathSet & context);
[[nodiscard]] StringMap realiseContext(const PathSet & context, const Pos &pos, const string & reason);

private:

Expand Down Expand Up @@ -487,6 +487,9 @@ struct EvalSettings : Config

Setting<bool> useEvalCache{this, true, "eval-cache",
"Whether to use the flake evaluation cache."};

Setting<bool> logAllIFD{this, false, "log-all-ifd",
"Emit log messages for all imports from derivation at the 'info' log level"};
};

extern EvalSettings evalSettings;
Expand Down
27 changes: 15 additions & 12 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace nix {
InvalidPathError::InvalidPathError(const Path & path) :
EvalError("path '%s' is not valid", path), path(path) {}

StringMap EvalState::realiseContext(const PathSet & context)
StringMap EvalState::realiseContext(const PathSet & context, const Pos &pos, const string & reason)
{
std::vector<DerivedPath::Built> drvs;
StringMap res;
Expand All @@ -47,6 +47,9 @@ StringMap EvalState::realiseContext(const PathSet & context)
throw InvalidPathError(store->printStorePath(ctx));
if (!outputName.empty() && ctx.isDerivation()) {
drvs.push_back({ctx, {outputName}});
if (evalSettings.logAllIFD) {
printInfo("%1% importing from derivation %2% via %3%", pos, ctxS, reason);
}
} else {
res.insert_or_assign(ctxS, ctxS);
}
Expand Down Expand Up @@ -96,15 +99,15 @@ struct RealisePathFlags {
bool checkForPureEval = true;
};

static Path realisePath(EvalState & state, const Pos & pos, Value & v, const RealisePathFlags flags = {})
static Path realisePath(EvalState & state, const Pos & pos, Value & v, const string & reason, const RealisePathFlags flags = {})
{
PathSet context;

Path path = flags.requireAbsolutePath
? state.coerceToPath(pos, v, context)
: state.coerceToString(pos, v, context, false, false);

StringMap rewrites = state.realiseContext(context);
StringMap rewrites = state.realiseContext(context, pos, reason);

auto realPath = state.toRealPath(rewriteStrings(path, rewrites), context);

Expand Down Expand Up @@ -150,7 +153,7 @@ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vS
{
Path path;
try {
path = realisePath(state, pos, vPath);
path = realisePath(state, pos, vPath, "scopedImport");
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt("cannot import '%1%', since path '%2%' is not valid", path, e.path),
Expand Down Expand Up @@ -314,7 +317,7 @@ void prim_importNative(EvalState & state, const Pos & pos, Value * * args, Value
{
Path path;
try {
path = realisePath(state, pos, *args[0]);
path = realisePath(state, pos, *args[0], "importNative");
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt("cannot import '%1%', since path '%2%' is not valid", path, e.path),
Expand Down Expand Up @@ -366,7 +369,7 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
for (unsigned int i = 1; i < args[0]->listSize(); ++i)
commandArgs.emplace_back(state.coerceToString(pos, *elems[i], context, false, false));
try {
auto _ = state.realiseContext(context); // FIXME: Handle CA derivations
auto _ = state.realiseContext(context, pos, "exec"); // FIXME: Handle CA derivations
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt("cannot execute '%1%', since path '%2%' is not valid",
Expand Down Expand Up @@ -1384,7 +1387,7 @@ static void prim_pathExists(EvalState & state, const Pos & pos, Value * * args,
// (and we can’t just catch the exception here because we still want to
// throw if something in the evaluation of `*args[0]` tries to access an
// unauthorized path)
path = realisePath(state, pos, *args[0], { .checkForPureEval = false });
path = realisePath(state, pos, *args[0], "pathExists", { .checkForPureEval = false });
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt(
Expand Down Expand Up @@ -1460,7 +1463,7 @@ static void prim_readFile(EvalState & state, const Pos & pos, Value * * args, Va
{
Path path;
try {
path = realisePath(state, pos, *args[0]);
path = realisePath(state, pos, *args[0], "readFile");
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt("cannot read '%1%', since path '%2%' is not valid", path, e.path),
Expand Down Expand Up @@ -1513,7 +1516,7 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
Path path;

try {
path = realisePath(state, pos, *i->value, { .requireAbsolutePath = false });
path = realisePath(state, pos, *i->value, "findFile", { .requireAbsolutePath = false });
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt("cannot find '%1%', since path '%2%' is not valid", path, e.path),
Expand Down Expand Up @@ -1548,7 +1551,7 @@ static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Va

Path path;
try {
path = realisePath(state, pos, *args[1]);
path = realisePath(state, pos, *args[1], "hashFile");
} catch (InvalidPathError & e) {
throw EvalError("cannot read '%s' since path '%s' is not valid, at %s", path, e.path, pos);
}
Expand All @@ -1572,7 +1575,7 @@ static void prim_readDir(EvalState & state, const Pos & pos, Value * * args, Val
{
Path path;
try {
path = realisePath(state, pos, *args[0]);
path = realisePath(state, pos, *args[0], "readDir");
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt("cannot read '%1%', since path '%2%' is not valid", path, e.path),
Expand Down Expand Up @@ -1907,7 +1910,7 @@ static void addPath(
try {
// FIXME: handle CA derivation outputs (where path needs to
// be rewritten to the actual output).
auto rewrites = state.realiseContext(context);
auto rewrites = state.realiseContext(context, noPos, "addPath");
path = state.toRealPath(rewriteStrings(path, rewrites), context);

StorePathSet refs;
Expand Down

0 comments on commit de58e97

Please sign in to comment.