I have just installed NixOS and have a bunch of shell scripts that I would like to install. I’m wondering how best to do it without having to edit them to adapt the paths to various executables in them, or if there is an automatic way to patch them while building the derivation.
First of all, I suppose I can still use my scripts without having to package them with nix. I used to just have my scripts in my home directory and set my PATH to point to them. I think I can keep it that way in nix.
But I guess the nix approach would be to create a derivation such that my scripts are installed into the nix store. I’m wondering which way I should chose and why. The nix way gives the advantage of easy reproducibility: once packaged, I’ll be sure that my scripts will always be installed along with the appropriate dependencies.
However, this requires changing the paths in my scripts to the various executables and other files that are used. For example, if a script uses the program
hello, I must make sure that the packaged script will use the right
hello, i.e. put something like
$out/bin/hello, and let nix set the environment variable $out to refer to the right path in the nix-store.
I’m reluctant to do this for two reasons. First, I’m lazy. Second, my scripts would become dependent on nix. I’d loose the possibility to easily send my script to someone who doesn’t use nix: if that person tries to execute it, the path
$out/bin/hello in the script will mean nothing.
I think I haven’t grabbed enough on nix yet to find a satisfying solution to this. What would be a good approach there? Is trying to package my personal scripts with nix going too far and should I use my good old $PATH and just use nix to install the dependencies?