diff --git a/flake.lock b/flake.lock index d2ba7f2..6effc13 100644 --- a/flake.lock +++ b/flake.lock @@ -16,6 +16,22 @@ "type": "github" } }, + "bark-gui-src": { + "flake": false, + "locked": { + "lastModified": 1690135468, + "narHash": "sha256-J/Mhv2lQ/IFKJ/MGm5p9HOoSJQ+fXXlUwLy5YRYi9tY=", + "owner": "C0untFloyd", + "repo": "bark-gui", + "rev": "7c85e68d230d282cf0a9ba4ac7f0ef611329f60d", + "type": "github" + }, + "original": { + "owner": "C0untFloyd", + "repo": "bark-gui", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": [ @@ -149,6 +165,22 @@ "type": "github" } }, + "kohya_ss-src": { + "flake": false, + "locked": { + "lastModified": 1699706768, + "narHash": "sha256-/9YWOUbqErxrG5igF7CgUTGzxjSkOPhMA79wekGPfaQ=", + "owner": "bmaltais", + "repo": "kohya_ss", + "rev": "9eb5da23002c6e00f084a19d62da6fc82074c773", + "type": "github" + }, + "original": { + "owner": "bmaltais", + "repo": "kohya_ss", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1686501370, @@ -202,9 +234,11 @@ "root": { "inputs": { "a1111-src": "a1111-src", + "bark-gui-src": "bark-gui-src", "flake-parts": "flake-parts", "hercules-ci-effects": "hercules-ci-effects", "invokeai-src": "invokeai-src", + "kohya_ss-src": "kohya_ss-src", "nixpkgs": "nixpkgs_2", "sd-src": "sd-src", "sgm-src": "sgm-src", diff --git a/flake.nix b/flake.nix index bc83149..13ca07b 100644 --- a/flake.nix +++ b/flake.nix @@ -7,6 +7,14 @@ description = "A Nix Flake that makes AI reproducible and easy to run"; inputs = { + bark-gui-src = { + url = "github:C0untFloyd/bark-gui"; + flake = false; + }; + kohya_ss-src = { + url = "github:bmaltais/kohya_ss"; + flake = false; + }; sgm-src = { url = "github:Stability-AI/generative-models"; flake = false; @@ -66,6 +74,8 @@ ./projects/automatic1111 ./projects/invokeai ./projects/textgen + ./projects/kohya_ss + ./projects/bark-gui ./website ]; }; diff --git a/overlays/default.nix b/overlays/default.nix index 01c9276..a87dc54 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,13 +1,13 @@ { lib, ... }: let - l = lib.extend (import ./lib.nix); +l = lib.extend (import ./lib.nix); - overlaySets = { - python = import ./python l; - }; +overlaySets = { + python = import ./python l; +}; - prefixAttrs = prefix: lib.mapAttrs' (name: value: lib.nameValuePair "${prefix}-${name}" value); +prefixAttrs = prefix: lib.mapAttrs' (name: value: lib.nameValuePair "${prefix}-${name}" value); in @@ -18,8 +18,8 @@ in }; overlays = lib.pipe overlaySets [ (lib.mapAttrs prefixAttrs) - (lib.attrValues) - (lib.foldl' (a: b: a // b) {}) + (lib.attrValues) + (lib.foldl' (a: b: a // b) {}) ]; }; } diff --git a/packages/audiolm-pytorch/default.nix b/packages/audiolm-pytorch/default.nix new file mode 100644 index 0000000..2aa3418 --- /dev/null +++ b/packages/audiolm-pytorch/default.nix @@ -0,0 +1,55 @@ +{ lib +, buildPythonPackage +, fetchPypi +, setuptools +, packaging +, torch +, einops +, beartype +, torchaudio +, fairseq +, transformers +, vector-quantize-pytorch +, local-attention +, encodec +, lion-pytorch +, ema-pytorch +, accelerate +}: + +buildPythonPackage rec { + pname = "audiolm-pytorch"; + version = "1.7.6"; + format = "pyproject"; + + src = fetchPypi { + inherit pname version; + hash = "sha256-Roo17hhrlNqnAt43kKQRnkHn6fvtW+vEVxLVHK0k884="; + }; + + buildInputs = [ + setuptools + ]; + propagatedBuildInputs = [ + packaging + torch + einops + beartype + torchaudio + fairseq + transformers + vector-quantize-pytorch + local-attention + encodec + lion-pytorch + ema-pytorch + accelerate + ]; + + pythonImportsCheck = [ "audiolm_pytorch" ]; + + meta = with lib; { + license = licenses.mit; + maintainers = with maintainers; [ ]; + }; +} diff --git a/packages/bark-gui.nix b/packages/bark-gui.nix new file mode 100644 index 0000000..198ed13 --- /dev/null +++ b/packages/bark-gui.nix @@ -0,0 +1,83 @@ +{ lib +, buildPythonPackage +, fetchFromGitHub +, writeShellScript +, setuptools + + # dependencies +, fairseq +, audiolm-pytorch +, gradio +, funcy +, linkify-it-py +, mutagen +, pytorch-seed +, pyyaml +, sentencepiece +, transformers + +, ffmpeg-full +}: + +buildPythonPackage rec { + pname = "bark-gui"; + format = "pyproject"; + version = "0.7.1"; + + src = fetchFromGitHub { + owner = "C0untFloyd"; + repo = "${pname}"; + rev = "v07.1"; + sha256 = "sha256-3UvX8c8SSzfeTleGU2FoAhmSj+EG0RPMtqozaopt9Fk="; + }; + + propagatedBuildInputs = [ + fairseq + audiolm-pytorch + gradio + funcy + linkify-it-py + mutagen + pytorch-seed + pyyaml + sentencepiece + transformers + ]; + buildInputs = [ + setuptools + ffmpeg-full + ]; + + dontWrapPythonPrograms = true; + postFixup = + let + setupScript = writeShellScript "bark-gui" '' + if [[ ! -d $HOME/.bark-gui ]]; then + mkdir -p $HOME + cp -r ${src} $HOME/.bark-gui + chmod 0755 $HOME/.bark-gui + chmod 0644 $HOME/.bark-gui/config.yaml + mkdir -p $HOME/.bark-gui/training/data/output + mkdir -p $HOME/.bark-gui/training/inputtext + chmod 755 $HOME/.bark-gui/training/data/output $HOME/.bark-gui/training/inputtext $HOME/.bark-gui/bark/assets/prompts/custom/ + fi + pushd "$PWD" + cd $HOME/.bark-gui/ + MYOLDPATH="$PATH" + export PATH="$PATH:${ffmpeg-full.bin}/bin/" + python webui.py "$@" + export PATH="$MYOLDPATH" + popd + ''; + in + '' + mkdir -p $out/bin + ln -s ${setupScript} $out/bin/bark-gui + ''; + + meta = with lib; { + maintainers = [ ]; + platforms = platforms.all; + }; +} + diff --git a/packages/deforum/default.nix b/packages/deforum/default.nix new file mode 100644 index 0000000..637b569 --- /dev/null +++ b/packages/deforum/default.nix @@ -0,0 +1,53 @@ +{ lib +, buildPythonPackage +, fetchPypi +, pydantic +, starlette +, pytestCheckHook +, pytest-asyncio +, aiosqlite +, flask +, httpx +, hatchling +, orjson +, passlib +, peewee +, python-jose +, sqlalchemy +, trio +, pythonOlder +, setuptools +}: + +buildPythonPackage rec { + pname = "deforum"; + version = "0.1.7"; + + disabled = pythonOlder "3.7"; + + src = fetchPypi { + inherit pname version; + sha256 = "sha256-vLwkSVj9gD6oDOeybQ4tTwcwey4mWuXYCjw9qFoaFsA="; + }; + + nativeBuildInputs = [ + hatchling + ]; + + propagatedBuildInputs = [ + starlette + pydantic + ]; + + doCheck = false; + + + meta = with lib; { + description = "Deforum is a Python package for diffusion animation toolkit."; + homepage = "https://github.com/deforum-art/deforum"; + license = licenses.mit; + maintainers = with maintainers; [ ]; + }; +} + + diff --git a/packages/discord-webhook/default.nix b/packages/discord-webhook/default.nix new file mode 100644 index 0000000..69613f7 --- /dev/null +++ b/packages/discord-webhook/default.nix @@ -0,0 +1,25 @@ +{ lib +, buildPythonPackage +, fetchPypi +}: + +buildPythonPackage rec { + pname = "discord-webhook"; + version = "1.3.0"; + format = "pyproject"; + + src = fetchPypi { + inherit pname version; + sha256 = ""; + }; + + propagatedBuildInputs = [ ]; + + doCheck = false; + + meta = with lib; { + description = ""; + homepage = "https://github.com/lovvskillz/python-discord-webhook"; + maintainers = with maintainers; [ ]; + }; +} \ No newline at end of file diff --git a/packages/ema-pytorch/default.nix b/packages/ema-pytorch/default.nix new file mode 100644 index 0000000..b5fe51f --- /dev/null +++ b/packages/ema-pytorch/default.nix @@ -0,0 +1,33 @@ +{ lib +, buildPythonPackage +, fetchPypi +, setuptools +, torch +, beartype +}: + +buildPythonPackage rec { + pname = "ema-pytorch"; + version = "0.3.0"; + format = "pyproject"; + + src = fetchPypi { + inherit pname version; + hash = "sha256-xZv/45dxN2aYUUAq9JRlCWcJnalAD1SuMbyU+//jBhw="; + }; + + buildInputs = [ + setuptools + ]; + propagatedBuildInputs = [ + torch + beartype + ]; + + pythonImportsCheck = [ "ema_pytorch" ]; + + meta = with lib; { + license = licenses.mit; + maintainers = with maintainers; [ ]; + }; +} \ No newline at end of file diff --git a/packages/local-attention/default.nix b/packages/local-attention/default.nix new file mode 100644 index 0000000..8bc861e --- /dev/null +++ b/packages/local-attention/default.nix @@ -0,0 +1,33 @@ +{ lib +, buildPythonPackage +, fetchPypi +, setuptools +, torch +, einops +}: + +buildPythonPackage rec { + pname = "local-attention"; + version = "1.9.0"; + format = "pyproject"; + + src = fetchPypi { + inherit pname version; + hash = "sha256-p7F53JIjWLS7SLMXLPs0nttFnRvc5YnYN4alel42kKY="; + }; + + buildInputs = [ + setuptools + ]; + propagatedBuildInputs = [ + torch + einops + ]; + + pythonImportsCheck = [ "local_attention" ]; + + meta = with lib; { + license = licenses.mit; + maintainers = with maintainers; [ ]; + }; +} \ No newline at end of file diff --git a/packages/pytorch-seed/default.nix b/packages/pytorch-seed/default.nix new file mode 100644 index 0000000..cb8d566 --- /dev/null +++ b/packages/pytorch-seed/default.nix @@ -0,0 +1,33 @@ +{ lib +, buildPythonPackage +, fetchPypi +, setuptools +, torch +, numpy +}: + +buildPythonPackage rec { + pname = "pytorch_seed"; + version = "0.2.0"; + format = "pyproject"; + + src = fetchPypi { + inherit pname version; + hash = "sha256-CW7dNAT4oA898rq0ECSUWAa68fZLBWeMgjc7eARY4aM="; + }; + + buildInputs = [ + setuptools + ]; + propagatedBuildInputs = [ + torch + numpy + ]; + + pythonImportsCheck = [ "pytorch_seed" ]; + + meta = with lib; { + license = licenses.mit; + maintainers = with maintainers; [ ]; + }; +} \ No newline at end of file diff --git a/packages/rich/default.nix b/packages/rich/default.nix new file mode 100644 index 0000000..369d880 --- /dev/null +++ b/packages/rich/default.nix @@ -0,0 +1,27 @@ + +{ lib +, buildPythonPackage +, fetchPypi +, poetry-core +}: + +buildPythonPackage rec { + pname = "rich"; + version = "13.7.0"; + format = "pyproject"; + + src = fetchPypi { + inherit pname version; + sha256 = "sha256-XLUSO1z57nBYQkQkaBbpEUIn4LmK2Rdu7eatVL9UA/o="; + }; + + propagatedBuildInputs = [ poetry-core ]; + + doCheck = false; + + meta = with lib; { + description = "Rich is a Python library for rich text and beautiful formatting in the terminal."; + homepage = "https://github.com/Textualize/rich"; + maintainers = with maintainers; [ ]; + }; +} diff --git a/packages/ultralytics/default.nix b/packages/ultralytics/default.nix new file mode 100644 index 0000000..13296b4 --- /dev/null +++ b/packages/ultralytics/default.nix @@ -0,0 +1,25 @@ +{ lib +, buildPythonPackage +, fetchPypi +, poetry-core +}: + +buildPythonPackage rec { + pname = "ultralytics"; + version = "8.0.211"; + + src = fetchPypi { + inherit pname version; + sha256 = "sha256-QZio7nuNFRYBwa+wUWM7uQ056M3GsRHGcqnrysfvN6E="; + }; + + propagatedBuildInputs = [ poetry-core ]; + + doCheck = false; + + meta = with lib; { + description = ""; + homepage = "https://github.com/ultralytics/ultralytics"; + maintainers = with maintainers; [ ]; + }; +} diff --git a/packages/vector-quantize-pytorch/default.nix b/packages/vector-quantize-pytorch/default.nix new file mode 100644 index 0000000..438668c --- /dev/null +++ b/packages/vector-quantize-pytorch/default.nix @@ -0,0 +1,33 @@ +{ lib +, buildPythonPackage +, fetchPypi +, setuptools +, torch +, einops +}: + +buildPythonPackage rec { + pname = "vector_quantize_pytorch"; + version = "1.11.7"; + format = "pyproject"; + + src = fetchPypi { + inherit pname version; + hash = "sha256-kMKeWhnTXbI+ROPJ0LHVh7TQjonhRzXUQm+U8TgghSM="; + }; + + buildInputs = [ + setuptools + ]; + propagatedBuildInputs = [ + torch + einops + ]; + + pythonImportsCheck = [ "vector_quantize_pytorch" ]; + + meta = with lib; { + license = licenses.mit; + maintainers = with maintainers; [ ]; + }; +} \ No newline at end of file diff --git a/projects/automatic1111/default.nix b/projects/automatic1111/default.nix index a4ab4f3..966589b 100644 --- a/projects/automatic1111/default.nix +++ b/projects/automatic1111/default.nix @@ -10,6 +10,11 @@ in commonOverlays = [ overlays.python-fixPackages (l.overlays.callManyPackages [ + + ../../packages/discord-webhook + ../../packages/deforum + ../../packages/ultralytics + ../../packages/rich ../../packages/k_diffusion ../../packages/openclip ../../packages/safetensors diff --git a/projects/automatic1111/package.nix b/projects/automatic1111/package.nix index f7d6130..cf50c6d 100644 --- a/projects/automatic1111/package.nix +++ b/projects/automatic1111/package.nix @@ -19,6 +19,10 @@ python3Packages.buildPythonPackage { version = "v1.6.0"; inherit src; propagatedBuildInputs = with python3Packages; [ + discord-webhook + numexpr + deforum + ultralytics k_diffusion inflection gdown @@ -27,6 +31,7 @@ python3Packages.buildPythonPackage { openclip semver numpy + rich torchsde uvicorn pyperclip @@ -78,7 +83,6 @@ python3Packages.buildPythonPackage { safetensors datasets accelerate - huggingface-hub easing-functions dynamicprompts torchvision @@ -94,63 +98,63 @@ python3Packages.buildPythonPackage { ]; nativeBuildInputs = with python3Packages; [ pythonRelaxDepsHook pip ]; pythonRemoveDeps = [ "clip" "pyreadline3" "flaskwebgui" "opencv-python" ]; - pythonRelaxDeps = [ "dnspython" "flask" "requests" "numpy" "pytorch-lightning" "torchsde" "uvicorn" "invisible-watermark" "accelerate" "scikit-image" "safetensors" "huggingface-hub" "torchvision" "test-tube" "fastapi" ]; + pythonRelaxDeps = [ "dnspython" "flask" "requests" "numpy" "pytorch-lightning" "torchsde" "uvicorn" "invisible-watermark" "accelerate" "scikit-image" "safetensors" "torchvision" "test-tube" "fastapi" ]; dontUsePytestCheck = true; doCheck = false; buildPhase = '' - runHook preBuild - mkdir -p dist - cp -r . $out - chmod -R +w $out - cd $out - - #replace dirs in paths_internal.py - #mkdir -p /var/lib/.webui - sed -i 's#os\.path\.join(script_path, "config_states")#os\.path\.join(data_path, "config_states")#' ./modules/paths_internal.py - #delete lines trying to pull git repos and setting up tests in launch.py - sed -i '28,43d' launch.py + runHook preBuild + mkdir -p dist + cp -r . $out + chmod -R +w $out + cd $out + + #replace dirs in paths_internal.py + #mkdir -p /var/lib/.webui + sed -i 's#os\.path\.join(script_path, "config_states")#os\.path\.join(data_path, "config_states")#' ./modules/paths_internal.py + #delete lines trying to pull git repos and setting up tests in launch.py + sed -i '28,43d' launch.py - #firstly, we need to make launch.py runnable by adding python shebang - cat <<-EOF > exec_launch.py.unwrapped - $(echo "#!/usr/bin/python") - $(cat launch.py) - EOF - chmod +x exec_launch.py.unwrapped + #firstly, we need to make launch.py runnable by adding python shebang + cat <<-EOF > exec_launch.py.unwrapped + $(echo "#!/usr/bin/python") + $(cat launch.py) + EOF + chmod +x exec_launch.py.unwrapped - #creating wrapper around launch.py with PYTHONPATH correctly set - makeWrapper "$(pwd)/exec_launch.py.unwrapped" exec_launch.py \ - --set-default PYTHONPATH $PYTHONPATH + #creating wrapper around launch.py with PYTHONPATH correctly set + makeWrapper "$(pwd)/exec_launch.py.unwrapped" exec_launch.py \ + --set-default PYTHONPATH $PYTHONPATH - mkdir $out/bin - pushd $out/bin - ln -s ../exec_launch.py launch.py - buck='$' #escaping $ inside shell inside shell is tricky - #next is an additional shell wrapper, which sets sensible default args for CLI - #additional arguments will be passed further - cat <<-EOF > flake-launch - #!/usr/bin/env bash - pushd $out #For some reason, fastapi only works when current workdir is set inside the repo - trap "popd" EXIT + mkdir $out/bin + pushd $out/bin + ln -s ../exec_launch.py launch.py + buck='$' #escaping $ inside shell inside shell is tricky + #next is an additional shell wrapper, which sets sensible default args for CLI + #additional arguments will be passed further + cat <<-EOF > flake-launch + #!/usr/bin/env bash + pushd $out #For some reason, fastapi only works when current workdir is set inside the repo + trap "popd" EXIT - "$out/bin/launch.py" --skip-install "$buck{@}" - EOF - # below lie remnants of my attempt to make webui use similar paths as InvokeAI for models download - # additions of such options in upstream is a welcome sign, however they're mostly ignored and therefore useless - # TODO: check in 6 months, maybe it'll work - # For now, your best bet is to use ZFS dataset with dedup enabled or make symlinks after the fact - - #--codeformer-models-path "\$mp/codeformer" \ - #--gfpgan-models-path "\$mp/gfpgan" --esrgan-models-path "\$mp/esrgan" \ - #--bsrgan-models-path "\$mp/bsrgan" --realesrgan-models-path "\$mp/realesrgan" \ - #--clip-models-path "\$mp/clip" - chmod +x flake-launch - popd + "$out/bin/launch.py" --skip-install "$buck{@}" + EOF + # below lie remnants of my attempt to make webui use similar paths as InvokeAI for models download + # additions of such options in upstream is a welcome sign, however they're mostly ignored and therefore useless + # TODO: check in 6 months, maybe it'll work + # For now, your best bet is to use ZFS dataset with dedup enabled or make symlinks after the fact + + #--codeformer-models-path "\$mp/codeformer" \ + #--gfpgan-models-path "\$mp/gfpgan" --esrgan-models-path "\$mp/esrgan" \ + #--bsrgan-models-path "\$mp/bsrgan" --realesrgan-models-path "\$mp/realesrgan" \ + #--clip-models-path "\$mp/clip" + chmod +x flake-launch + popd - runHook postBuild - ''; + runHook postBuild + ''; installPhase = '' runHook preInstall @@ -164,6 +168,7 @@ python3Packages.buildPythonPackage { ln -s ${codeformer}/ CodeFormer ln -s ${blip}/ BLIP popd + echo $PATH runHook postInstall ''; meta = { diff --git a/projects/bark-gui/default.nix b/projects/bark-gui/default.nix new file mode 100644 index 0000000..f4ac45e --- /dev/null +++ b/projects/bark-gui/default.nix @@ -0,0 +1,44 @@ +{ config, inputs, lib, withSystem, ... }: +{ + perSystem = { config, pkgs, ... }: + let + src = inputs.bark-gui-src; + overlays = [ + ( + final: prev: { + final.python310 = prev.python310.override { + enableOptimizations = true; + reproducibleBuild = false; + self = final.python310; + buildInputs = [ final.ffmpeg-full ]; + }; + pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ + ( + python-final: python-prev: { + pytorch-seed = python-final.callPackage ../../Packages/pytorch-seed { }; + audiolm-pytorch = python-final.callPackage ../../Packages/audiolm-pytorch { }; + vector-quantize-pytorch = python-final.callPackage ../../Packages/vector-quantize-pytorch { }; + local-attention = python-final.callPackage ../../Packages/local-attention { }; + ema-pytorch = python-final.callPackage ../../Packages/ema-pytorch { }; + + openai-triton = python-prev.openai-triton-bin; + torch = python-prev.torch-bin; + torchaudio = python-prev.torchaudio-bin; + + #bark-gui = python-final.callPackage ../../Packages/bark-gui.nix { }; + } + ) + ]; + } + ) + ]; + mkbark-guiVariant = args: pkgs.callPackage ./package.nix ({ inherit src; } // args); + in + { + packages = { + bark-gui = mkbark-guiVariant { + inherit overlays; + }; + }; + }; +} diff --git a/projects/bark-gui/package.nix b/projects/bark-gui/package.nix new file mode 100644 index 0000000..a344c0c --- /dev/null +++ b/projects/bark-gui/package.nix @@ -0,0 +1,79 @@ +{ lib +, buildPythonPackage +, fetchFromGitHub +, writeShellScript +, setuptools + + # dependencies +, fairseq +, audiolm-pytorch +, gradio +, funcy +, linkify-it-py +, mutagen +, pytorch-seed +, pyyaml +, sentencepiece +, transformers + +, ffmpeg-full + +, src +}: + +buildPythonPackage rec { + pname = "bark-gui"; + format = "pyproject"; + version = "0.7.1"; + + propagatedBuildInputs = [ + fairseq + audiolm-pytorch + gradio + funcy + linkify-it-py + mutagen + pytorch-seed + pyyaml + sentencepiece + transformers + ]; + buildInputs = [ + setuptools + ffmpeg-full + ]; + + dontWrapPythonPrograms = true; + postFixup = + let + setupScript = writeShellScript "bark-gui" '' + if [[ ! -d $HOME/.bark-gui ]]; then + mkdir -p $HOME + cp -r ${src} $HOME/.bark-gui + chmod 0755 $HOME/.bark-gui + chmod 0644 $HOME/.bark-gui/config.yaml + mkdir -p $HOME/.bark-gui/training/data/output + mkdir -p $HOME/.bark-gui/training/inputtext + chmod 755 $HOME/.bark-gui/training/data/output $HOME/.bark-gui/training/inputtext $HOME/.bark-gui/bark/assets/prompts/custom/ + fi + pushd "$PWD" + cd $HOME/.bark-gui/ + MYOLDPATH="$PATH" + export PATH="$PATH:${ffmpeg-full.bin}/bin/" + python webui.py "$@" + export PATH="$MYOLDPATH" + popd + ''; + in + '' + mkdir -p $out/bin + ln -s ${setupScript} $out/bin/bark-gui + ''; + + meta = { + description = "A Gradio Web UI for an extended - easy to use - Bark Version"; + homepage = "https://github.com/C0untFloyd/bark-gui"; + mainProgram = "bark-gui"; + }; +} + diff --git a/projects/kohya_ss/default.nix b/projects/kohya_ss/default.nix new file mode 100644 index 0000000..74b3711 --- /dev/null +++ b/projects/kohya_ss/default.nix @@ -0,0 +1,122 @@ +{ config, inputs, lib, withSystem, ... }: + +let + l = lib // config.flake.lib; + inherit (config.flake) overlays; +in + +{ + perSystem = { config, pkgs, ... }: let + commonOverlays = [ + overlays.python-fixPackages + (l.overlays.callManyPackages [ + ../../packages/deforum + ../../packages/k_diffusion + ../../packages/openclip + ../../packages/safetensors + ../../packages/easing-functions + ../../packages/dynamicprompts + ../../packages/controlnet-aux + ../../packages/fastapi + ../../packages/fastapi-events + ../../packages/fastapi-socketio + ../../packages/pytorch-lightning + ../../packages/starlette + ../../packages/compel + ../../packages/taming-transformers-rom1504 + ../../packages/albumentations + ../../packages/qudida + ../../packages/gfpgan + ../../packages/basicsr + ../../packages/facexlib + ../../packages/realesrgan + ../../packages/codeformer + ../../packages/clipseg + ../../packages/kornia + ../../packages/picklescan + ../../packages/diffusers + ../../packages/pypatchmatch + ../../packages/torch-fidelity + ../../packages/resize-right + ../../packages/torchdiffeq + ../../packages/accelerate + ../../packages/clip-anytorch + ../../packages/clean-fid + ../../packages/getpass-asterisk + ../../packages/mediapipe + ../../packages/python-engineio + ../../packages/lpips + ../../packages/blip + ../../packages/gradio + ../../packages/gradio-client + ../../packages/analytics-python + ../../packages/tomesd + ../../packages/blendmodes + ../../packages/xformers + ]) + (final: prev: lib.mapAttrs + (_: pkg: pkg.overrideAttrs (old: { + nativeBuildInputs = old.nativeBuildInputs ++ [ final.pythonRelaxDepsHook ]; + pythonRemoveDeps = [ "opencv-python-headless" "opencv-python" "tb-nightly" "clip" ]; + })) + { + inherit (prev) + albumentations + qudida + gfpgan + basicsr + facexlib + realesrgan + clipseg + ; + } + ) + ]; + + python3Variants = { + amd = l.overlays.applyOverlays pkgs.python3Packages (commonOverlays ++ [ + overlays.python-torchRocm + ]); + nvidia = l.overlays.applyOverlays pkgs.python3Packages (commonOverlays ++ [ + overlays.python-torchCuda + ]); + }; + + src = inputs.kohya_ss-src; + + mkkohya_ssVariant = args: pkgs.callPackage ./package.nix ({ inherit src; } // args); + in { + packages = { + kohya_ss-nvidia = mkkohya_ssVariant { + python3Packages = python3Variants.nvidia; + }; + }; + legacyPackages = { + kohya_ss-amd = throw '' + AMD not done yet. + ''; + }; + }; + + flake.nixosModules = let + packageModule = pkgAttrName: { pkgs, ... }: { + services.kohya_ss.package = withSystem pkgs.system ( + { config, ... }: lib.mkOptionDefault config.packages.${pkgAttrName} + ); + }; + in { + kohya_ss = ./nixos; + kohya_ss-amd = { + imports = [ + config.flake.nixosModules.invokeai + (packageModule "kohya_ss-amd") + ]; + }; + kohya_ss-nvidia = { + imports = [ + config.flake.nixosModules.invokeai + (packageModule "kohya_ss-nvidia") + ]; + }; + }; +} diff --git a/projects/kohya_ss/package.nix b/projects/kohya_ss/package.nix new file mode 100644 index 0000000..92ba976 --- /dev/null +++ b/projects/kohya_ss/package.nix @@ -0,0 +1,114 @@ +{ python3Packages + , lib + , src +}: +python3Packages.buildPythonPackage { + pname = "kohya_ss"; + format = "other"; + version = "v22.1.1"; + inherit src; + propagatedBuildInputs = with python3Packages; [ + deforum + inflection + gdown + altair + aiofiles + openclip + semver + numpy + torchsde + uvicorn + pyperclip + invisible-watermark + fastapi + fastapi-events + fastapi-socketio + timm + scikit-image + controlnet-aux + compel + python-dotenv + uvloop + watchfiles + httptools + websockets + dnspython + albumentations + opencv4 + pudb + imageio + imageio-ffmpeg + compel + npyscreen + pytorch-lightning + protobuf + omegaconf + test-tube + einops + taming-transformers-rom1504 + torch-fidelity + torchmetrics + transformers + kornia + k-diffusion + picklescan + diffusers + pypatchmatch + realesrgan + pillow + send2trash + flask + flask-cors + dependency-injector + gfpgan + eventlet + clipseg + getpass-asterisk + safetensors + datasets + accelerate + easing-functions + dynamicprompts + torchvision + test-tube + lark + gradio + gradio-client + tomesd + piexif + blendmodes + xformers + python-multipart + ]; + nativeBuildInputs = with python3Packages; [ pythonRelaxDepsHook pip ]; + pythonRemoveDeps = [ "clip" "pyreadline3" "flaskwebgui" "opencv-python" ]; + pythonRelaxDeps = [ "dnspython" "flask" "requests" "numpy" "pytorch-lightning" "torchsde" "uvicorn" "invisible-watermark" "accelerate" "scikit-image" "safetensors" "torchvision" "test-tube" "fastapi" ]; + + dontUsePytestCheck = true; + + doCheck = false; + + buildPhase = '' + runHook preBuild + mkdir -p dist + cp -r . $out + chmod -R +w $out + cd $out + + --run setup.sh + mkdir -p $out/bin + mv gui.sh $out/bin/gui.sh + + runHook postBuild + ''; + installPhase = '' + runHook preInstall + + runHook postInstall + ''; + meta = { + description = "GUI for Kohya's Stable Diffusion trainers"; + homepage = "https://github.com/bmaltais/kohya_ss.git"; + mainProgram = "gui.sh"; + }; +} diff --git a/starta1111.sh b/starta1111.sh index a5fdb4d..e738d27 100755 --- a/starta1111.sh +++ b/starta1111.sh @@ -1 +1 @@ -nix run .#a1111-nvidia -- --data-dir /home/denis/.webui --ckpt-dir /home/denis/.invokeai/autoimport/main --theme dark --medvram --no-half-vae --opt-sdp-attention --opt-split-attention --no-gradio-queue +nix run .#a1111-nvidia -- --data-dir /home/denis/webui --ckpt-dir /home/denis/.invokeai/autoimport/main --theme dark --medvram --no-half-vae