nix-ld icon indicating copy to clipboard operation
nix-ld copied to clipboard

Decouple configuration from activation

Open tobiasBora opened this issue 3 years ago • 2 comments

In order to easily run applications on the system that are not patched (steam-run is not practical at all and integrates poorly with the host system) I set NIX_LD and NIX_LD_LIBRARY_PATH on my whole system. It worked great so far but I don't really like the idea that my system may be less reproducible as nix-ld is now always enabled. So I would love instead if nix-ld could read an environment variable like NIX_ENABLE_FHS that would enable it if it is set. Of course I could manually set NIX_LD_LIBRARY_PATH when I want a shell but it is not as practical to manually specify a huge list of items. Moreover I am also thinking to use this same environment variable to enable other systems like a /bin/bash or other programs (for modularity one could also define another environment variable when one wants to enable only nix_ld but not /bin/bash).

This also have the advantage that if the NIX_ENABLE_FHS is not set, then the user can get a meaningful error explaining that the loader /lib are disabled by default but could easily be enabled (in a quick and dirty way) by setting the above environment variable or by writting a proper derivation. We could also provide more meaningful default values that can run most programs. This way, nix-ld could even be set by default on nixos to provide more helpful help messages.

Do you think it would make sense to integrate this into nix-ld or should I create my own project to test these ideas?

tobiasBora avatar Sep 26 '22 22:09 tobiasBora

How about a bash/zsh function that sources NIX_LD and NIX_LD_LIBRARY_PATH on demand?

Mic92 avatar Nov 04 '22 12:11 Mic92

Sounds great as it avoids breaking existing stuff, and it seems quite flexible (we could fetch the data the first time the user uses the command, provide various "profiles" depending on the apps to install…). Just it may be a bit annoying to write one function for every shell (there are many more shells than zsh and bash), but we can certainly eithen start a new shell like nix-shell to populate the variables and drop the user in it's wanted shell after (just if a user wants to enable it in it's .bashrc/.profile it would not work ), or additionally provide values in NIX_LD_DEFAULT so that one can just write a few export NIX_LD=NIX_LD_DEFAULT if needed. Or explicitely ask the user to pipe the output to exec or alike, providing multiple options depending on the shell.

tobiasBora avatar Nov 19 '22 08:11 tobiasBora