anchor.diff:      , name ? ""
       , developerProgram ? false
       , python ? python27
  +    , runPatches ? []
       }:
   
       stdenv.mkDerivation rec {
         name = "cudatoolkit-${version}";
  -      inherit (args) version;
  +      inherit version runPatches;
   
         dontPatchELF = true;
         dontStrip = true;
  
positive.code:             rpath2=$rpath:$lib/lib:$out/jre/lib/amd64/jli:$out/lib:$out/lib64:$out/nvvm/lib:$out/nvvm/lib64
            fi
            patchelf --set-rpath $rpath2 --force-rpath $i
          done < <(find . -type f -print0)
        '';
  
        installPhase = ''
          mkdir $out
          perl ./install-linux.pl --prefix="$out"
  
          rm $out/tools/CUDA_Occupancy_Calculator.xls # FIXME: why?
  
          # let's remove the 32-bit libraries, they confuse the lib64->lib mover
          rm -rf $out/lib
  
          # Remove some cruft.
          rm $out/bin/uninstall*
  
          # Fixup path to samples (needed for cuda 6.5 or else nsight will not find them)
          if [ -d "$out"/cuda-samples ]; then
              mv "$out"/cuda-samples "$out"/samples
          fi
  
          # Change the #error on GCC > 4.9 to a #warning.
          sed -i $out/include/host_config.h -e 's/#error\(.*unsupported GNU version\)/#warning\1/'
  
          # Fix builds with newer glibc version
          sed -i "1 i#define _BITS_FLOATN_H" "$out/include/host_defines.h"
  
          # Ensure that cmake can find CUDA.
          mkdir -p $out/nix-support
          echo "cmakeFlags+=' -DCUDA_TOOLKIT_ROOT_DIR=$out'" >> $out/nix-support/setup-hook
  
          # Move some libraries to the lib output so that programs that
          # depend on them don't pull in this entire monstrosity.
          mkdir -p $lib/lib
          mv -v $out/lib64/libcudart* $lib/lib/
  
          # Remove OpenCL libraries as they are provided by ocl-icd and driver.
          rm -f $out/lib64/libOpenCL*
  
          # Set compiler for NVCC.
          wrapProgram $out/bin/nvcc \
            --prefix PATH : ${gcc}/bin
        '' + lib.optionalString (lib.versionOlder version "8.0") ''
          # Hack to fix building against recent Glibc/GCC.
          echo "NIX_CFLAGS_COMPILE+=' -D_FORCE_INLINES'" >> $out/nix-support/setup-hook
        '';
  
        passthru = {
  
negative.code:   };
  
    cudatoolkit8 = common {
      version = "8.0.61.2";
      url = "https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run";
      sha256 = "1i4xrsqbad283qffvysn88w2pmxzxbbby41lw0j1113z771akv4w";
      runPatches = [
        (fetchurl {
          url = "https://developer.nvidia.com/compute/cuda/8.0/Prod2/patches/2/cuda_8.0.61.2_linux-run";
          sha256 = "1iaz5rrsnsb1p99qiqvxn6j3ksc7ry8xlr397kqcjzxqbljbqn9d";
        })
      ];
      gcc = gcc5;
    };
  
  