How do I set cmakeFlags that point to a library?

default.nix:

...
 cmakeFlags = [ 
  "DCUDA_LIB=/usr/local/cuda/lib64/stubs/libcuda.so"
  "DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda"
 ]
...

Which produces an error:

build/DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda" does not exist.

The command to build it:

nix-build --keep-failed --expr 'with import <nixpkgs> {}; callPackage ./default.nix {}'

This path doesn’t exist in the sandbox. If you really need to do this you can turn the sandbox off in /etc/nix/nix.conf but this isn’t recommended. The recommendation would be to use a library packaged for nixpkgs, or package the library you need as well.