Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions pkgs/by-name/co/comfyui/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
lib,
callPackage,
fetchFromGitHub,
makeBinaryWrapper,
nix-update-script,
python3Packages,
withManager ? false,
}:

let
appDependencies =
ps:
with ps;
[
aiohttp
alembic
av
blake3
comfy-aimdo
comfy-kitchen
comfyui-embedded-docs
comfyui-frontend-package
comfyui-workflow-templates
einops
filelock
glfw
kornia
numpy
pillow
psutil
pydantic
pydantic-settings
pyopengl
pyyaml
requests
safetensors
scipy
sentencepiece
simpleeval
spandrel
sqlalchemy
tokenizers
torch
torchaudio
torchsde
torchvision
tqdm
transformers
yarl
]
++ lib.optionals withManager [
ps.comfyui-manager
];
pythonEnv = python3Packages.python.withPackages appDependencies;
in
python3Packages.buildPythonApplication (finalAttrs: {
pname = "comfyui";
version = "0.20.1";

pyproject = false;

strictDeps = true;
__structuredAttrs = true;

src = fetchFromGitHub {
owner = "Comfy-Org";
repo = "ComfyUI";
tag = "v${finalAttrs.version}";
hash = "sha256-CYrOLwfQvj4024WZ7OlGbJOxyj8qKHuwIfVluNVHIk4=";
};

nativeBuildInputs = [ makeBinaryWrapper ];

patches = [ ./use-writable-runtime-paths.patch ];

dependencies = appDependencies python3Packages;

dontBuild = true;
dontWrapPythonPrograms = true;

installPhase = ''
runHook preInstall

mkdir -p $out/share/comfyui $out/bin
cp -r . $out/share/comfyui

makeBinaryWrapper ${lib.getExe pythonEnv} $out/bin/comfyui \
--add-flag "$out/share/comfyui/main.py"

runHook postInstall
'';

doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck

"$out"/bin/comfyui --help
export XDG_DATA_HOME="$(mktemp -d)"
"$out"/bin/comfyui --cpu --quick-test-for-ci

runHook postInstallCheck
'';

passthru = {
inherit pythonEnv;
updateScript = nix-update-script { };
}
// lib.optionalAttrs (!withManager) {
tests.withManager = callPackage ./package.nix {
withManager = true;
};
};

meta = {
description = "Modular diffusion model GUI, API, and backend with graph and nodes interface";
homepage = "https://github.com/Comfy-Org/ComfyUI";
changelog = "https://github.com/Comfy-Org/ComfyUI/releases/tag/v${finalAttrs.version}";
license = lib.licenses.gpl3Only;
mainProgram = "comfyui";
maintainers = with lib.maintainers; [
caniko
jk
];
platforms = lib.platforms.linux;
};
})
58 changes: 58 additions & 0 deletions pkgs/by-name/co/comfyui/use-writable-runtime-paths.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
diff --git a/comfy/cli_args.py b/comfy/cli_args.py
index 810c90935..09d5bad61 100644
--- a/comfy/cli_args.py
+++ b/comfy/cli_args.py
@@ -42,7 +42,9 @@ parser.add_argument("--enable-cors-header", type=str, default=None, metavar="ORI
parser.add_argument("--enable-cors-header", type=str, default=None, metavar="ORIGIN", nargs="?", const="*", help="Enable CORS (Cross-Origin Resource Sharing) with optional origin or allow all with default '*'.")
parser.add_argument("--max-upload-size", type=float, default=100, help="Set the maximum upload size in MB.")

-parser.add_argument("--base-directory", type=str, default=None, help="Set the ComfyUI base directory for models, custom_nodes, input, output, temp, and user directories.")
+xdg_data_home = os.environ.get("XDG_DATA_HOME") or os.path.expanduser("~/.local/share")
+comfyui_data_home = os.path.join(xdg_data_home, "comfyui")
+parser.add_argument("--base-directory", type=str, default=comfyui_data_home, help="Set the ComfyUI base directory for models, custom_nodes, input, output, temp, and user directories.")
parser.add_argument("--extra-model-paths-config", type=str, default=None, metavar="PATH", nargs='+', action='append', help="Load one or more extra_model_paths.yaml files.")
parser.add_argument("--output-directory", type=str, default=None, help="Set the ComfyUI output directory. Overrides --base-directory.")
parser.add_argument("--temp-directory", type=str, default=None, help="Set the ComfyUI temp directory (default is in the ComfyUI directory). Overrides --base-directory.")
@@ -233,9 +235,7 @@ parser.add_argument(
help="Set the base URL for the ComfyUI API. (default: https://api.comfy.org)",
)

-database_default_path = os.path.abspath(
- os.path.join(os.path.dirname(__file__), "..", "user", "comfyui.db")
-)
+database_default_path = os.path.join(comfyui_data_home, "user", "comfyui.db")
parser.add_argument("--database-url", type=str, default=f"sqlite:///{database_default_path}", help="Specify the database URL, e.g. for an in-memory database you can use 'sqlite:///:memory:'.")
parser.add_argument("--enable-assets", action="store_true", help="Enable the assets system (API routes, database synchronization, and background scanning).")

diff --git a/folder_paths.py b/folder_paths.py
index 2a7a7a996..8062cc1b6 100644
--- a/folder_paths.py
+++ b/folder_paths.py
@@ -40,7 +40,8 @@ folder_names_and_paths["upscale_models"] = ([os.path.join(models_dir, "upscale_

folder_names_and_paths["latent_upscale_models"] = ([os.path.join(models_dir, "latent_upscale_models")], supported_pt_extensions)

-folder_names_and_paths["custom_nodes"] = ([os.path.join(base_path, "custom_nodes")], set())
+custom_nodes_directory = os.path.join(base_path, "custom_nodes")
+folder_names_and_paths["custom_nodes"] = ([custom_nodes_directory], set())

folder_names_and_paths["hypernetworks"] = ([os.path.join(models_dir, "hypernetworks")], supported_pt_extensions)

@@ -101,11 +102,12 @@ def map_legacy(folder_name: str) -> str:
"clip": "text_encoders"}
return legacy.get(folder_name, folder_name)

-if not os.path.exists(input_directory):
- try:
- os.makedirs(input_directory)
- except:
- logging.error("Failed to create input directory")
+for default_directory in (input_directory, custom_nodes_directory):
+ if not os.path.exists(default_directory):
+ try:
+ os.makedirs(default_directory)
+ except:
+ logging.error(f"Failed to create {default_directory}")

def set_output_directory(output_dir: str) -> None:
global output_directory
37 changes: 37 additions & 0 deletions pkgs/development/python-modules/comfy-aimdo/default.nix
Comment thread
caniko marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
lib,
buildPythonPackage,
fetchFromGitHub,
setuptools,
setuptools-scm,
}:

buildPythonPackage (finalAttrs: {
pname = "comfy-aimdo";
version = "0.2.14";
pyproject = true;

src = fetchFromGitHub {
owner = "Comfy-Org";
repo = "comfy-aimdo";
tag = "v${finalAttrs.version}";
hash = "sha256-jmBVUwQkd6ceLVx1ZSNiByx1vZF+Al7/jmgz0sy+B/E=";
};

build-system = [
setuptools
setuptools-scm
];

# Upstream ships no test suite at this tag.
doCheck = false;

pythonImportsCheck = [ "comfy_aimdo.control" ];

meta = {
description = "AI model dynamic offloader for ComfyUI";
homepage = "https://github.com/Comfy-Org/comfy-aimdo";
license = lib.licenses.gpl3Only;
maintainers = with lib.maintainers; [ caniko ];
};
})
47 changes: 47 additions & 0 deletions pkgs/development/python-modules/comfy-kitchen/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
lib,
buildPythonPackage,
fetchFromGitHub,
nanobind,
setuptools,
torch,
}:

buildPythonPackage (finalAttrs: {
pname = "comfy-kitchen";
version = "0.2.8";
pyproject = true;

src = fetchFromGitHub {
owner = "Comfy-Org";
repo = "comfy-kitchen";
tag = "v${finalAttrs.version}";
hash = "sha256-u83fTb65wALGzgBZO53UJMEFSm1w727IBhiS5XVEoc4=";
};

build-system = [
nanobind
setuptools
];

dependencies = [ torch ];

postPatch = ''
substituteInPlace setup.py \
--replace-fail "BUILD_NO_CUDA = False" "BUILD_NO_CUDA = True"
'';

# Upstream tests exercise the CUDA/Triton kernel backends; this build
# uses BUILD_NO_CUDA = True so those backends are unavailable and the
# suite cannot run in the sandbox.
doCheck = false;

pythonImportsCheck = [ "comfy_kitchen" ];

meta = {
description = "Fast kernel library for ComfyUI with multiple compute backends";
homepage = "https://github.com/Comfy-Org/comfy-kitchen";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ caniko ];
};
})
32 changes: 32 additions & 0 deletions pkgs/development/python-modules/comfyui-embedded-docs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
lib,
buildPythonPackage,
fetchPypi,
setuptools,
}:

