whole bunch of stuff

This commit is contained in:
atagen 2025-01-03 16:14:31 +11:00
parent bafb226314
commit 4e99a0e323
43 changed files with 555 additions and 868 deletions

117
flakes/comfyui/default.nix Normal file
View file

@ -0,0 +1,117 @@
{
pkgs,
lib,
config,
comfyui,
comfy_dir ? "/run/user/1000/comfyui/",
spandrel,
plugins ? config.comfyui.plugins or [],
...
}: let
inherit (pkgs) python3;
inherit
(pkgs.python3Packages)
torch
torchsde
torchvision
torchaudio
einops
transformers
tokenizers
sentencepiece
safetensors
aiohttp
pyyaml
pillow
scipy
tqdm
psutil
kornia
soundfile
;
python = python3.buildEnv.override {
extraLibs =
[
torch
torchsde
torchvision
torchaudio
einops
transformers
tokenizers
sentencepiece
safetensors
aiohttp
pyyaml
pillow
scipy
tqdm
psutil
kornia
soundfile
spandrel
]
++ plugins;
};
# python = python3.withPackages (
# ps:
# with ps; [
# torch
# torchsde
# torchvision
# torchaudio
# einops
# transformers
# tokenizers
# sentencepiece
# safetensors
# aiohttp
# pyyaml
# pillow
# scipy
# tqdm
# psutil
# kornia
# soundfile
# spandrel
# ]
# );
in
pkgs.stdenvNoCC.mkDerivation {
name = "comfyui";
pname = "comfyui";
version = "dev-${builtins.toString comfyui.lastModified}";
src = comfyui;
nativeBuildInputs = let
inherit (pkgs) makeWrapper;
in [
makeWrapper
];
propagatedBuildInputs = let
inherit (pkgs.cudaPackages) cudatoolkit;
in [
python
cudatoolkit
];
patches = [./folder_paths.patch];
installPhase = let
launcher =
pkgs.writeShellScript "launch.sh"
''
mkdir -p $COMFY_DIR/custom_nodes
mkdir -p $COMFY_DIR/models/{checkpoints,configs,loras,vae,clip,unet,diffusion_models,clip_vision,style_models,embeddings,diffusers,vae_approx,controlnet,gligen,upscale_models,hypernetworks,photomaker,classifiers}
${python}/bin/python3 $COMFY/comfyui/main.py --output-directory $(mktemp)
'';
in ''
mkdir -p $out/comfyui
cp -r * $out/comfyui
mkdir -p $out/bin
makeWrapper ${launcher} $out/bin/comfyui --prefix PATH : ${lib.makeBinPath [python]} \
--set PYTHONPATH ${lib.makeLibraryPath [python]} --set COMFY $out --set COMFY_DIR ${comfy_dir}
'';
meta.mainProgram = "comfyui";
}

41
flakes/comfyui/flake.lock generated Normal file
View file

