From fb76a4d33565b596e7d58a32648353692ea453be Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 6 Dec 2024 00:59:53 +0100 Subject: [PATCH] libcmd: munge evalSettings in the right place these must be tampered with before the evaluator is created, *never* after. doing it any other way leads to interesting things like #596. fixes #596 Change-Id: Iea253ccce44b94b1243833837a3df93c795967d9 --- lix/libcmd/command.hh | 4 +++- lix/libcmd/installables.cc | 18 ++++++++++-------- tests/functional/impure-eval.sh | 3 +++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lix/libcmd/command.hh b/lix/libcmd/command.hh index 3a55b1532..90199145c 100644 --- a/lix/libcmd/command.hh +++ b/lix/libcmd/command.hh @@ -77,7 +77,7 @@ struct EvalCommand : virtual StoreCommand, MixEvalArgs ref getEvalStore(); - ref getEvaluator(); + virtual ref getEvaluator(); private: std::shared_ptr evalStore; @@ -114,6 +114,8 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions SourceExprCommand(); + ref getEvaluator() override; + Installables parseInstallables( EvalState & state, ref store, std::vector ss); diff --git a/lix/libcmd/installables.cc b/lix/libcmd/installables.cc index d2d64730d..9970d4319 100644 --- a/lix/libcmd/installables.cc +++ b/lix/libcmd/installables.cc @@ -212,9 +212,7 @@ void SourceExprCommand::completeInstallable(EvalState & state, AddCompletions & if (file) { completions.setType(AddCompletions::Type::Attrs); - evalSettings.pureEval.override(false); auto evaluator = getEvaluator(); - evaluator->paths.allowedPaths.reset(); Expr & e = evaluator->parseExprFromFile( resolveExprPath(evaluator->paths.checkSourcePath(lookupFileArg(*evaluator, *file))) @@ -427,6 +425,16 @@ ref openEvalCache( } } +ref SourceExprCommand::getEvaluator() +{ + // FIXME: backward compatibility hack + if (file) { + evalSettings.pureEval.override(false); + } + + return EvalCommand::getEvaluator(); +} + Installables SourceExprCommand::parseInstallables( EvalState & state, ref store, std::vector ss) { @@ -436,12 +444,6 @@ Installables SourceExprCommand::parseInstallables( if (file && expr) throw UsageError("'--file' and '--expr' are exclusive"); - // FIXME: backward compatibility hack - if (file) { - evalSettings.pureEval.override(false); - getEvaluator()->paths.allowedPaths.reset(); - } - auto evaluator = getEvaluator(); auto vFile = evaluator->mem.allocValue(); diff --git a/tests/functional/impure-eval.sh b/tests/functional/impure-eval.sh index 6c72f01d7..c06a8361c 100644 --- a/tests/functional/impure-eval.sh +++ b/tests/functional/impure-eval.sh @@ -33,3 +33,6 @@ simpleTest 'builtins.currentSystem' 'bar' --eval-system 'bar' ## `eval-system` overrides `system` simpleTest 'builtins.currentSystem' 'bar' --system 'foo' --eval-system 'bar' simpleTest 'builtins.currentSystem' 'baz' --system 'foo' --eval-system 'baz' + +## `-f` honors nix-path +[ "$(nix eval --option nix-path "foo=$PWD" -f '' attr.foo)" = '"bar"' ]