buildPythonPackage (finalAttrs: {
pname = "comfyui-embedded-docs";
version = "0.4.4";
pyproject = true;

src = fetchPypi {
pname = "comfyui_embedded_docs";
inherit (finalAttrs) version;
hash = "sha256-+ZoRloCC+TQtszf8BpFkqN6UT2Op9efoMZ+8TQZhedk=";
};

build-system = [ setuptools ];

# Package only ships static Markdown documentation; no tests.
doCheck = false;

pythonImportsCheck = [ "comfyui_embedded_docs" ];

meta = {
description = "Embedded node documentation for ComfyUI";
homepage = "https://github.com/Comfy-Org/embedded-docs";
license = lib.licenses.gpl3Only;
maintainers = with lib.maintainers; [ caniko ];
};
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
lib,
buildPythonPackage,
fetchPypi,
setuptools,
}:

buildPythonPackage (finalAttrs: {
pname = "comfyui-frontend-package";
version = "1.42.15";
pyproject = true;

src = fetchPypi {
pname = "comfyui_frontend_package";
inherit (finalAttrs) version;
hash = "sha256-V1j+wiJSMyePkySd0PaNs99XLx3B4zT/tp7uV3AxuBQ=";
};

build-system = [ setuptools ];

# Package only ships the prebuilt frontend bundle; no tests.
doCheck = false;

pythonImportsCheck = [ "comfyui_frontend_package" ];

meta = {
description = "Frontend assets for ComfyUI";
homepage = "https://github.com/Comfy-Org/ComfyUI_frontend";
license = lib.licenses.gpl3Only;
maintainers = with lib.maintainers; [ caniko ];
};
})
Loading
Loading