It only happens for derivations with preferLocalBuild = true;
$ nix build --system x86_64-linux --impure --expr 'with import <nixpkgs> {}; runCommand "foo" { preferLocalBuild = true; } "touch $out"'
error: builder for '/nix/store/y69h2h703kwvryj28sn9mspr41sh7ncl-foo.drv' failed with exit code 126;
last 1 log lines:
> /nix/store/2r9n7fz1rxq088j6mi5s7izxdria6d5f-bash-5.1-p16/bin/bash: /nix/store/2r9n7fz1rxq088j6mi5s7izxdria6d5f-bash-5.1-p16/bin/bash: cannot execute binary file
For full logs, run 'nix log /nix/store/y69h2h703kwvryj28sn9mspr41sh7ncl-foo.drv'.
Nix thinks it’s an x86_64-linux when it’s not, sees preferLocalBuild
, and decides to try to build a linux derivation locally on a darwin machine.