diff --git a/lix/libcmd/repl.cc b/lix/libcmd/repl.cc index 4cf3e8128..9acb7ef99 100644 --- a/lix/libcmd/repl.cc +++ b/lix/libcmd/repl.cc @@ -544,6 +544,7 @@ ProcessLineResult NixRepl::processLine(std::string line) << " :bl Build a derivation, creating GC roots in the\n" << " working directory\n" << " :e, :edit Open package or function in $EDITOR\n" + << " :env Show env stack\n" << " :i Build derivation, then install result into\n" << " current profile\n" << " :l, :load Load Nix expression and add it to scope\n" @@ -566,7 +567,6 @@ ProcessLineResult NixRepl::processLine(std::string line) std::cout << "\n" << " Debug mode commands\n" - << " :env Show env stack\n" << " :bt, :backtrace Show trace stack\n" << " :st Show current trace\n" << " :st Change to another trace in the stack\n" @@ -588,14 +588,16 @@ ProcessLineResult NixRepl::processLine(std::string line) } else if (command == ":env") { - if (!inDebugger) - throw Error("env command is only available in debug mode (see %s)", "--debugger"); - auto traces = evaluator.debug->traces(); - for (const auto & [idx, i] : enumerate(traces)) { - if (idx == debugTraceIndex) { - printEnvBindings(state, i->expr, i->env); - break; + if (inDebugger) { + auto traces = evaluator.debug->traces(); + for (const auto & [idx, i] : enumerate(traces)) { + if (idx == debugTraceIndex) { + printEnvBindings(state, i->expr, i->env); + break; + } } + } else { + printEnvBindings(state.ctx.symbols, *staticEnv, *env, 0); } } diff --git a/tests/functional/repl_characterization/data/repl_printing.test b/tests/functional/repl_characterization/data/repl_printing.test index 1206281e7..c9836efbb 100644 --- a/tests/functional/repl_characterization/data/repl_printing.test +++ b/tests/functional/repl_characterization/data/repl_printing.test @@ -90,3 +90,13 @@ they aren't the top level item being printed. }; }; } + +Printing an environment with :env after adding a variable to the scope + + nix-repl> foo = "bar" + nix-repl> :env + Env level 0 + static: foo + + Env level 1 + abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true