nix: repl: segmentation fault

Running -unstable in a single core VM with 2G RAM:

   nixos\-version   20\.03pre196836\.1c40ee6fc44 \(Markhor\)    grep MemTotal /proc/meminfo
  MemTotal: 2041736 kB

The following steps led to the crash immediately after boot in complete
idle state:

  # nix repl '<nixpkgs>'
  Welcome to Nix version 2.3.1. Type :? for help.

  Loading '<nixpkgs>'...
  Added 10966 variables.

  nix-repl> :l <nixpkgs/nixos>
  Added 6 variables.

I then curiously looked through various variables by tab completing on
`config.` and eventually printing the following variables in the exact
order of listing; full output redacted for the sake of readability:

  nix-repl> config.boot.kernelModules
  nix-repl> config
  nix-repl> config.fileSystems
  nix-repl> config.zramSwap
  nix-repl> config.system
  nix-repl> config.environemnt
  ^C^P^C

  ^C

  Segmentation fault (core dumped)

All variables were properly printed except the last one. Note how
"environemnt" was mistyped. "^C^P^C<Enter>^C<Enter>" was typed
literally as I noticed it hanging.

Backtrace:

#0 0x000000000049e37b in nix::EvalState::forceValue(nix::Value&, nix::Pos const&) ()
#1 0x00007fa4ca0887b4 in nix::ExprVar::eval(nix::EvalState&, nix::Env&, nix::Value&) ()
   from /nix/store/cqzmhhibmhw5h92qwjd0ki4y4jhk0pl4-nix-2.3.1/lib/libnixexpr.so
#2 0x00007fa4ca089f1e in nix::ExprSelect::eval(nix::EvalState&, nix::Env&, nix::Value&) ()
   from /nix/store/cqzmhhibmhw5h92qwjd0ki4y4jhk0pl4-nix-2.3.1/lib/libnixexpr.so
#3 0x00000000004e4a1b in nix::NixRepl::evalString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, nix::Value&) ()
#4 0x00000000004e7760 in nix::NixRepl::processLine(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) ()
#5 0x00000000004e7ce2 in nix::NixRepl::mainLoop(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) ()
#6 0x00000000004e965b in nix::CmdRepl::run(nix::ref<nix::Store>) ()
#7 0x00000000004b7449 in nix::StoreCommand::run() ()
#8 0x00000000004d57c8 in nix::mainWrapped(int, char**) ()
#9 0x00007fa4c9d8201c in nix::handleExceptions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>)
    ()
   from /nix/store/cqzmhhibmhw5h92qwjd0ki4y4jhk0pl4-nix-2.3.1/lib/libnixmain.so
#10 0x0000000000441fab in main ()

I saved both executable and core dump for later inspection, feel free
to ask for further details.

I cannot reproduce this issue.

1 Like