Writing a derivation for a small script really doesn’t have to be hard. There are lots of shortcuts available in nixpkgs for simple things. For example, with python, you can do something like this:
pkgs.writers.writePython3 "myscript" {
libraries = with pkgs.python3Packages; [ numpy ];
} ./myscript.py
(Use writePython3Bin
if you want the output to be formatted like a package with a bin
directory, rather than a bare script in the nix store.)
You can also use a nix-shell
shebang to make standalone scripts grab their environment through nix at the time they’re run. You can even combine the two approaches, so that myscript.py
has a nix-shell
shebang for rapid iteration during development of the script itself, which is then overwritten by pkgs.writers.writePython3
when used normally as part of your configuration.
Many ecosystems have similar things available.