Skip to content

Commit

Permalink
hashcat: add CUDA support (NixOS#240735)
Browse files Browse the repository at this point in the history
Previously, hashcat was unable to use CUDA at runtime, and would warn:

> Failed to initialize the NVIDIA main driver CUDA runtime library.
> Failed to initialize NVIDIA RTC library.
> * Device #1: CUDA SDK Toolkit not installed or incorrectly installed.
>              CUDA SDK Toolkit required for proper device support and utilization.
>              Falling back to OpenCL runtime.

This remedies that, at least on NixOS.
  • Loading branch information
amarshall authored Jul 1, 2023
1 parent e8f97f0 commit 54769c6
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions pkgs/tools/security/hashcat/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{ lib, stdenv
, addOpenGLRunpath
, config
, cudaPackages ? {}
, cudaSupport ? config.cudaSupport or false
, fetchurl
, makeWrapper
, opencl-headers
Expand All @@ -15,7 +19,12 @@ stdenv.mkDerivation rec {
sha256 = "sha256-sl4Qd7zzSQjMjxjBppouyYsEeyy88PURRNzzuh4Leyo=";
};

nativeBuildInputs = [ makeWrapper ];
nativeBuildInputs = [
makeWrapper
] ++ lib.optionals cudaSupport [
addOpenGLRunpath
];

buildInputs = [ opencl-headers xxHash ];

makeFlags = [
Expand All @@ -34,8 +43,20 @@ stdenv.mkDerivation rec {
done
'';

postFixup = ''
wrapProgram $out/bin/hashcat --prefix LD_LIBRARY_PATH : ${ocl-icd}/lib
postFixup = let
LD_LIBRARY_PATH = builtins.concatStringsSep ":" ([
"${ocl-icd}/lib"
] ++ lib.optionals cudaSupport [
"${cudaPackages.cudatoolkit}/lib"
]);
in ''
wrapProgram $out/bin/hashcat \
--prefix LD_LIBRARY_PATH : ${lib.escapeShellArg LD_LIBRARY_PATH}
'' + lib.optionalString cudaSupport ''
for program in $out/bin/hashcat $out/bin/.hashcat-wrapped; do
isELF "$program" || continue
addOpenGLRunpath "$program"
done
'';

meta = with lib; {
Expand Down

0 comments on commit 54769c6

Please sign in to comment.