From 431174cd19afd5ac1671d2a42cde53f7cb6e59d5 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Wed, 15 Apr 2026 21:45:40 -0400 Subject: [PATCH] better comfy --- modules/nixos/server/services/comfyui/init.sh | 56 +++++++++++++++++++ .../server/services/comfyui/rocm-docker.nix | 11 ++-- .../services/comfyui/rocm.Containerfile | 7 +-- 3 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 modules/nixos/server/services/comfyui/init.sh diff --git a/modules/nixos/server/services/comfyui/init.sh b/modules/nixos/server/services/comfyui/init.sh new file mode 100644 index 0000000..b3c36db --- /dev/null +++ b/modules/nixos/server/services/comfyui/init.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# init.sh – runs inside the ComfyUI Docker container +# +# 1. Checks whether each custom node directory exists. +# 2. If a node is missing, it is cloned from its repository +# and its Python dependencies are installed via pip. +# 3. Finally, the script hands control over to the ComfyUI server +# (python main.py ...). + +set -euo pipefail + +# The base directory for ComfyUI – exported in the Dockerfile. +COMFYUI_PATH=${COMFYUI_PATH:-/workspace/ComfyUI} + +# Helper to clone and install a node only if it does not already exist. +install_node() { + local repo_url=$1 + local node_dir=$2 + local req_file=$3 + + if [ ! -d "$node_dir" ]; then + echo "Cloning $repo_url into $node_dir ..." + git clone "$repo_url" "$node_dir" + + if [ -f "$req_file" ]; then + echo "Installing dependencies for $node_dir ..." + pip install --no-cache-dir -r "$req_file" + else + echo "No requirements file found for $node_dir; skipping pip install." + fi + else + echo "$node_dir already exists; skipping clone." + fi +} + +# 1️⃣ ComfyUI‑Manager +install_node "https://github.com/ltdrdata/ComfyUI-Manager" \ + "$COMFYUI_PATH/custom_nodes/ComfyUI-Manager" \ + "$COMFYUI_PATH/custom_nodes/ComfyUI-Manager/requirements.txt" + +# 2️⃣ WAN 2.1 Video Wrapper +install_node "https://github.com/kijai/ComfyUI-WanVideoWrapper" \ + "$COMFYUI_PATH/custom_nodes/ComfyUI-WanVideoWrapper" \ + "$COMFYUI_PATH/custom_nodes/ComfyUI-WanVideoWrapper/requirements.txt" + +# 3️⃣ Video Helper Suite +install_node "https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite" \ + "$COMFYUI_PATH/custom_nodes/ComfyUI-VideoHelperSuite" \ + "$COMFYUI_PATH/custom_nodes/ComfyUI-VideoHelperSuite/requirements.txt" + +# 4️⃣ Start the ComfyUI server +echo "Starting ComfyUI..." +exec python "$COMFYUI_PATH/main.py" \ + --listen 0.0.0.0 \ + --port 8188 \ + --use-pytorch-cross-attention diff --git a/modules/nixos/server/services/comfyui/rocm-docker.nix b/modules/nixos/server/services/comfyui/rocm-docker.nix index 4cce8e6..2b59750 100644 --- a/modules/nixos/server/services/comfyui/rocm-docker.nix +++ b/modules/nixos/server/services/comfyui/rocm-docker.nix @@ -11,9 +11,10 @@ let # Load Containerfile from file containerfile = ./rocm.Containerfile; + containerinitsh = ./init.sh; # Image name and tag - imageName = "comfyui-rocm"; + imageName = "nix-comfyui-rocm"; imageTag = cfg.rocm.imageTag; fullImageName = "${imageName}:${imageTag}"; in @@ -21,13 +22,13 @@ in options.skyg.nixos.server.services.comfyui.rocm = with lib; { uid = mkOption { type = types.int; - default = 1000; + default = 0; description = "User ID to run the ComfyUI container as"; }; gid = mkOption { type = types.int; - default = 100; + default = 0; description = "Group ID to run the ComfyUI container as"; }; @@ -111,6 +112,8 @@ in system.activationScripts.comfyui-rocm-build = { text = '' # Check if image exists or rebuild is requested + # Note: init.sh is located next to the Dockerfile, so it is automatically + # included in the Docker build context and no explicit copy step is needed. if ! ${pkgs.docker}/bin/docker image inspect ${fullImageName} > /dev/null 2>&1 || ${lib.boolToString cfg.rocm.rebuildImage}; then echo "Building ComfyUI ROCm Docker image..." ${pkgs.docker}/bin/docker build \ @@ -118,7 +121,7 @@ in --build-arg COMFYUI_COMMIT=${cfg.rocm.comfyuiCommit} \ --build-arg HSA_OVERRIDE_GFX_VERSION=${cfg.rocm.hsaOverrideGfxVersion} \ -f ${containerfile} \ - ${pkgs.emptyDirectory} + $(dirname "${containerinitsh}") else echo "ComfyUI ROCm Docker image already exists, skipping build." fi diff --git a/modules/nixos/server/services/comfyui/rocm.Containerfile b/modules/nixos/server/services/comfyui/rocm.Containerfile index 8bd1774..4085d94 100644 --- a/modules/nixos/server/services/comfyui/rocm.Containerfile +++ b/modules/nixos/server/services/comfyui/rocm.Containerfile @@ -52,7 +52,6 @@ RUN mkdir -p \ WORKDIR "$COMFYUI_PATH" EXPOSE 8188 -CMD ["python", "main.py", \ - "--listen", "0.0.0.0", \ - "--port", "8188", \ - "--use-pytorch-cross-attention"] +COPY init.sh /init.sh +RUN chmod +x /init.sh +ENTRYPOINT ["/init.sh"]