NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.79k stars 1.52k forks source link

Not possible to build 32bit binary using emulation on 64bit only processor. `cannot set 32-bit personality: Invalid argument` #6473

Open patryk4815 opened 2 years ago

patryk4815 commented 2 years ago

Describe the bug apple silicon M1 support only 64bit: error: cannot set 32-bit personality: Invalid argument extra info: https://news.ycombinator.com/item?id=27278019

Steps To Reproduce

  1. Enable armv7 emulation manually (because binfmt from nixpkgs not working! issue https://github.com/NixOS/nixpkgs/issues/171297 )
    
    [root@nixos:~]# nix-build '<nixpkgs>' -A pkgsCross.armv7l-hf-multiplatform.hello
    /nix/store/vn06l0k5vh77xg4kbcbb55w4zbqdwbcn-hello-armv7l-unknown-linux-gnueabihf-2.12

[root@nixos:~]# ./result/bin/hello -bash: ./result/bin/hello: cannot execute binary file: Exec format error

[root@nixos:~]# mount -t binfmt_misc none /proc/sys/fs/binfmt_misc

[root@nixos:~]# nix-env -i qemu replacing old 'qemu-7.0.0' installing 'qemu-7.0.0'

[root@nixos:~]# echo ':qemu-arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/root/.nix-profile/bin/qemu-arm:OCF' > /proc/sys/fs/binfmt_misc/register

[root@nixos:~]# ./result/bin/hello Hello, world!

2. Trying to build binary using qemu emulation
```console
[root@nixos:~]# cat /etc/nix/nix.conf | grep extra-platforms
extra-platforms = aarch64-linux armv7l-linux

[root@nixos:~]# nix-build '<nixpkgs>' --argstr system armv7l-linux -A hello
these 107 derivations will be built:
  /nix/store/sr23b3qz26irq0pb7pl75aim8f12irbl-bootstrap-stage0-stdenv-linux.drv
  [...]
  /nix/store/cc43l5irlxhipvih17a89ykl6sr8h80l-stdenv-linux.drv
  /nix/store/x6q9bannddbp934653b20c30bd1sn54l-hello-2.12.drv
error: cannot set 32-bit personality: Invalid argument
(use '--show-trace' to show detailed location information)

Expected behavior Is should be possible to build 32bits binary using emulation.

image

[root@nixos:~]# nix-shell -p nix-info --run "nix-info -m"
 - system: `"aarch64-linux"`
 - host os: `Linux 5.17.3, NixOS, 22.05 (Quokka), 22.05.20220425.6a32390`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.8.0`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

cc: @matthewbauer

patryk4815 commented 1 year ago

Up to avoid stale. Bug still exists on 64bit only cpu, without 32bit support