1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-11 04:56:01 +01:00

Log warnings on IFD with new option

This commit is contained in:
gustavderdrache 2025-05-20 13:46:19 -04:00
parent ea2f882fb1
commit 8825cd56b5
2 changed files with 23 additions and 5 deletions

View file

@ -151,6 +151,16 @@ struct EvalSettings : Config
)"
};
Setting<bool> traceImportFromDerivation{
this, false, "trace-import-from-derivation",
R"(
By default, Nix allows [Import from Derivation](@docroot@/language/import-from-derivation.md).
When this setting is `true`, Nix will log a warning indicating that it performed such an import.
The `allow-import-from-derivation` setting takes precedence, and no warnings will be logged if that setting is also enabled.
)"
};
Setting<bool> enableImportFromDerivation{
this, true, "allow-import-from-derivation",
R"(

View file

@ -97,11 +97,19 @@ StringMap EvalState::realiseContext(const NixStringContext & context, StorePathS
if (drvs.empty()) return {};
if (isIFD && !settings.enableImportFromDerivation)
error<IFDError>(
"cannot build '%1%' during evaluation because the option 'allow-import-from-derivation' is disabled",
drvs.begin()->to_string(*store)
).debugThrow();
if (isIFD) {
if (!settings.enableImportFromDerivation)
error<IFDError>(
"cannot build '%1%' during evaluation because the option 'allow-import-from-derivation' is disabled",
drvs.begin()->to_string(*store)
).debugThrow();
if (settings.traceImportFromDerivation)
warn(
"built '%1%' during evaluation due to an import from derivation",
drvs.begin()->to_string(*store)
);
}
/* Build/substitute the context. */
std::vector<DerivedPath> buildReqs;