-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
comfyui: init at unstable-2024-04-15
- Loading branch information
1 parent
96f0aa9
commit 82d76ad
Showing
3 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
fetchFromGitHub | ||
, stdenv | ||
, lib | ||
}: | ||
|
||
let | ||
mkComfyUICustomNodes = args: stdenv.mkDerivation ({ | ||
installPhase = '' | ||
runHook preInstall | ||
mkdir -p $out/ | ||
cp -r $src/* $out/ | ||
runHook postInstall | ||
''; | ||
|
||
passthru.dependencies = []; | ||
} // args); | ||
in | ||
{ | ||
ultimate-sd-upscale = mkComfyUICustomNodes { | ||
pname = "ultimate-sd-upscale"; | ||
version = "unstable-2023-08-16"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "ssitu"; | ||
repo = "ComfyUI_UltimateSDUpscale"; | ||
rev = "6ea48202a76ccf5904ddfa85f826efa80dd50520"; | ||
hash = "sha256-fUZ0AO+LARa+x30Iu+8jvEDun4T3f9G0DOlB2XNxY9Q="; | ||
fetchSubmodules = true; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
{ lib | ||
, python311 | ||
, linkFarm | ||
, writers | ||
, writeTextFile | ||
, fetchFromGitHub | ||
, stdenv | ||
, symlinkJoin | ||
, config | ||
, gpuBackend ? ( | ||
if config.cudaSupport | ||
then "cuda" | ||
else if config.rocmSupport | ||
then "rocm" | ||
else "none" | ||
) | ||
, modelsPath ? "/var/lib/comfyui/models" | ||
, inputPath ? "/var/lib/comfyui/input" | ||
, outputPath ? "/var/lib/comfyui/output" | ||
, tempPath ? "/var/lib/comfyui/temp" | ||
, userPath ? "/var/lib/comfyui/user" | ||
, customNodes ? [] | ||
, models ? { | ||
checkpoints = {}; | ||
clip = {}; | ||
clip_vision = {}; | ||
configs = {}; | ||
controlnet = {}; | ||
embeddings = {}; | ||
upscale_modules = {}; | ||
vae = {}; | ||
vae_approx = {}; | ||
} | ||
}: | ||
|
||
let | ||
|
||
config-data = { | ||
comfyui = { | ||
base_path = modelsPath; | ||
checkpoints = "${modelsPath}/checkpoints"; | ||
clip = "${modelsPath}/clip"; | ||
clip_vision = "${modelsPath}/clip_vision"; | ||
configs = "${modelsPath}/configs"; | ||
controlnet = "${modelsPath}/controlnet"; | ||
embeddings = "${modelsPath}/embeddings"; | ||
loras = "${modelsPath}/loras"; | ||
upscale_models= "${modelsPath}/upscale_models"; | ||
vae = "${modelsPath}/vae"; | ||
vae_approx = "${modelsPath}/vae_approx"; | ||
}; | ||
}; | ||
|
||
modelPathsFile = writeTextFile { | ||
name = "extra_model_paths.yaml"; | ||
text = (lib.generators.toYAML {} config-data); | ||
}; | ||
|
||
pythonEnv = (python311.withPackages (ps: with ps; [ | ||
( | ||
if gpuBackend == "cuda" | ||
then torchWithCuda | ||
else if gpuBackend == "rocm" | ||
then torchWithRocm | ||
else torch | ||
) | ||
torchsde | ||
torchvision | ||
torchaudio | ||
transformers | ||
safetensors | ||
accelerate | ||
aiohttp | ||
einops | ||
kornia | ||
pyyaml | ||
pillow | ||
scipy | ||
psutil | ||
tqdm | ||
] ++ (builtins.concatMap (node: node.dependencies) customNodes))); | ||
|
||
executable = writers.writeDashBin "comfyui" '' | ||
cd $out && \ | ||
${pythonEnv}/bin/python comfyui \ | ||
--input-directory ${inputPath} \ | ||
--output-directory ${outputPath} \ | ||
--extra-model-paths-config ${modelPathsFile} \ | ||
--temp-directory ${tempPath} \ | ||
"$@" | ||
''; | ||
|
||
customNodesCollection = ( | ||
linkFarm "comfyui-custom-nodes" (builtins.map (pkg: { name = pkg.pname; path = pkg; }) customNodes) | ||
); | ||
in stdenv.mkDerivation rec { | ||
pname = "comfyui"; | ||
version = "unstable-2024-04-15"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "comfyanonymous"; | ||
repo = "ComfyUI"; | ||
rev = "45ec1cbe963055798765645c4f727122a7d3e35e"; | ||
hash = "sha256-oK+PwAJdvItK1NaRRJMNI4Oh/g4jNt1M5gWfXEy3C9g="; | ||
}; | ||
|
||
installPhase = '' | ||
runHook preInstall | ||
echo "Preparing bin folder" | ||
mkdir -p $out/bin/ | ||
echo "Copying comfyui files" | ||
# These copies everything over but test/ci/github directories. But it's not | ||
# very future-proof. This can lead to errors such as "ModuleNotFoundError: | ||
# No module named 'app'" when new directories get added (which has happened | ||
# at least once). Investigate if we can just copy everything. | ||
cp -r $src/comfy $out/ | ||
cp -r $src/comfy_extras $out/ | ||
cp -r $src/app $out/ | ||
cp -r $src/web $out/ | ||
cp -r $src/*.py $out/ | ||
mv $out/main.py $out/comfyui | ||
echo "Copying ${modelPathsFile} to $out" | ||
cp ${modelPathsFile} $out/extra_model_paths.yaml | ||
echo "Setting up input and output folders" | ||
ln -s ${inputPath} $out/input | ||
ln -s ${outputPath} $out/output | ||
mkdir -p $out/${tempPath} | ||
echo "Setting up custom nodes" | ||
ln -snf ${customNodesCollection} $out/custom_nodes | ||
echo "Copying executable script" | ||
cp ${executable}/bin/comfyui $out/bin/comfyui | ||
substituteInPlace $out/bin/comfyui --replace "\$out" "$out" | ||
echo "Patching python code..." | ||
substituteInPlace $out/folder_paths.py --replace 'os.path.join(os.path.dirname(os.path.realpath(__file__)), "temp")' '"${tempPath}"' | ||
substituteInPlace $out/folder_paths.py --replace 'os.path.join(os.path.dirname(os.path.realpath(__file__)), "user")' '"${userPath}"' | ||
runHook postInstall | ||
''; | ||
|
||
# outputs = ["" "extra_model_paths.yaml" "inputs" "outputs"]; | ||
|
||
meta = with lib; { | ||
homepage = "https://github.com/comfyanonymous/ComfyUI"; | ||
description = "The most powerful and modular stable diffusion GUI with a graph/nodes interface."; | ||
license = licenses.gpl3; | ||
platforms = platforms.all; | ||
maintainers = with maintainers; [ fazo96 ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters