Repository navigation
Closed
Description
Describe the bug
Certain chain of builtins.toFile calls lead to the repl crash
Steps To Reproduce
I managed to reproduce the issue consistently with these three repl commands. Inside the repl, do:
builtins.toFile "name" "${./not-found.txt}". It should result inpath '/home/threetimeslazy/.../not-found.txt' does not existbuiltins.toFile "hi" "hi"or any successful call to the builtin. It usually returnsend of string reached.- Run the command from step 2. again. The repl should crash at this point
Here's a full output sample of running these steps:
nix-repl> builtins.toFile "name" "${./not-found.txt}"
error:
… while calling the 'toFile' builtin
at «string»:1:1:
1| builtins.toFile "name" "${./not-found.txt}"
| ^
… while evaluating the second argument passed to builtins.toFile
error: path '/home/threetimeslazy/not-found.txt' does not exist
nix-repl> builtins.toFile "hi" "hi"
error:
… while calling the 'toFile' builtin
at «string»:1:1:
1| builtins.toFile "hi" "hi"
| ^
error: end of string reached
nix-repl> builtins.toFile "hi" "hi"
terminating due to unexpected unrecoverable internal error: Assertion 'block' failed in std::__exception_ptr::exception_ptr nix::WorkerProto::BasicClientConnection::processStderrReturn(nix::Sink*, nix::Source*, bool, bool) at ../worker-protocol-connection.cc:101
Nix crashed. This is a bug. Please report this at https://github.com/NixOS/nix/issues with the following information included:
std::terminate() called without exception
Stack trace:
0# 0x00000000001124AE in nix
1# 0x00000000000C539A in /nix/store/hngmi01i8wgi25a0byrxcn4ysz5j79mw-gcc-15.2.0-lib/lib/libstdc++.so.6
2# std::unexpected() in /nix/store/hngmi01i8wgi25a0byrxcn4ysz5j79mw-gcc-15.2.0-lib/lib/libstdc++.so.6
3# 0x00000000000E92EF in /nix/store/l5p52saf0rh1fspzwfx32813pb1ap597-nix-util-2.34.7/lib/libnixutil.so.2.34.7
4# __wrap___assert_fail in /nix/store/0hin4abpq9yk7zrl1x0v0yaw1x8yjpy6-nix-store-2.34.7/lib/libnixstore.so.2.34.7
5# 0x000000000012DFCF in /nix/store/0hin4abpq9yk7zrl1x0v0yaw1x8yjpy6-nix-store-2.34.7/lib/libnixstore.so.2.34.7
6# 0x0000000000378266 in /nix/store/0hin4abpq9yk7zrl1x0v0yaw1x8yjpy6-nix-store-2.34.7/lib/libnixstore.so.2.34.7
7# 0x0000000000318787 in /nix/store/0hin4abpq9yk7zrl1x0v0yaw1x8yjpy6-nix-store-2.34.7/lib/libnixstore.so.2.34.7
8# nix::RemoteStore::ConnectionHandle::withFramedSink(nix::fun<void (nix::Sink&)>) in /nix/store/0hin4abpq9yk7zrl1x0v0yaw1x8yjpy6-nix-store-2.34.7/lib/libnixstore.so.2.34.7
9# nix::RemoteStore::addCAToStore(nix::Source&, std::basic_string_view<char, std::char_traits<char> >, nix::ContentAddressMethod, nix::HashAlgorithm, std::set<nix::StorePath, std::less<nix::StorePath>, std::allocator<nix::StorePath> > const&, nix::RepairFlag) in /nix/store/0hin4abpq9yk7zrl1x0v0yaw1x8yjpy6-nix-store-2.34.7/lib/libnixstore.so.2.34.7
10# nix::RemoteStore::addToStoreFromDump(nix::Source&, std::basic_string_view<char, std::char_traits<char> >, nix::FileSerialisationMethod, nix::ContentAddressMethod, nix::HashAlgorithm, std::set<nix::StorePath, std::less<nix::StorePath>, std::allocator<nix::StorePath> > const&, nix::RepairFlag) in /nix/store/0hin4abpq9yk7zrl1x0v0yaw1x8yjpy6-nix-store-2.34.7/lib/libnixstore.so.2.34.7
11# 0x0000000000137F4B in /nix/store/prs3vvry5dw9gqy7frwg1ny119swakjs-nix-expr-2.34.7/lib/libnixexpr.so.2.34.7
12# nix::EvalState::callFunction(nix::Value&, std::span<nix::Value*, 18446744073709551615ul>, nix::Value&, nix::PosIdx) in /nix/store/prs3vvry5dw9gqy7frwg1ny119swakjs-nix-expr-2.34.7/lib/libnixexpr.so.2.34.7
13# nix::ExprCall::eval(nix::EvalState&, nix::Env&, nix::Value&) in /nix/store/prs3vvry5dw9gqy7frwg1ny119swakjs-nix-expr-2.34.7/lib/libnixexpr.so.2.34.7
14# nix::NixRepl::evalString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, nix::Value&) in /nix/store/z8sp8bniwl5mxqnqprrjzsvhyhx94waz-nix-cmd-2.34.7/lib/libnixcmd.so.2.34.7
15# nix::NixRepl::processLine(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) in /nix/store/z8sp8bniwl5mxqnqprrjzsvhyhx94waz-nix-cmd-2.34.7/lib/libnixcmd.so.2.34.7
16# nix::NixRepl::mainLoop() in /nix/store/z8sp8bniwl5mxqnqprrjzsvhyhx94waz-nix-cmd-2.34.7/lib/libnixcmd.so.2.34.7
17# 0x00000000001D61B5 in nix
18# nix::RawInstallablesCommand::run(nix::ref<nix::Store>) in /nix/store/z8sp8bniwl5mxqnqprrjzsvhyhx94waz-nix-cmd-2.34.7/lib/libnixcmd.so.2.34.7
19# nix::StoreCommand::run(nix::ref<nix::StoreConfig>) in /nix/store/z8sp8bniwl5mxqnqprrjzsvhyhx94waz-nix-cmd-2.34.7/lib/libnixcmd.so.2.34.7
20# virtual thunk to nix::StoreConfigCommand::run() in /nix/store/z8sp8bniwl5mxqnqprrjzsvhyhx94waz-nix-cmd-2.34.7/lib/libnixcmd.so.2.34.7
21# 0x000000000019FADB in nix
22# nix::handleExceptions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, nix::fun<void ()>) in /nix/store/l5p52saf0rh1fspzwfx32813pb1ap597-nix-util-2.34.7/lib/libnixutil.so.2.34.7
23# 0x00000000000E1A0B in nix
24# 0x000000000002B285 in /nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libc.so.6
25# __libc_start_main in /nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libc.so.6
26# 0x00000000000E6675 in nix
zsh: abort (core dumped) nix repl
Expected behavior
I'd expect the first call to fail, but subsequent calls to return a valid value instead. In that case, i'd be
nix-repl> builtins.toFile "hi" "hi"
"/nix/store/fd6846zv66nhsbwjaijjqbykvk60smps-hi"
Metadata
nix-env (Nix) 2.34.7
Additional context
Checklist
- checked latest Nix manual (source)
- checked open bug issues and pull requests for possible duplicates
- reviewed the contributing guide
Add 👍 to issues you find important.
Activity
xokdvium commentedon Jul 20, 2026
Oh huh, this is quite a convoluted crash. This is quite certainly (at least me looking in the debugger and staring at the code) due to our usage of stackful coroutines and some weirdness around marking connections bad? This doesn't really affect just
toFile(or has anything to do with it actually). The initial error when trying to add a path to the store via path interpolation in the"${./not-found.txt}"expression. Needs a bit more debugging though.xokdvium commentedon Jul 20, 2026
Generally, boost's forced_unwind should lead us to properly unwind the stack and mark a connection as bad, but that doesn't seem to be working hmmmm.
xokdvium commentedon Jul 21, 2026
Indeed this is a boost "nuance" (hopefully upstream treats it as a bug). Applying this patch to the nix tree (along with a patch to boost.context) fixes the issue:
xokdvium commentedon Jul 21, 2026
I have submitted boostorg/context#337, let's see how that pans out. Though we'd probably still need some workaround even if that was merged. Probably depending on the review on the patch it'd be clearer what the best shape of the workaround would be.
xokdvium commentedon Jul 22, 2026
Ok we seem to have agreed to go with applying my patch to our dependencies. If this goes well on master for a bit we'll also backport to our packaging and also apply it in nixpkgs to the nix's boost dependency.
Add boost.context patch for std::uncaught_exceptions() misreporting 0…
xokdvium commentedon Jul 27, 2026
NixOS/nixpkgs#546405 is now up for boost.context patches backport in nixpkgs. That should address the underlying issue here.
Add boost.context patch for std::uncaught_exceptions() misreporting 0…
xokdvium commentedon Aug 13, 2026
This is now fixed in nixpkgs and in our binary builds in 2.35.2. Boost patches are in unstable and 26.05 staging now.
3timeslazy commentedon Aug 16, 2026
Thank you for detailed overview! I checked again from the main branch, the issue is gone
Add boost.context patch for std::uncaught_exceptions() misreporting 0…
flake: Drop Nix's extra boost patches
flake: Drop Nix's extra boost patches
flake: Drop Nix's extra boost patches
flake: Drop Nix's extra boost patches