From d46f741cdfcb4b9b6aed5532dec7fe62f1e3cb72 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 30 Apr 2025 22:29:27 +0200 Subject: [PATCH] Complain when using --pure-eval with --file This never worked and cannot work because in pure eval mode, the evaluator doesn't have access to the file. --- src/libcmd/installables.cc | 6 +++++- tests/functional/eval.sh | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 1c414e9e2..080557d4f 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -491,7 +491,11 @@ Installables SourceExprCommand::parseInstallables( throw UsageError("'--file' and '--expr' are exclusive"); // FIXME: backward compatibility hack - if (file) evalSettings.pureEval = false; + if (file) { + if (evalSettings.pureEval && evalSettings.pureEval.overridden) + throw UsageError("'--file' is not compatible with '--pure-eval'"); + evalSettings.pureEval = false; + } auto state = getEvalState(); auto vFile = state->allocValue(); diff --git a/tests/functional/eval.sh b/tests/functional/eval.sh index ed9c214f5..f876f5ac4 100755 --- a/tests/functional/eval.sh +++ b/tests/functional/eval.sh @@ -39,6 +39,9 @@ nix-instantiate --eval -E 'assert 1 + 2 == 3; true' ln -sfn cycle.nix "$TEST_ROOT/cycle.nix" (! nix eval --file "$TEST_ROOT/cycle.nix") +# --file and --pure-eval don't mix. +expectStderr 1 nix eval --pure-eval --file "$TEST_ROOT/cycle.nix" | grepQuiet "not compatible" + # Check that relative symlinks are resolved correctly. mkdir -p "$TEST_ROOT/xyzzy" "$TEST_ROOT/foo" ln -sfn ../xyzzy "$TEST_ROOT/foo/bar"