Nixy way to execute some bash code before app start

On my old linux distro I used a trick to execute some code before each launch of an application:
I created a script with that name in ~/.local/bin which executed the code, then called the application in /bin.
E.g. I used this for setting a specific java version before launching eclipse. What would be the nixy way to add code surrounding the run of an application?

What exactly are you trying to achieve? Not the solution but the end goal.

We often wrap programs to change the environment variables they run in. To, for example, change the JAVA_HOME or add a dependency to the PATH.
You could create a derivation yourself with the desired wrapper.

What exactly did your script on other distros do? Is it just a bash script that sets some environment variables and then executes the program? Why can’t you do that with nix?

I assume you’re using NixOS, not just Nix?

1 Like