nix/install: Rewrite to not rely on bashisms.

Gets rid of `[[ ... ]]` and provides a fallback to `which` if the `type` builtin is not available.

Also, this now longer relies on "set -e", because we're checking the errors carefully by ourselves and properly clean up whenever there was an error.