7.4 patchShebangs: running scripts in the Nix sandbox
Lesson 50 of 68 · 8:18
Up next in 5s…
About this lesson
Your shell or Python script runs fine on your machine, then dies in the Nix build sandbox with "bad interpreter: No such file or directory". The reason: /usr/bin/env and /usr/bin/bash simply do not exist there. This lesson explains patchShebangs, the stdenv tool that rewrites shebang lines to point at interpreters from your build inputs, and shows when Nix already does it for you automatically.
In this video
- Why the sandbox has no
/usr/bin, and what that means for shell, Python, Perl, and Ruby scripts - What the fixup phase patches automatically after installing, and the exact conditions it needs (one of them is a file permission bit)
- A live demo: a Python script that fails, then works after one line in the derivation
- Testing scripts in
checkPhasebefore installing them, and why that needs a manualpatchShebangscall buildInputsvsnativeBuildInputsfor interpreters, and why the difference matters once cross-compilation enters the picture
After this lesson
You can package any collection of scripts so they run inside the sandbox and on every target machine, with a pinned interpreter instead of whatever the host happens to have.
Builds on: The sandbox (4.2)