Add the following to your inputs:
stable-diffusion-webui-nix = {
url = "github:Janrupf/stable-diffusion-webui-nix/main";
inputs.nixpkgs.follows = "nixpkgs";
};
Then add the overlay to your system configuration:
{
nixpkgs.overlays = [ stable-diffusion-webui-nix.overlays.default ];
}
Finally add the package you want to your system packages:
environment.systemPackages = [
pkgs.stable-diffusion-webui.forge.cuda # For lllyasviel's fork of AUTOMATIC1111 WebUI
pkgs.stable-diffusion-webui.comfy.cuda # For ComfyUI
];
Afterwards you should have the command stable-diffusion-webui
or comfy-ui
available which launches the server.
Data is by default stored in $HOME/.local/share/stable-diffusion-webui
, this can be
overwritten by using the --data-dir /another/path
argument when starting the Web UI.
Data is by default stored in $HOME/.local/share/comfy-ui
, this can be ovewritten
by using --base-directory /another/path
argument.
Running Stable Diffusion models requires CUDA and thus depends on packages which are by default not available in the NixOS cache. Add the cuda-maintainers Cachix as a substituter to your Nix configuration. See the NixOS Wiki for more information.
Due to the nature of python package management, this flake is quite complex.
- update the commit hashes in
source/package
(file depends on which package you want to change). - run
nix run .#package.update-helper source/package/install-instructions.json
(for example.#comfy.cuda.update-helper source/comfy/install-instructions-cuda.json
) to update the requirements metadata - try running the package using
nix run .#package
(for examplenix run .#comfy.cuda
) and test everything
NOTE: If you get an error that you have run out of disk space during step 2, your
/tmp
is too small. Either increase the tmpfs size or run the command with TMPDIR
set to a different directory. Generally, if step 2 fails the temporary directory
may not be deleted, you are free to rm -rf
it, but it can be useful for inspecting
why it failed.
This flake provides a FHS (nix run .#fhs.cuda
) and pkgs.stable-diffusion-webui.fhs.cuda
(as command stable-diffusion-fhs-cuda
) which can be used to provide an FHS which (hopefully...) has the
packages installed required to run with upstream python environments.
NOTE: The FHS is unmanaged - you don't get ComfyUI/StableDiffusionWebUI/Something pre-installed! It only provides you a standard Linux environment, in which you can follow the upstream instructions to install your UI of choice.
Due to being unmanaged, you should be able to install custom python packages just fine (provided you have set up your python venv!).