nixpkgs/pkgs/games/katago/default.nix

115 lines
2.5 KiB
Nix
Raw Normal View History

2020-03-08 23:36:58 +00:00
{ stdenv
, gcc8Stdenv
, boost
, cmake
2021-01-14 15:41:01 +00:00
, cudatoolkit
, cudnn
, eigen
2020-03-08 23:36:58 +00:00
, fetchFromGitHub
2021-01-14 15:41:01 +00:00
, gperftools
, lib
, libzip
, makeWrapper
, mesa
, ocl-icd
, opencl-headers
, openssl
, writeShellScriptBin
, enableAVX2 ? stdenv.hostPlatform.avx2Support
2020-08-26 15:34:30 +00:00
, enableBigBoards ? false
, enableCuda ? false
2021-01-14 15:41:01 +00:00
, enableContrib ? false
2020-08-26 15:34:30 +00:00
, enableGPU ? true
, enableTcmalloc ? true
}:
2020-03-08 23:36:58 +00:00
2020-08-26 15:34:30 +00:00
assert !enableGPU -> (
!enableCuda);
2020-08-23 21:00:52 +00:00
2020-03-08 23:36:58 +00:00
let
2020-08-26 15:34:30 +00:00
env = if enableCuda
2020-03-08 23:36:58 +00:00
then gcc8Stdenv
else stdenv;
in env.mkDerivation rec {
pname = "katago";
2021-07-03 18:05:39 +00:00
version = "1.9.1";
githash = "c3220a5a404af835792c476f3f24904e4b799444";
2020-03-08 23:36:58 +00:00
src = fetchFromGitHub {
owner = "lightvector";
repo = "katago";
2020-08-23 21:00:52 +00:00
rev = "v${version}";
2021-07-03 18:05:39 +00:00
sha256 = "sha256-sAtPOqGe6fZ9mAtLdp80fTALXVkP9WdWQU2iTFGXe24=";
2020-03-08 23:36:58 +00:00
};
2021-01-14 15:41:01 +00:00
fakegit = writeShellScriptBin "git" "echo ${githash}";
2020-03-08 23:36:58 +00:00
nativeBuildInputs = [
cmake
makeWrapper
];
buildInputs = [
libzip
boost
2020-08-26 15:34:30 +00:00
] ++ lib.optionals (!enableGPU) [
2020-08-23 21:00:52 +00:00
eigen
2020-08-26 15:34:30 +00:00
] ++ lib.optionals (enableGPU && enableCuda) [
2020-03-08 23:36:58 +00:00
cudnn
mesa.drivers
2020-08-26 15:34:30 +00:00
] ++ lib.optionals (enableGPU && !enableCuda) [
2020-03-08 23:36:58 +00:00
opencl-headers
ocl-icd
2021-01-14 15:41:01 +00:00
] ++ lib.optionals enableContrib [
openssl
2020-08-26 15:34:30 +00:00
] ++ lib.optionals enableTcmalloc [
2020-03-08 23:36:58 +00:00
gperftools
];
cmakeFlags = [
"-DNO_GIT_REVISION=ON"
2020-08-26 15:34:30 +00:00
] ++ lib.optionals (!enableGPU) [
2020-08-23 21:00:52 +00:00
"-DUSE_BACKEND=EIGEN"
2020-08-26 15:34:30 +00:00
] ++ lib.optionals enableAVX2 [
2020-08-23 21:00:52 +00:00
"-DUSE_AVX2=ON"
2020-08-26 15:34:30 +00:00
] ++ lib.optionals (enableGPU && enableCuda) [
2020-03-08 23:36:58 +00:00
"-DUSE_BACKEND=CUDA"
2020-08-26 15:34:30 +00:00
] ++ lib.optionals (enableGPU && !enableCuda) [
2020-03-08 23:36:58 +00:00
"-DUSE_BACKEND=OPENCL"
2021-01-14 15:41:01 +00:00
] ++ lib.optionals enableContrib [
"-DBUILD_DISTRIBUTED=1"
"-DNO_GIT_REVISION=OFF"
"-DGIT_EXECUTABLE=${fakegit}/bin/git"
2020-08-26 15:34:30 +00:00
] ++ lib.optionals enableTcmalloc [
2020-03-08 23:36:58 +00:00
"-DUSE_TCMALLOC=ON"
2020-08-26 15:34:30 +00:00
] ++ lib.optionals enableBigBoards [
"-DUSE_BIGGER_BOARDS_EXPENSIVE=ON"
2020-03-08 23:36:58 +00:00
];
preConfigure = ''
cd cpp/
2020-08-26 15:34:30 +00:00
'' + lib.optionalString enableCuda ''
2020-03-08 23:36:58 +00:00
export CUDA_PATH="${cudatoolkit}"
export EXTRA_LDFLAGS="-L/run/opengl-driver/lib"
'';
installPhase = ''
2021-03-15 14:36:53 +00:00
runHook preInstall
2020-03-08 23:36:58 +00:00
mkdir -p $out/bin; cp katago $out/bin;
2020-08-26 15:34:30 +00:00
'' + lib.optionalString enableCuda ''
2020-03-08 23:36:58 +00:00
wrapProgram $out/bin/katago \
--prefix LD_LIBRARY_PATH : "/run/opengl-driver/lib"
2021-03-15 14:36:53 +00:00
'' + ''
runHook postInstall
2020-03-08 23:36:58 +00:00
'';
meta = with lib; {
2020-03-08 23:36:58 +00:00
description = "Go engine modeled after AlphaGo Zero";
homepage = "https://github.com/lightvector/katago";
license = licenses.mit;
maintainers = [ maintainers.omnipotententity ];
platforms = [ "x86_64-linux" ];
};
}