Skip to content

Instantly share code, notes, and snippets.

@jammus
Created September 14, 2022 15:58
Show Gist options
  • Save jammus/02f118f4edef9ab3435edf4fd5515651 to your computer and use it in GitHub Desktop.
Save jammus/02f118f4edef9ab3435edf4fd5515651 to your computer and use it in GitHub Desktop.
{ pkgs ? import <nixpkgs> {}}:
with pkgs;
let
pythonPackages = python310Packages;
nixGLSrc = builtins.fetchGit {
url = "https://github.com/guibou/nixGL";
rev = "7165ffbccbd2cf4379b6cd6d2edd1620a427e5ae";
};
nixGLDefault = (pkgs.callPackage nixGLSrc {}).auto.nixGLDefault;
nvidiaPackages = pkgs:
with pkgs; [
cudaPackages_10_2.cudatoolkit
cudaPackages.cudnn
nixGLDefault
];
requiredPackags = [
python310
git
stdenv
glib
pythonPackages.venvShellHook
];
in pkgs.mkShell rec {
name = "Imagine.nvim-StableDiffusion";
venvDir = ".venv";
#nrizq2w7q86fgpbmcx178vv5s4hxdlfa-hello.dr Required for building C extensions
CUDA_PATH = "${cudaPackages_10_2.cudatoolkit}";
LD_LIBRARY_PATH =
"${cudaPackages_10_2.cudatoolkit}/lib:${cudaPackages.cudnn}/lib:${cudaPackages_10_2.cudatoolkit.lib}/lib:${zlib}/lib:${stdenv.cc.cc.lib}/lib:/run/opengl-driver/lib:/run/opengl-driver-32/lib:/usr/lib:/usr/lib32:/run/opengl-driver/lib:/run/opengl-driver-32/lib:/usr/lib:/usr/lib32:${pkgs.glib.out}/lib:$LD_LIBRARY_PATH";
buildInputs = requiredPackags ++ (nvidiaPackages pkgs);
# Run this command, only after creating the virtual environment
postVenvCreation = ''
export LD_LIBRARY_PATH=$(nixGL printenv LD_LIBRARY_PATH):$LD_LIBRARY_PATH
unset SOURCE_DATE_EPOCH
pip install -r requirements.txt --no-cache-dir --prefer-binary
pip install -e .
pip install -r repositories/CodeFormer/requirements.txt --prefer-binary
pip install -r repositories/CodeFormer/requirements.txt --prefer-binary
'';
# Now we can execute any commands within the virtual environment.
# This is optional and can be left out to run pip manually.
postShellHook = ''
# allow pip to install wheels
unset SOURCE_DATE_EPOCH
'';
}
@hacker1024
Copy link

Thanks! Pasting the instructions in your comment here for convenience and archival purposes:

This was really helpful, thanks. I made some edits to get it working for the AUTOMATIC1111 version of webui.

Steps I followed were:

Download this gist and save as default.nix alongside a clone of the repo. Then

# Copy models as described in README
cp ~/Downloads/model.ckpt .
cp ~/Downloads/GFPGANv1.3.pth .

# Clone other repos as mentioned in README
mkdir repositories
git clone https://github.com/CompVis/stable-diffusion.git repositories/stable-diffusion
git clone https://github.com/CompVis/taming-transformers.git repositories/taming-transformers git clone > https://github.com/sczhou/CodeFormer.git repositories/CodeFormer
git clone https://github.com/salesforce/BLIP.git repositories/BLIP

export NIXPKGS_ALLOW_UNFREE=1
nix-shell default.nix

pip install torch --extra-index-url https://download.pytorch.org/whl/cu113 # Also from linux > instructions. Can probably be added to default.nix

python webui.py

gfpgan/CodeFormer errors. Not sure how serious they yet, but a basic txt2img worked fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment