I’ve been wondering how exactly does Nix prevent side effects? I tried to manually insert some side effects in the
builder.sh file by inserting a
touch /home/<username>/side-effect in the shell script. When I ran
nix-build, it failed with the following error
touch: cannot touch '/home/<username>/temp/side-effect': No such file or directory
How exactly does this happen, i.e. how does Nix know that this line in the shell script will cause a side effect?
Followup question: if I replace
touch /home/<username>/side-effect with
nix-build runs without errors, but there’s no file named
/tmp anyways? Why is this happening?