nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 131 lines 2.9 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 cmake, 6 ninja, 7 pkg-config, 8 python3, 9 autoAddDriverRunpath, 10 11 config ? { }, 12 13 cudaSupport ? (config.cudaSupport or false), 14 cudaPackages ? { }, 15 16 rocmSupport ? (config.rocmSupport or false), 17 rocmPackages ? { }, 18 rocmGpuTargets ? (rocmPackages.clr.localGpuTargets or rocmPackages.clr.gpuTargets or [ ]), 19 20 openclSupport ? false, 21 clblast, 22 vulkanSupport ? false, 23 shaderc, 24 vulkan-headers, 25 vulkan-loader, 26 spirv-tools, 27 28 metalSupport ? (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64), 29 darwin, 30 apple-sdk, 31}: 32 33let 34 inherit (lib) 35 cmakeBool 36 cmakeFeature 37 optionals 38 optionalString 39 ; 40 41 effectiveStdenv = if cudaSupport then cudaPackages.backendStdenv else stdenv; 42in 43effectiveStdenv.mkDerivation (finalAttrs: { 44 pname = "stable-diffusion-cpp"; 45 version = "master-475-2efd199"; 46 47 outputs = [ 48 "out" 49 "dev" 50 ]; 51 52 src = fetchFromGitHub { 53 owner = "leejet"; 54 repo = "stable-diffusion.cpp"; 55 rev = "master-475-2efd199"; 56 hash = "sha256-ic0mnkKjgfL8k94ZCyqckjDR953NL7kBZ/tlIfLgZYo="; 57 fetchSubmodules = true; 58 }; 59 60 nativeBuildInputs = [ 61 cmake 62 ninja 63 pkg-config 64 ] 65 ++ optionals cudaSupport [ 66 (cudaPackages.cuda_nvcc) 67 autoAddDriverRunpath 68 ]; 69 70 buildInputs = 71 (optionals cudaSupport ( 72 with cudaPackages; 73 [ 74 cuda_cccl 75 cuda_cudart 76 libcublas 77 ] 78 )) 79 ++ (optionals rocmSupport ( 80 with rocmPackages; 81 [ 82 clr 83 hipblas 84 rocblas 85 ] 86 )) 87 ++ (optionals vulkanSupport [ 88 shaderc 89 vulkan-headers 90 vulkan-loader 91 spirv-tools 92 ]) 93 ++ (optionals openclSupport [ 94 clblast 95 ]) 96 ++ (optionals metalSupport [ 97 apple-sdk 98 ]); 99 100 cmakeFlags = [ 101 (cmakeBool "SD_BUILD_EXAMPLES" true) 102 (cmakeBool "SD_BUILD_SHARED_LIBS" true) 103 (cmakeBool "SD_USE_SYSTEM_GGML" false) 104 (cmakeBool "SD_CUDA" cudaSupport) 105 (cmakeBool "SD_HIPBLAS" rocmSupport) 106 (cmakeBool "SD_VULKAN" vulkanSupport) 107 (cmakeBool "SD_OPENCL" openclSupport) 108 (cmakeBool "SD_METAL" metalSupport) 109 (cmakeBool "SD_FAST_SOFTMAX" false) 110 ] 111 ++ optionals cudaSupport [ 112 (cmakeFeature "CMAKE_CUDA_ARCHITECTURES" cudaPackages.flags.cmakeCudaArchitecturesString) 113 ] 114 ++ optionals rocmSupport [ 115 (cmakeFeature "CMAKE_HIP_ARCHITECTURES" (builtins.concatStringsSep ";" rocmGpuTargets)) 116 ]; 117 118 meta = { 119 description = "Stable Diffusion inference in pure C/C++"; 120 homepage = "https://github.com/leejet/stable-diffusion.cpp"; 121 license = lib.licenses.mit; 122 mainProgram = "sd"; 123 maintainers = with lib.maintainers; [ 124 dit7ya 125 adriangl 126 ]; 127 platforms = lib.platforms.unix; 128 badPlatforms = lib.optionals (cudaSupport || openclSupport) lib.platforms.darwin; 129 broken = metalSupport && !stdenv.hostPlatform.isDarwin; 130 }; 131})