From ce89c8c114254aa558c314a19b730a53cfe17785 Mon Sep 17 00:00:00 2001 From: gustavderdrache Date: Tue, 20 May 2025 13:46:19 -0400 Subject: [PATCH] Log warnings on IFD with new option Co-authored-by: Eelco Dolstra --- src/libexpr/include/nix/expr/eval-settings.hh | 10 ++++++++++ src/libexpr/primops.cc | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/libexpr/include/nix/expr/eval-settings.hh b/src/libexpr/include/nix/expr/eval-settings.hh index 284e02a9b..9ff73138a 100644 --- a/src/libexpr/include/nix/expr/eval-settings.hh +++ b/src/libexpr/include/nix/expr/eval-settings.hh @@ -152,6 +152,16 @@ struct EvalSettings : Config )" }; + Setting 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. + This option has no effect if `allow-import-from-derivation` is disabled. + )" + }; + Setting enableImportFromDerivation{ this, true, "allow-import-from-derivation", R"( diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index c4e6feb28..f3e3e1290 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -90,11 +90,19 @@ StringMap EvalState::realiseContext(const NixStringContext & context, StorePathS if (drvs.empty()) return {}; - if (isIFD && !settings.enableImportFromDerivation) - error( - "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( + "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 buildReqs;