diff --git a/doc/manual/change-authors.yml b/doc/manual/change-authors.yml index b3871c9eb..92b782f4e 100644 --- a/doc/manual/change-authors.yml +++ b/doc/manual/change-authors.yml @@ -99,6 +99,9 @@ goldstein: forgejo: goldstein github: GoldsteinE +gustavderdrache: + github: gustavderdrache + horrors: display_name: eldritch horrors forgejo: pennae diff --git a/doc/manual/rl-next/warn-import-from-derivation.md b/doc/manual/rl-next/warn-import-from-derivation.md new file mode 100644 index 000000000..c0af6a40a --- /dev/null +++ b/doc/manual/rl-next/warn-import-from-derivation.md @@ -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`. diff --git a/lix/libexpr/meson.build b/lix/libexpr/meson.build index 0552dff2c..fff97b8f7 100644 --- a/lix/libexpr/meson.build +++ b/lix/libexpr/meson.build @@ -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( diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index d2501c26a..53f646b31 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -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 buildReqs; for (auto & d : drvs) buildReqs.emplace_back(DerivedPath { d }); diff --git a/lix/libexpr/settings/warn-import-from-derivation.md b/lix/libexpr/settings/warn-import-from-derivation.md new file mode 100644 index 000000000..30c3ec26d --- /dev/null +++ b/lix/libexpr/settings/warn-import-from-derivation.md @@ -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`. diff --git a/tests/functional/meson.build b/tests/functional/meson.build index c475f8758..87e195a83 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -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. diff --git a/tests/functional/warn-import-from-derivation.sh b/tests/functional/warn-import-from-derivation.sh new file mode 100644 index 000000000..9a424ddcb --- /dev/null +++ b/tests/functional/warn-import-from-derivation.sh @@ -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"