nixpkgs/pkgs/tools/security/hashcat/default.nix
Andrew Marshall 54769c6fa1
hashcat: add CUDA support (#240735)
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.
2023-07-01 10:59:09 +02:00

70 lines
1.8 KiB
Nix

{ lib, stdenv
, addOpenGLRunpath
, config
, cudaPackages ? {}
, cudaSupport ? config.cudaSupport or false
, fetchurl
, makeWrapper
, opencl-headers
, ocl-icd
, xxHash
}:
stdenv.mkDerivation rec {
pname = "hashcat";
version = "6.2.6";
src = fetchurl {
url = "https://hashcat.net/files/hashcat-${version}.tar.gz";
sha256 = "sha256-sl4Qd7zzSQjMjxjBppouyYsEeyy88PURRNzzuh4Leyo=";
};
nativeBuildInputs = [
makeWrapper
] ++ lib.optionals cudaSupport [
addOpenGLRunpath
];
buildInputs = [ opencl-headers xxHash ];
makeFlags = [
"PREFIX=${placeholder "out"}"
"COMPTIME=1337"
"VERSION_TAG=${version}"
"USE_SYSTEM_OPENCL=1"
"USE_SYSTEM_XXHASH=1"
];
preFixup = ''
for f in $out/share/hashcat/OpenCL/*.cl; do
# Rewrite files to be included for compilation at runtime for opencl offload
sed "s|#include \"\(.*\)\"|#include \"$out/share/hashcat/OpenCL/\1\"|g" -i "$f"
sed "s|#define COMPARE_\([SM]\) \"\(.*\.cl\)\"|#define COMPARE_\1 \"$out/share/hashcat/OpenCL/\2\"|g" -i "$f"
done
'';
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; {
description = "Fast password cracker";
homepage = "https://hashcat.net/hashcat/";
license = licenses.mit;
platforms = platforms.linux;
maintainers = with maintainers; [ kierdavis zimbatm ];
};
}