From a5c9b10083ffedd0c16e10eb5a1e8cad86bf9383 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 23 Mar 2025 22:10:43 +0000 Subject: [PATCH 1/3] libcmd/repl: Make `AbstractNixRepl::create` respect its `store` argument The only reference (according to clangd) to this function also uses `openStore`, so this is a no-op. (cherry picked from commit 8066e4b0c30d68bd7431f8a8c9c11d44765b0bf9) --- src/libcmd/repl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 281e1f6f0..68bf41329 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -839,7 +839,7 @@ std::unique_ptr AbstractNixRepl::create( { return std::make_unique( lookupPath, - openStore(), + std::move(store), state, getValues ); From 49fa3e186981ef8dece5486d5d6ddf9b38a9d10a Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 23 Mar 2025 22:13:14 +0000 Subject: [PATCH 2/3] libcmd/repl: Fix missing `runNix` in repl Without this :u, :sh and :i repl commands fail with: > Cannot run 'nix-shell'/`nix-env` because no method of calling the Nix > CLI was provided. This is a configuration problem pertaining to how > this program was built. Remove the default ctor argument as it evidently makes catching refactoring bugs much harder. `NixRepl` implementation lives completely in `repl.cc`, so we can be as explicit as necessary. (cherry picked from commit 44055dc09d12e85c3187a1a793c129ccb5d89050) --- src/libcmd/repl.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 68bf41329..38b219643 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -124,7 +124,7 @@ std::string removeWhitespace(std::string s) NixRepl::NixRepl(const LookupPath & lookupPath, nix::ref store, ref state, - std::function getValues, RunNix * runNix = nullptr) + std::function getValues, RunNix * runNix) : AbstractNixRepl(state) , debugTraceIndex(0) , getValues(getValues) @@ -841,7 +841,8 @@ std::unique_ptr AbstractNixRepl::create( lookupPath, std::move(store), state, - getValues + getValues, + runNix ); } @@ -859,7 +860,8 @@ ReplExitStatus AbstractNixRepl::runSimple( lookupPath, openStore(), evalState, - getValues + getValues, + /*runNix=*/nullptr ); repl->initEnv(); From 20ce98f87bf7e09724880e171bbf90ca8e44bcf3 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 23 Mar 2025 22:13:40 +0000 Subject: [PATCH 3/3] tests/functional: Add regression test for broken `:sh` in repl Can't really test `:u` because it needs . (cherry picked from commit d371aadb2b6587572ce84f3899c19ae9d14eb435) --- tests/functional/repl.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/functional/repl.sh b/tests/functional/repl.sh index 59d1f1be0..5d99fbb02 100755 --- a/tests/functional/repl.sh +++ b/tests/functional/repl.sh @@ -56,6 +56,10 @@ testRepl () { nix repl "${nixArgs[@]}" 2>&1 <<< "builtins.currentSystem" \ | grep "$(nix-instantiate --eval -E 'builtins.currentSystem')" + # regression test for #12163 + replOutput=$(nix repl "${nixArgs[@]}" 2>&1 <<< ":sh import $testDir/simple.nix") + echo "$replOutput" | grepInverse "error: Cannot run 'nix-shell'" + expectStderr 1 nix repl "${testDir}/simple.nix" \ | grepQuiet -s "error: path '$testDir/simple.nix' is not a flake" }