blender-mask-peoples/flake.nix

103 lines
3.6 KiB
Nix
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
description = "Blender VoiceVox Plugin Development Environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
in
{
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
# Python環境
python311
python311Packages.pip
python311Packages.virtualenv
git
# C/C++標準ライブラリPyTorchなどに必要
stdenv.cc.cc.lib
zlib
zstd
# ROCm関連AMD GPU推論に必要
rocmPackages.clr
rocmPackages.rocm-smi
rocmPackages.rocm-runtime
];
shellHook = ''
python --version
blender --version | head -n 1
# ROCm
export ROCM_PATH="${pkgs.rocmPackages.clr}"
export HSA_OVERRIDE_GFX_VERSION="11.0.0" # RX 7900 (RDNA 3 / gfx1100)
# LD_LIBRARY_PATH: ROCm libraries FIRST (critical for GPU inference)
export LD_LIBRARY_PATH="${pkgs.rocmPackages.clr}/lib:${pkgs.rocmPackages.rocm-runtime}/lib:${pkgs.stdenv.cc.cc.lib}/lib:${pkgs.zlib}/lib:${pkgs.zstd.out}/lib:$LD_LIBRARY_PATH"
# venv
VENV_DIR="$PWD/.venv"
if [ ! -d "$VENV_DIR" ]; then
echo "[Setup] Creating Python virtual environment..."
python -m venv "$VENV_DIR"
fi
# venv
source "$VENV_DIR/bin/activate"
# PyTorch ROCmGPU
if ! python -c "import torch; print(torch.cuda.is_available())" 2>/dev/null | grep -q "True"; then
echo "[Setup] Installing PyTorch ROCm dependencies..."
pip install --quiet --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm7.0
fi
# requirements.txt
if [ -f "$PWD/requirements.txt" ]; then
echo "[Setup] Syncing Python dependencies from requirements.txt..."
pip install --quiet -r "$PWD/requirements.txt"
fi
# OpenCVimportheadless
if ! python -c "import cv2" >/dev/null 2>&1; then
echo "[Setup] Repairing OpenCV (opencv-python-headless)..."
pip install --quiet --force-reinstall --no-cache-dir opencv-python-headless
fi
# Python
export PYTHONPATH="$PWD:$PYTHONPATH"
#
export BLENDER_USER_SCRIPTS="$HOME/.config/blender/5.0/scripts"
export BLENDER_USER_ADDONS="$BLENDER_USER_SCRIPTS/addons"
#
# CRITICAL: ROCm library paths MUST come first for GPU inference
cat > "$PWD/.env" << EOF
LD_LIBRARY_PATH=${pkgs.rocmPackages.clr}/lib:${pkgs.rocmPackages.rocm-runtime}/lib:${pkgs.stdenv.cc.cc.lib}/lib:${pkgs.zlib}/lib:${pkgs.zstd.out}/lib
ROCM_PATH=${pkgs.rocmPackages.clr}
HSA_OVERRIDE_GFX_VERSION=11.0.0
EOF
echo "[Setup] Environment ready with GPU support"
'';
};
}
);
}