With nix, I can write shell scripts that require some packages by using nix-shell as the interpreter.

To do this, I just need to put nix-shell in the shebang:

#! /usr/bin/env nix-shell
#! nix-shell -i bash -p python3 python3.pkgs.requests
response = requests.get(os.getenv($SOME_URL))
print(response.content())

In this example, the script will be ran by python 3 with the requests package ready to use.

This is quite useful when I want to make a quick script that needs one or two packages and I don’t want to run nix-shell -p <package1> <package2> every time I want to run.

For a more in-depth view into nix in shebangs, I thoroughly recommend this NixOS wiki page.