@ -0,0 +1,41 @@
{
"nodes": {
"comfyui": {
"flake": false,
"locked": {
"lastModified": 1735863648,
"narHash": "sha256-hMe8kXco8PTtOeLq0Q2+P3MbcnnShzAlOeCnY1MSuyI=",
"owner": "comfyanonymous",
"repo": "ComfyUI",
"rev": "0b9839ef433572609b37d880afb427e4c9ddf151",
"type": "github"
},
"original": {
"owner": "comfyanonymous",
"repo": "ComfyUI",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1735471104,
"narHash": "sha256-0q9NGQySwDQc7RhAV2ukfnu7Gxa5/ybJ2ANT8DQrQrs=",
"path": "/nix/store/8vz84mqgnm1gz5yk7hgnnb5gir5hjxas-source",
"rev": "88195a94f390381c6afcdaa933c2f6ff93959cb4",
"type": "path"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"comfyui": "comfyui",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

48
flakes/comfyui/flake.nix Normal file
View file

@ -0,0 +1,48 @@
{
inputs = {
comfyui = {
url = "github:comfyanonymous/ComfyUI";
flake = false;
};
};
nixConfig = {
extra-substituters = ["https://nix-community.cachix.org" "https://cuda-maintainers.cachix.org"];
extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E="
];
};
outputs = {
self,
nixpkgs,
comfyui,
}: {
homeManagerModules.comfyui = import ./module.nix;
overlays.comfyui = final: _prev: {
comfyui = let
spandrel = final.callPackage ./spandrel.nix {};
in
final.callPackage ./default.nix {
cudaSupport = true;
inherit comfyui spandrel;
};
};
packages.x86_64-linux = let
system = "x86_64-linux";
pkgs = import nixpkgs {
config.allowUnfree = true;
config.cudaSupport = true;
inherit system;
};
spandrel = pkgs.callPackage ./spandrel.nix {};
in {
default = pkgs.callPackage ./default.nix {
inherit comfyui spandrel;
};
};
};
}

View file

@ -0,0 +1,28 @@
diff --git a/folder_paths.py b/folder_paths.py
index 01ae821..27906ac 100644
--- a/folder_paths.py
+++ b/folder_paths.py
@@ -11,7 +11,7 @@ supported_pt_extensions: set[str] = {'.ckpt', '.pt', '.bin', '.pth', '.safetenso
folder_names_and_paths: dict[str, tuple[list[str], set[str]]] = {}
-base_path = os.path.dirname(os.path.realpath(__file__))
+base_path = os.path.dirname(os.environ['COMFY_DIR'])
models_dir = os.path.join(base_path, "models")
folder_names_and_paths["checkpoints"] = ([os.path.join(models_dir, "checkpoints")], supported_pt_extensions)
folder_names_and_paths["configs"] = ([os.path.join(models_dir, "configs")], [".yaml"])
@@ -39,10 +39,10 @@ folder_names_and_paths["photomaker"] = ([os.path.join(models_dir, "photomaker")]
folder_names_and_paths["classifiers"] = ([os.path.join(models_dir, "classifiers")], {""})
-output_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "output")
-temp_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "temp")
-input_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "input")
-user_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "user")
+output_directory = os.path.join(base_path, "output")
+temp_directory = os.path.join(base_path, "temp")
+input_directory = os.path.join(base_path, "input")
+user_directory = os.path.join(base_path, "user")
filename_list_cache: dict[str, tuple[list[str], dict[str, float], float]] = {}

46
flakes/comfyui/module.nix Normal file
View file

@ -0,0 +1,46 @@
{
pkgs,
lib,
config,
...
}: let
inherit (lib) mkEnableOption mkOption types hasSuffix;
cfg = config.programs.comfyui;
# comfyui only understands the path properly with a trailing slash
getStorage =
if (hasSuffix "/" cfg.storage)
then cfg.storage
else cfg.storage + "/";
in {
options.programs.comfyui = {
enable = mkEnableOption "ComfyUI";
storage = mkOption {
type = types.path;
description = "where to source models and store information";
};
plugins = mkOption {
type = with types; listOf package;
description = "list of comfyui plugins";
default = [];
};
};
config = lib.mkIf cfg.enable {
home.packages = [
# pkgs.comfyui
(pkgs.comfyui.override {
comfy_dir = getStorage;
plugins = cfg.plugins;
})
];
home.file = builtins.listToAttrs (map (
pkg: {
name = "${getStorage}/custom_nodes/${pkg.name}";
value = {
recursive = true;
source = "${pkg}";
};
}
)
cfg.plugins);
};
}

View file

@ -0,0 +1,43 @@
{
lib,
python3Packages,
fetchPypi,
...
}:
python3Packages.buildPythonPackage rec {
pname = "spandrel";
version = "0.4.0";
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-9FUmiT+SOhLvN1QsROREsSCJdlk7x8zfpU/QTHw+gMo=";
};
build-system = let
inherit (python3Packages) setuptools;
in [
setuptools
];
dependencies = let
inherit
(python3Packages)
torch
torchvision
safetensors
numpy
einops
typing-extensions
;
in [
torch
torchvision
safetensors
numpy
einops
typing-extensions
];
doCheck = false;
}