NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.45k stars 13.65k forks source link

bazelisk: bazel binaries don't run in NixOS #309978

Open cyounkins opened 4 months ago

cyounkins commented 4 months ago

Describe the bug

As noted in the package description, "This package does not work on NixOS". This bug documents the issue.

> nix-shell -p bazelisk

$ cat .bazelversion
6.1.0

$ bazelisk version
Bazelisk version: development
2024/05/07 19:29:17 could not run Bazel: could not start Bazel: fork/exec /home/craig/.cache/bazelisk/downloads/sha256/6c25a6d716545d6b672ec46f770521cd9ebb63d73617b8f4e6747825d1db1839/bin/bazel: no such file or directory

$ /home/craig/.cache/bazelisk/downloads/sha256/6c25a6d716545d6b672ec46f770521cd9ebb63d73617b8f4e6747825d1db1839/bin/bazel
bash: /home/craig/.cache/bazelisk/downloads/sha256/6c25a6d716545d6b672ec46f770521cd9ebb63d73617b8f4e6747825d1db1839/bin/bazel: cannot execute: required file not found

$ file /home/craig/.cache/bazelisk/downloads/sha256/6c25a6d716545d6b672ec46f770521cd9ebb63d73617b8f4e6747825d1db1839/bin/bazel
/home/craig/.cache/bazelisk/downloads/sha256/6c25a6d716545d6b672ec46f770521cd9ebb63d73617b8f4e6747825d1db1839/bin/bazel: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=0b087b9491ae2b0be7dacfa3bfe23bd5c282e4d6, not stripped

$ ls -al /lib64/ld-linux-x86-64.so.2
ls: cannot access '/lib64/ld-linux-x86-64.so.2': No such file or directory

bazelisk pulls down a binary which is expecting the system dynamic linker at /lib64/ld-linux-x86-64.so.2 and gives the confusing "file not found" error.

Patching the interpreter...

$ patchelf --set-interpreter /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/ld-linux-x86-64.so.2 /home/craig/.cache/bazelisk/downloads/sha256/6c25a6d716545d6b672ec46f770521cd9ebb63d73617b8f4e6747825d1db1839/bin/bazel

$ /home/craig/.cache/bazelisk/downloads/sha256/6c25a6d716545d6b672ec46f770521cd9ebb63d73617b8f4e6747825d1db1839/bin/bazel
/home/craig/.cache/bazelisk/downloads/sha256/6c25a6d716545d6b672ec46f770521cd9ebb63d73617b8f4e6747825d1db1839/bin/bazel: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

That's as far as I can take it. Maybe we should patch bazelisk to do the necessary patching of any downloaded binaries?

Notify maintainers

@elasticdog

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

> nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.90, NixOS, 23.11 (Tapir), 23.11.6981.27c13997bf45`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"home-manager-23.11.tar.gz, nixos-23.11, nixpkgs-unstable"`
 - channels(craig): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Add a :+1: reaction to issues you find important.

cyounkins commented 4 months ago

As a workaround, I point people to the Nix package versions project. You can find a few more versions not listed there, for example you can get version 6.1.0 with nix-shell -p bazel -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/be9859e8994910156989cb842a373541fde19bb1.tar.gz

fzakaria commented 2 months ago

Should bazelisk create a FHS ?