mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +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:
commit
161bf86457
4 changed files with 57 additions and 5 deletions
|
@ -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{
|
Setting<bool> enableImportFromDerivation{
|
||||||
this, true, "allow-import-from-derivation",
|
this, true, "allow-import-from-derivation",
|
||||||
R"(
|
R"(
|
||||||
|
|
|
@ -90,12 +90,20 @@ StringMap EvalState::realiseContext(const NixStringContext & context, StorePathS
|
||||||
|
|
||||||
if (drvs.empty()) return {};
|
if (drvs.empty()) return {};
|
||||||
|
|
||||||
if (isIFD && !settings.enableImportFromDerivation)
|
if (isIFD) {
|
||||||
|
if (!settings.enableImportFromDerivation)
|
||||||
error<IFDError>(
|
error<IFDError>(
|
||||||
"cannot build '%1%' during evaluation because the option 'allow-import-from-derivation' is disabled",
|
"cannot build '%1%' during evaluation because the option 'allow-import-from-derivation' is disabled",
|
||||||
drvs.begin()->to_string(*store)
|
drvs.begin()->to_string(*store)
|
||||||
).debugThrow();
|
).debugThrow();
|
||||||
|
|
||||||
|
if (settings.traceImportFromDerivation)
|
||||||
|
warn(
|
||||||
|
"built '%1%' during evaluation due to an import from derivation",
|
||||||
|
drvs.begin()->to_string(*store)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/* Build/substitute the context. */
|
/* Build/substitute the context. */
|
||||||
std::vector<DerivedPath> buildReqs;
|
std::vector<DerivedPath> buildReqs;
|
||||||
buildReqs.reserve(drvs.size());
|
buildReqs.reserve(drvs.size());
|
||||||
|
|
|
@ -33,6 +33,7 @@ suites += {
|
||||||
'debugger.sh',
|
'debugger.sh',
|
||||||
'source-paths.sh',
|
'source-paths.sh',
|
||||||
'old-lockfiles.sh',
|
'old-lockfiles.sh',
|
||||||
|
'trace-ifd.sh',
|
||||||
],
|
],
|
||||||
'workdir': meson.current_source_dir(),
|
'workdir': meson.current_source_dir(),
|
||||||
}
|
}
|
||||||
|
|
33
tests/functional/flakes/trace-ifd.sh
Normal file
33
tests/functional/flakes/trace-ifd.sh
Normal 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'
|
Loading…
Add table
Add a link
Reference in a new issue