mirror of
https://github.com/gbtb/nix-stable-diffusion.git
synced 2024-09-17 14:07:29 +03:00
Flake for running SD on NixOS
packages | ||
.gitmodules | ||
flake.lock | ||
flake.nix | ||
python-relax-deps-hook.sh | ||
README.md |
Table of contents
- nix-stable-diffusion
- How to use it?
- What's needed to be done
- Updates and versioning
- Acknowledgements
nix-stable-diffusion
Flake for running SD on NixOS
What's done
- Nix devShell capable of running InvokeAI's and stable-diffusion-webui flavors of SD without need to reach for pip or conda (including AMD ROCM support)
- ...???
- PROFIT
How to use it?
InvokeAI
- Clone repo
- Run
nix run -L .#invokeai.{default,amd,nvidia} -- --web
, wait for package to build.#invokeai.default
builds package which overrides bare minimum required for SD to run.#invokeai.amd
builds package which overrides torch packages with ROCM-enabled bin versions.#invokeai.nvidia
builds package with overlay explicitly settingcudaSupport = true
for torch
- Weights download
- Built-in CLI way. Upon first launch InvokeAI will check its default config dir (~/invokeai) and suggest you to run build-in TUI startup configuration script that help you to download default models or supply existing ones to InvokeAI. Follow the instructions and finish configuration. Note: you can also pass option
--root_dir
to pick another location for configs/models installation. More fine-grained directory setup options also available - runnix run .#invokeai -- --help
for more info. - Build-in GUI way. Recent version of InvokeAI added GUI for model managing. See upstream docs on that matter.
- Built-in CLI way. Upon first launch InvokeAI will check its default config dir (~/invokeai) and suggest you to run build-in TUI startup configuration script that help you to download default models or supply existing ones to InvokeAI. Follow the instructions and finish configuration. Note: you can also pass option
- CLI arguments for invokeai itself can be supplied after
--
part of the nix run command - If you need to run additional scripts (like invokeai-merge, invokeai-ti), then you can run
nix build .#invokeai
and call those scripts manually like that:./result/bin/invokeai-ti
.
stable-diffusion-webui aka 111AUTOMATIC111 fork
- Clone repo
- Clone submodule with stable-diffusion-webui
- Run
nix develop .#webui.{default,nvidia,amd}
, wait for shell to build.#webui.default
builds shell which overrides bare minimum required for SD to run.#webui.amd
builds shell which overrides torch packages with ROCM-enabled bin versions.#webui.nvidia
builds shell with overlay explicitly settingcudaSupport = true
for torch
- Obtain and place SD weights into
stable-diffusion-webui/models/Stable-diffusion/model.ckpt
- Inside
stable-diffusion-webui/
directory, runpython launch.py
to start web server. It should preload required models from the start. Additional models, such as CLIP, will be loaded before the first actual usage of them.
ROCM shenanigans
todo
What's needed to be done
- devShell with CUDA support (should be trivial, but requires volunteer with NVidia GPU)
- Missing packages definitions should be submitted to Nixpkgs
- Investigate ROCM device warning on startup
- Apply patches so that all downloaded models would go into one specific folder
- Should create a PR to pynixify with "skip-errors mode" so that no ugly patches would be necessary
- Shell hooks for initial setup?
- May be this devShell should be itself turned into a package?
- Add additional flavors of SD ?
Updates and versioning
Current versions:
- InvokeAI 2.3.1.post2
- stable-diffusion-webui 27.10.2022
I have no intention to keep up with development pace of these apps, especially the Automatic's fork :) . However, I will ocasionally update at least InvokeAI's flake. Considering versioning, I will try to follow semver with respect to submodules as well, which means major version bump for submodule = major version bump for this flake.
Acknowledgements
Many many thanks to https://github.com/cript0nauta/pynixify which generated all the boilerplate for missing python packages.
Also thanks to https://github.com/colemickens/stable-diffusion-flake and https://github.com/skogsbrus/stable-diffusion-nix-flake for inspiration and some useful code snippets.
Similar projects
todo