Running a Stack-heavy binary in mkDerivation results in a Segmentation fault

Hi folks,

I have my own program in Rust that takes a JSON, does some calculations and then returns another JSON. I can build the program using Nix without a problem. The problem is then to run the program, since recently I started getting a Segmentation fault error when the program runs inside mkDerivation.

The solution was to Box a few things inside the program (to move some data structures from Stack to Heap), but I’m worried that this will be an ongoing issue, and I’ll have to make changes only to make it runnable in derivation.

If I simply run the program with the same data and the same arguments as the derivation, it works just fine. I also tried to run ulimit -s 8192 in Bash and then run the program, and that also works. Which makes me question how it is possible to fail inside the derivation? By boxing, I tested that decreasing Stack usage helps, but I don’t understand why it’s needed.

Thank you.

Program arguments (argv) and environment variables are also stored on the stack, maybe the mkDerivation environment had more environment variables or the data within was longer which meant it took more space on the stack.

What OS are you running on? And which Nix version? Is there any public repro I can poke at?

Hi folks,

thank you for the tips. Unfortunately I can’t share the Rust code. I’m running NixOS 25.11.

I’ve just tested it in terminal - it works with ulimit -s 1024 and it breaks (Segmentation fault) with ulimit -s 512,