Setting up CUDA development on NixOS has two high-level steps:
- Setting up your GPU and its drivers
- Setting up CUDA compilation and runtime
Drivers
Setting up your GPU is decently explained on the NixOS Cuda page. I'm using an eGPU (GTX 1070) connected to my laptop through a thunderbolt port. Therefore, my NixOS contains a module that looks like this:
This will set up the drivers for the GPU, and (specific to my configuration) will identify the bus ids of the respective GPUs.
Runtime
          Then, we can set up a shell.nix for local development. (Sorry flake.nix friends):
        
          Now, you can use nvcc to compile CUDA applications. Additionally, LD_LIBRARY_PATH is
          properly set up to make the CUDA shared libraries discoverable at runtime.
        
LSP
          Lastly, if you're using clangd as an LSP server, CUDA_PATH is taken care of you will have to create a .clangd file
          containing the --cuda-gpu-arch flag to identify the compute capability of your GPU: