Skip to content

Commit

Permalink
log all ifd
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverca22 committed Apr 25, 2021
1 parent fe2bf46 commit a81c0fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public:
/* Print statistics. */
void printStats();

void realiseContext(const PathSet & context);
void realiseContext(const PathSet & context, const Pos &pos, const string & reason);

private:

Expand Down Expand Up @@ -428,6 +428,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
19 changes: 11 additions & 8 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace nix {
InvalidPathError::InvalidPathError(const Path & path) :
EvalError("path '%s' is not valid", path), path(path) {}

void EvalState::realiseContext(const PathSet & context)
void EvalState::realiseContext(const PathSet & context, const Pos &pos, const string & reason)
{
std::vector<DerivedPath::Built> drvs;

Expand All @@ -44,6 +44,9 @@ void 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);
}
}
}

Expand Down Expand Up @@ -114,7 +117,7 @@ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vS
Path path = state.coerceToPath(pos, vPath, context);

try {
state.realiseContext(context);
state.realiseContext(context, pos, "scopedImport");
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt("cannot import '%1%', since path '%2%' is not valid", path, e.path),
Expand Down Expand Up @@ -284,7 +287,7 @@ void prim_importNative(EvalState & state, const Pos & pos, Value * * args, Value
Path path = state.coerceToPath(pos, *args[0], context);

try {
state.realiseContext(context);
state.realiseContext(context, pos, "importNative");
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt(
Expand Down Expand Up @@ -338,7 +341,7 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
commandArgs.emplace_back(state.coerceToString(pos, *elems[i], context, false, false));
}
try {
state.realiseContext(context);
state.realiseContext(context, pos, "exec");
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt("cannot execute '%1%', since path '%2%' is not valid",
Expand Down Expand Up @@ -1294,7 +1297,7 @@ static void prim_pathExists(EvalState & state, const Pos & pos, Value * * args,
PathSet context;
Path path = state.coerceToPath(pos, *args[0], context);
try {
state.realiseContext(context);
state.realiseContext(context, pos, "pathExists");
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt(
Expand Down Expand Up @@ -1371,7 +1374,7 @@ static void prim_readFile(EvalState & state, const Pos & pos, Value * * args, Va
PathSet context;
Path path = state.coerceToPath(pos, *args[0], context);
try {
state.realiseContext(context);
state.realiseContext(context, pos, "readFile");
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt("cannot read '%1%', since path '%2%' is not valid", path, e.path),
Expand Down Expand Up @@ -1422,7 +1425,7 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
string path = state.coerceToString(pos, *i->value, context, false, false);

try {
state.realiseContext(context);
state.realiseContext(context, pos, "findFile");
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt("cannot find '%1%', since path '%2%' is not valid", path, e.path),
Expand Down Expand Up @@ -1478,7 +1481,7 @@ static void prim_readDir(EvalState & state, const Pos & pos, Value * * args, Val
PathSet ctx;
Path path = state.coerceToPath(pos, *args[0], ctx);
try {
state.realiseContext(ctx);
state.realiseContext(ctx, pos, "readDir");
} catch (InvalidPathError & e) {
throw EvalError({
.msg = hintfmt("cannot read '%1%', since path '%2%' is not valid", path, e.path),
Expand Down

0 comments on commit a81c0fa

Please sign in to comment.