That. I used to use bumblebee, but with recent NVidia drivers it's automatic.
That said, if I want to start a process with using the NVidia driver and card I use this script.
#!/bin/bash
__NV_PRIME_RENDER_OFFLOAD=1 \
__GLX_VENDOR_LIBRARY_NAME=nvidia \
__VK_LAYER_NV_optimus=NVIDIA_only \
exec "$@"