Strange bash script behaviour in fish shell

I have recently switched to nix from arch. I have also started using fish as my usershell. I have been using neovim with lsp-zero with mason configured. My configuration works out of the box. But now some lsp clients are not working. I have checked the logs. There does not seem any issue with mason or the configurations. One such lsp is lua-language-server.

Here is an example:

❯ echo $SHELL

❯ pwd

❯ cat lua-language-server
#!/usr/bin/env bash

exec "/home/groot/.local/share/nvim/mason/packages/lua-language-server/libexec/bin/lua-language-server" "$@"

❯ ./lua-language-server
./lua-language-server: line 3: /home/groot/.local/share/nvim/mason/packages/lua-language-server/libexec/bin/lua-language-server: cannot execute: required file not found

But the file is there for sure.

❯ la /home/groot/.local/share/nvim/mason/packages/lua-language-server/libexec/bin/lua-language-server
-rwxr-xr-x 1 groot users 2.2M Jun 14 13:41 /home/groot/.local/share/nvim/mason/packages/lua-language-server/libexec/bin/lua-language-server

I can’t seem to find any issue with mason or zero-lsp.

As I am new to nix, I can only hope there is something i don’t know about with how bash script is supposed to work in a fish shell in nix.

I don’t know if this might be reproducible. I tried removing the nvim cache and data folder and re-installing all the plugins and so on.

From the error message, it looks like an issue with how dynamic binaries work on NixOS, instead of your user shell. You should see a similar error message if you run mason’s lua-language-server in bash.

The simple solution is to use lua-language-server from nixpkgs, you can add it to your NixOS configuration or enter an environment with lua-language-server with either nix-shell -p lua-language-server or nix shell nixpkgs#lua-language-server (with flakes)


Thanks. Now i get it why it is behaving this way.

But instead of working around it, how do i solve it? I might get many more dynamic linking executables in the future as i do ctfs often. And each time, I just simply cannot deal with it as the binaries will not be in the nixpkgs.

From a NixOS point of view, your sense of what is the solution and what is the workaround is backwards. :wink:

But there is a Nix tool for doing what you want (running unpatched dynamic binaries on NixOS)! It’s called nix-ld. :slight_smile:

If you’ve got a specific binary that you’ve pulled down from a server you’re trying to pwn for a game of capture the flag, you might also sometimes find it appropriate to craft a special environment to wrap just that package which reflects it’s specific needs.

For that kind of approach, Nixpkgs provides autoPatchElfHook, and you can find examples of its usage with proprietary software packages in Nixpkgs. The same goes for buildFHSEnv, which runs a binary in a chroot environment with a normal FHS layout.

There are also some interactive tools that try to automate setting up a suitable environment for binaries like that. The two I know of are also linked in the readme for nix-ld: nix-alien and nix-autobahn.

In a pinch, many NixOS users just use steam-run to run a given binary in a fairly complete FHS environment.