with builtins;
with import <nixpkgs> {};

(overrideCC stdenv gcc6).mkDerivation rec {
  name = "gpu";

  ignore = map toString [
    ./default.nix
    ./data
    ./log
  ];
  src = filterSource (path: type: !elem path ignore) ./.;

  nativeBuildInputs = [
    cmake
    cudatoolkit linuxPackages.nvidia_x11 makeWrapper
  ];

  preBuild = ''
    export CUDA_PATH="${cudatoolkit}"
  '';

  installPhase = ''
    mkdir -p $out/bin
    find . -executable -exec cp {} $out/bin/ \;

    wrapProgram $out/bin/main \
      --prefix LD_LIBRARY_PATH ":" "${linuxPackages.nvidia_x11}/lib"
  '';
}