1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-24 22:11:15 +02:00

Merge pull request #13279 from DeterminateSystems/gustavderdrache/trace-import-from-derivation

Emit warnings for IFDs with new `trace-import-from-derivation` option
This commit is contained in:
Jörg Thalheim 2025-05-27 16:37:29 +02:00 committed by GitHub
commit 161bf86457
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 57 additions and 5 deletions

View file

@ -152,6 +152,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.
This option has no effect if `allow-import-from-derivation` is disabled.
)"
};
Setting<bool> enableImportFromDerivation{
this, true, "allow-import-from-derivation",
R"(

View file

@ -90,11 +90,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;

View file

@ -33,6 +33,7 @@ suites += {
'debugger.sh',
'source-paths.sh',
'old-lockfiles.sh',
'trace-ifd.sh',
],
'workdir': meson.current_source_dir(),
}

View file

@ -0,0 +1,33 @@
#!/usr/bin/env bash
source ./common.sh
requireGit
flake1Dir="$TEST_ROOT/flake"
createGitRepo "$flake1Dir"
createSimpleGitFlake "$flake1Dir"
cat > "$flake1Dir/flake.nix" <<'EOF'
{
outputs = { self }: let inherit (import ./config.nix) mkDerivation; in {
drv = mkDerivation {
name = "drv";
buildCommand = ''
echo drv >$out
'';
};
ifd = mkDerivation {
name = "ifd";
buildCommand = ''
echo ${builtins.readFile self.drv} >$out
'';
};
};
}
EOF
nix build --no-link "$flake1Dir#ifd" --option trace-import-from-derivation true 2>&1 \
| grepQuiet 'warning: built .* during evaluation due to an import from derivation'