Skip to content

Commit b919084

Browse files
cleverca22cidkidnix
andcommitted
fix: log all ifd
Co-authored-by: Dylan Green <[email protected]>
1 parent ae2d330 commit b919084

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/libexpr/eval.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public:
507507
/* Realise the given context, and return a mapping from the placeholders
508508
* used to construct the associated value to their final store path
509509
*/
510-
[[nodiscard]] StringMap realiseContext(const PathSet & context);
510+
[[nodiscard]] StringMap realiseContext(const PathSet & context, const PosIdx pos, const std::string & reason);
511511

512512
private:
513513

@@ -656,6 +656,9 @@ struct EvalSettings : Config
656656

657657
Setting<bool> traceVerbose{this, false, "trace-verbose",
658658
"Whether `builtins.traceVerbose` should trace its first argument when evaluated."};
659+
660+
Setting<bool> logAllIFD{this, false, "log-all-ifd",
661+
"Emit log messages for all imports from derivation at the 'info' log level"};
659662
};
660663

661664
extern EvalSettings evalSettings;

src/libexpr/primops.cc

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace nix {
3737
InvalidPathError::InvalidPathError(const Path & path) :
3838
EvalError("path '%s' is not valid", path), path(path) {}
3939

40-
StringMap EvalState::realiseContext(const PathSet & context)
40+
StringMap EvalState::realiseContext(const PathSet & context, const PosIdx pos, const std::string & reason)
4141
{
4242
std::vector<DerivedPath::Built> drvs;
4343
StringMap res;
@@ -49,6 +49,9 @@ StringMap EvalState::realiseContext(const PathSet & context)
4949
debugThrowLastTrace(InvalidPathError(store->printStorePath(ctx)));
5050
if (!outputName.empty() && ctx.isDerivation()) {
5151
drvs.push_back({ctx, {outputName}});
52+
if (evalSettings.logAllIFD) {
53+
printInfo("%1% importing from derivation %2% via %3%", positions[pos], ctxS, reason);
54+
}
5255
} else {
5356
res.insert_or_assign(ctxS, ctxS);
5457
}
@@ -97,7 +100,7 @@ struct RealisePathFlags {
97100
bool checkForPureEval = true;
98101
};
99102

100-
static Path realisePath(EvalState & state, const PosIdx pos, Value & v, const RealisePathFlags flags = {})
103+
static Path realisePath(EvalState & state, const PosIdx pos, Value & v, const std::string & reason, const RealisePathFlags flags = {})
101104
{
102105
PathSet context;
103106

@@ -112,7 +115,7 @@ static Path realisePath(EvalState & state, const PosIdx pos, Value & v, const Re
112115
}();
113116

114117
try {
115-
StringMap rewrites = state.realiseContext(context);
118+
StringMap rewrites = state.realiseContext(context, pos, reason);
116119

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

@@ -160,7 +163,7 @@ static void mkOutputString(
160163
argument. */
161164
static void import(EvalState & state, const PosIdx pos, Value & vPath, Value * vScope, Value & v)
162165
{
163-
auto path = realisePath(state, pos, vPath);
166+
auto path = realisePath(state, pos, vPath, "scopedImport");
164167

165168
// FIXME
166169
auto isValidDerivationInStore = [&]() -> std::optional<StorePath> {
@@ -313,7 +316,7 @@ extern "C" typedef void (*ValueInitializer)(EvalState & state, Value & v);
313316
/* Load a ValueInitializer from a DSO and return whatever it initializes */
314317
void prim_importNative(EvalState & state, const PosIdx pos, Value * * args, Value & v)
315318
{
316-
auto path = realisePath(state, pos, *args[0]);
319+
auto path = realisePath(state, pos, *args[0], "importNative");
317320

318321
std::string sym(state.forceStringNoCtx(*args[1], pos));
319322

@@ -355,7 +358,7 @@ void prim_exec(EvalState & state, const PosIdx pos, Value * * args, Value & v)
355358
commandArgs.push_back(state.coerceToString(pos, *elems[i], context, false, false).toOwned());
356359
}
357360
try {
358-
auto _ = state.realiseContext(context); // FIXME: Handle CA derivations
361+
auto _ = state.realiseContext(context, pos, "exec"); // FIXME: Handle CA derivations
359362
} catch (InvalidPathError & e) {
360363
state.debugThrowLastTrace(EvalError({
361364
.msg = hintfmt("cannot execute '%1%', since path '%2%' is not valid",
@@ -1465,7 +1468,7 @@ static void prim_pathExists(EvalState & state, const PosIdx pos, Value * * args,
14651468
can’t just catch the exception here because we still want to
14661469
throw if something in the evaluation of `*args[0]` tries to
14671470
access an unauthorized path). */
1468-
auto path = realisePath(state, pos, *args[0], { .checkForPureEval = false });
1471+
auto path = realisePath(state, pos, *args[0], "pathExists", { .checkForPureEval = false });
14691472

14701473
try {
14711474
v.mkBool(pathExists(state.checkSourcePath(path)));
@@ -1532,7 +1535,7 @@ static RegisterPrimOp primop_dirOf({
15321535
/* Return the contents of a file as a string. */
15331536
static void prim_readFile(EvalState & state, const PosIdx pos, Value * * args, Value & v)
15341537
{
1535-
auto path = realisePath(state, pos, *args[0]);
1538+
auto path = realisePath(state, pos, *args[0], "readFile");
15361539
auto s = readFile(path);
15371540
if (s.find((char) 0) != std::string::npos)
15381541
state.debugThrowLastTrace(Error("the contents of the file '%1%' cannot be represented as a Nix string", path));
@@ -1584,7 +1587,7 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value * * args, V
15841587
auto path = state.coerceToString(pos, *i->value, context, false, false).toOwned();
15851588

15861589
try {
1587-
auto rewrites = state.realiseContext(context);
1590+
auto rewrites = state.realiseContext(context, pos, "findFile");
15881591
path = rewriteStrings(path, rewrites);
15891592
} catch (InvalidPathError & e) {
15901593
state.debugThrowLastTrace(EvalError({
@@ -1618,7 +1621,7 @@ static void prim_hashFile(EvalState & state, const PosIdx pos, Value * * args, V
16181621
.errPos = state.positions[pos]
16191622
}));
16201623

1621-
auto path = realisePath(state, pos, *args[1]);
1624+
auto path = realisePath(state, pos, *args[1], "hashFile");
16221625

16231626
v.mkString(hashFile(*ht, path).to_string(Base16, false));
16241627
}
@@ -1637,7 +1640,7 @@ static RegisterPrimOp primop_hashFile({
16371640
/* Read a directory (without . or ..) */
16381641
static void prim_readDir(EvalState & state, const PosIdx pos, Value * * args, Value & v)
16391642
{
1640-
auto path = realisePath(state, pos, *args[0]);
1643+
auto path = realisePath(state, pos, *args[0], "readDir");
16411644

16421645
DirEntries entries = readDirectory(path);
16431646

@@ -1967,7 +1970,7 @@ static void addPath(
19671970
try {
19681971
// FIXME: handle CA derivation outputs (where path needs to
19691972
// be rewritten to the actual output).
1970-
auto rewrites = state.realiseContext(context);
1973+
auto rewrites = state.realiseContext(context, noPos, "addPath");
19711974
path = state.toRealPath(rewriteStrings(path, rewrites), context);
19721975

19731976
StorePathSet refs;

0 commit comments

Comments
 (0)