libexpr: warn when encountering IFD with warn-import-from-derivation

This is intended to be a softer version of
`allow-import-from-derivation`, allowing for users to only flag when IFD
is encountered rather than error out

Based-on: https://github.com/NixOS/nix/pull/13279
Co-authored-by: gustavderdrache <alex.ford@determinate.systems>
Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
Change-Id: I879a444e3a24b4e82a8cea3a5a94834c78c3924a
This commit is contained in:
Seth Flynn
2026-03-05 13:39:12 +00:00
committed by Qyriad
co-authored by gustavderdrache Eelco Dolstra
parent 6f25c5468d
commit b7cf773540
7 changed files with 46 additions and 0 deletions
+3
View File
@@ -99,6 +99,9 @@ goldstein:
forgejo: goldstein
github: GoldsteinE
gustavderdrache:
github: gustavderdrache
horrors:
display_name: eldritch horrors
forgejo: pennae
@@ -0,0 +1,12 @@
---
synopsis: "Emit warnings when encountering IFD with `warn-import-from-derivation`"
prs: [nix#13279]
cls: [3879]
category: Features
credits: [getchoo, gustavderdrache, edolstra]
---
Instead of only being able to toggle the use of [Import from
Derivation](https://nix.dev/manual/nix/stable/language/import-from-derivation) with
`allow-import-from-derivation`, Lix is now able to warn users whenever IFD is encountered with
`warn-import-from-derivation`.
+1
View File
@@ -31,6 +31,7 @@ libexpr_setting_definitions = files(
'settings/restrict-eval.md',
'settings/trace-function-calls.md',
'settings/trace-verbose.md',
'settings/warn-import-from-derivation.md',
# keep-sorted end
)
liblix_generated_headers += custom_target(
+7
View File
@@ -82,6 +82,13 @@ StringMap EvalState::realiseContext(const NixStringContext & context)
drvs.begin()->to_string(*ctx.store)
).debugThrow();
if (evalSettings.warnImportFromDerivation) {
printTaggedWarning(
"building '%1%' during evaluation due to the use of import from derivation",
drvs.begin()->to_string(*ctx.store)
);
}
/* Build/substitute the context. */
std::vector<DerivedPath> buildReqs;
for (auto & d : drvs) buildReqs.emplace_back(DerivedPath { d });
@@ -0,0 +1,14 @@
---
name: warn-import-from-derivation
internalName: warnImportFromDerivation
type: bool
default: false
---
By default, Lix allows you to `import` from a derivation, allowing
building at evaluation time. With this option set to true, Lix will
throw a warning when evaluating an expression that uses this feature,
allowing users to know when their evaluation will requires any builds
to take place.
This option has no effect when `allow-import-from-derivation` is `false`.
+1
View File
@@ -105,6 +105,7 @@ functional_tests_scripts = [
'extra-sandbox-profile.sh',
'regression-484.sh',
'redirected-filter-source.sh',
'warn-import-from-derivation.sh',
]
# Plugin tests require shared libraries support.
@@ -0,0 +1,8 @@
source common.sh
clearStore
nix-build ./import-derivation.nix \
--no-out-link \
--option warn-import-from-derivation true \
2>&1 | grepQuiet "warning: building '.*' during evaluation due to the use of import from derivation"