Envfs: fix shebangs on NixOS

Many projects have shell scripts with shebangs to absolute executables i.e. /usr/bin/python.
Patching all those instances can be tedious and annoying.
That’s why I build envfs fuse filesystem.
envfs is mounted to /usr/bin and returns for symlinks based on what is the process PATH environment variable:

$ ls -l /usr/bin/{bash,python}
lr----x--t 0 root  1 Jan  1970  /usr/bin/bash -> /nix/store/j37555sj2w3xsql3f8qrwbaim7pv67hg-bash-interactive-4.4-p23/bin/bash
lr----x--t 0 root  1 Jan  1970  /usr/bin/python -> /home/joerg/.nix-profile/bin/python
$ cat > foo.py <<EOF
#!/usr/bin/python
print("hello world")
EOF
$ chmod +x ./foo.py
$ ./foo.py
hello world

Set up instruction are on the project page.
Cheers!

23 Likes

Looks interesting! I wonder if it could also support customized environment variables, not only PATH, so that we can build a /usr/lib to solve Any way for LD_LIBRARY_PATH to *not* break nix-env's absolute paths for dynamic libs · Issue #902 · NixOS/nix · GitHub

Essentially it can be used to implement LD_FALLBACK_PATH like glibc: implement `LD_FALLBACK_PATH` environment variable by oxij · Pull Request #248547 · NixOS/nixpkgs · GitHub while not having to patch glibc

nix-ld is solving this gap for me.

We still suffer from Any way for LD_LIBRARY_PATH to *not* break nix-env's absolute paths for dynamic libs · Issue #902 · NixOS/nix · GitHub even with nix-ld

Try out nix-ld-rs, which doesn’t pollute child processes with LD_LIBRARY_PATH