diff --git a/modules/comfyui/default.nix b/modules/comfyui/default.nix new file mode 100644 index 00000000..9f345919 --- /dev/null +++ b/modules/comfyui/default.nix @@ -0,0 +1,172 @@ +{ withSystem, ... }: +{ + flake.modules.nixos.comfyui = + { + pkgs, + config, + lib, + ... + }: + let + cfg = config.services.comfyui; + package = withSystem pkgs.stdenv.hostPlatform.system ( + { config, ... }: config.packages.comfyui.override ({ inherit (cfg) basePath; }) + ); + in + { + options.services.pyroscope = + with lib; + { + enable = mkEnableOption (lib.mdDoc "ComfyUI"); + basePath = mkOption { + type = types.path; + default = "/var/lib/comfyui"; + description = "Base path for ComfyUI data."; + }; + nodes = mkOption { + type = types.listOf types.package; + default = [ ]; + description = "List of custom nodes to install. (Some are defined in comfyui.nodes)"; + }; + models = mkOption { + type = types.attrsOf types.listOf ( + types.either types.package ( + types.submodule { + options = { + url = mkOption { + type = types.str; + description = "URL to the model."; + }; + hash = mkOption { + type = types.str; + description = "Hash of the model."; + }; + name = mkOption { + type = types.str; + default = null; + description = "Filename of the model."; + }; + }; + } + ) + ); + default = { + checkpoints = [ ]; + clip = [ ]; + clip_vision = [ ]; + configs = [ ]; + controlnet = [ ]; + diffusion_models = [ ]; + embeddings = [ ]; + loras = [ ]; + style_models = [ ]; + text_encoders = [ ]; + upscale_models = [ ]; + vae = [ ]; + vae_approx = [ ]; + }; + description = "List of models to install. (Either derivations or sets of urls, hashes and optionally filenames)"; + }; + port = mkOption { + type = types.port; + default = 8188; + description = "Port for ComfyUI."; + }; + listen = mkOption { + type = types.str; + default = null; + description = "Specify the IP address to listen on (default: 127.0.0.1). You can give a list of ip addresses by separating them with a comma like: 127.2.2.2,127.3.3.3 If --listen is provided without an argument, it defaults to 0.0.0.0,:: (listens on all ipv4 and ipv6)"; + }; + cudaDevice = mkOption { + type = types.str; + default = null; + description = "Set the id of the cuda device this instance will use."; + }; + tlsKeyFile = mkOption { + type = types.path; + default = null; + description = "Path to the TLS key file. If set, ComfyUI will use TLS. (Requires tlsCertFile)"; + }; + tlsCertFile = mkOption { + type = types.path; + default = null; + description = "Path to the TLS certificate file. If set, ComfyUI will use TLS. (Requires tlsKeyFile)"; + }; + enableCorsHeader = mkOption { + type = types.either types.str types.bool; + default = false; + description = "Enable CORS (Cross-Origin Resource Sharing) with optional origin or allow all with default '*'."; + }; + maxUploadSize = mkOption { + type = types.int; + default = 0; + description = "Maximum upload size in MB. 0 means no limit."; + }; + cudaMAlloc = mkOption { + type = types.bool; + default = true; + description = "Enable cudaMallocAsync (enabled by default for torch 2.0 and up)."; + }; + deterministic = mkOption { + type = types.bool; + default = false; + description = "Enable deterministic mode (default: false)."; + }; + } + // builtins.listToAttrs ( + map + (x: { + name = "${x}Path"; + value = mkOption { + type = types.path; + default = "${cfg.basePath}/${x}"; + description = "Path for ComfyUI ${x} data."; + }; + }) + [ + "models" + "input" + "output" + "temp" + "user" + ] + ); + config = + with lib; + with builtins; + { + assertions = [ + { + assertion = (isNull cfg.tlsKeyFile) != (isNull cfg.tlsCertFile); + message = "If tlsKeyFile is set, tlsCertFile must also be set and vice versa."; + } + ]; + systemd.services.pyroscope = lib.mkIf cfg.enable { + description = "comfyui"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = + "${getExe package} --multi-user --port ${toString cfg.port}" + + (optionalString (!isNull cfg.listen) " --listen ${cfg.listen}") + + (optionalString (!isNull cfg.cudaDevice) " --cuda-device ${cfg.cudaDevice}") + + (optionalString (!isNull cfg.tlsKeyFile) " --tls-keyfile ${toString cfg.tlsKeyFile}") + + (optionalString (!isNull cfg.tlsCertFile) " --tls-certfile ${toString cfg.tlsCertFile}") + + (optionalString (cfg.enableCorsHeader != false) ( + " --enable-cors-header" + + ( + if isString cfg.enableCorsHeader then + cfg.enableCorsHeader + else if cfg.enableCorsHeader == true then + "*" + else + "" + ) + )) + + (optionalString (cfg.maxUploadSize != 0) " --max-upload-size ${toString cfg.maxUploadSize}") + + (if cfg.cudaMAlloc then " --cuda-malloc" else " --disable-cuda-malloc") + + (optionalString cfg.deterministic " --deterministic"); + }; + }; + }; + }; +} diff --git a/modules/default.nix b/modules/default.nix index 19a71c0d..e241fac8 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -7,5 +7,6 @@ ./random-alerts ./host-info.nix ./secrets.nix + ./comfyui ]; } diff --git a/packages/comfyui/base.nix b/packages/comfyui/base.nix new file mode 100644 index 00000000..6acfad36 --- /dev/null +++ b/packages/comfyui/base.nix @@ -0,0 +1,56 @@ +{ + version, + modelPathsFile, + modelsPath, + inputPath, + outputPath, + tempPath, + userPath, + stdenv, + fetchFromGitHub, +}: +stdenv.mkDerivation { + pname = "comfyui-base"; + inherit version; + + src = fetchFromGitHub { + owner = "comfyanonymous"; + repo = "ComfyUI"; + rev = "b685b8a4e098237919adae580eb29e8d861b738f"; + hash = "sha256-OtTvyqiz2Ba7HViW2MxC1hFulSWPuQaCADeQflr80Ik="; + }; + + 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/app $out/ + cp -r $src/api_server $out/ + cp -r $src/comfy $out/ + cp -r $src/comfy_api_nodes $out/ + cp -r $src/comfy_extras $out/ + cp -r $src/comfy_execution $out/ + cp -r $src/utils $out/ + cp $src/*.py $out/ + cp --remove-destination $src/folder_paths.py $out/ + cp $src/requirements.txt $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 + echo "Setting up node folders" + ln -s ${modelsPath}/wildcards $out/wildcards + mkdir -p $out/${tempPath} + echo "Patching python code..." + substituteInPlace $out/folder_paths.py --replace 'os.path.join(base_path, "temp")' '"${tempPath}"' + substituteInPlace $out/folder_paths.py --replace 'os.path.join(base_path, "user")' '"${userPath}"' + runHook postInstall + ''; +} diff --git a/packages/comfyui/default.nix b/packages/comfyui/default.nix new file mode 100644 index 00000000..36614a65 --- /dev/null +++ b/packages/comfyui/default.nix @@ -0,0 +1,141 @@ +{ + lib, + runCommand, + callPyPackage, + writers, + writeTextFile, + pkgs, + basePath ? "/var/lib/comfyui", + modelsPath ? "${basePath}/models", + inputPath ? "${basePath}/input", + outputPath ? "${basePath}/output", + tempPath ? "${basePath}/temp", + userPath ? "${basePath}/user", + customNodes ? [ ], + models ? { + checkpoints = [ ]; + clip = [ ]; + clip_vision = [ ]; + configs = [ ]; + controlnet = [ ]; + embeddings = [ ]; + upscale_modules = [ ]; + vae = [ ]; + vae_approx = [ ]; + gligen = [ ]; + }, +}: + +let + version = "unstable-2025-04-26"; + + config-data = { + comfyui = { + base_path = modelsPath; + checkpoints = "${modelsPath}/checkpoints"; + clip = "${modelsPath}/clip"; + clip_vision = "${modelsPath}/clip_vision"; + configs = "${modelsPath}/configs"; + controlnet = "${modelsPath}/controlnet"; + diffusion_models = "${modelsPath}/diffusion_models"; + embeddings = "${modelsPath}/embeddings"; + loras = "${modelsPath}/loras"; + style_models = "${modelsPath}/style_models"; + text_encoders = "${modelsPath}/text_encoders"; + 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 = callPyPackage ./python-env.nix { + inherit customNodes; + }; + + installedModels = + let + # Helper function to process a single category + processCategory = + category: urls: + map ( + model: + if lib.isDerivation model then + model + else + pkgs.fetchurl rec { + url = model.url; + name = if model.name != null then model.name else builtins.baseNameOf model.url; + hash = model.hash; + downloadToTemp = true; + recursiveHash = true; + postFetch = '' + echo mkdir -p "$out"/${category} + mkdir -p "$out"/${category} + cp "$downloadedFile" "$out"/${category}/${name} + ''; + } + ) urls; + in + builtins.concatLists (builtins.attrValues (builtins.mapAttrs processCategory models)); + + comfyui-base = callPyPackage ./base.nix { + inherit + version + modelsPath + modelPathsFile + inputPath + outputPath + tempPath + userPath + ; + }; + + wrapperScript = writers.writeBashBin "comfyui" '' + cd $out + export WAS_CONFIG_DIR="${userPath}" + ${pythonEnv}/bin/python comfyui \ + --input-directory ${inputPath} \ + --output-directory ${outputPath} \ + --extra-model-paths-config ${modelPathsFile} \ + --temp-directory ${tempPath} \ + "$@" + ''; + +in +(runCommand "comfyui" + { + inherit version; + + meta = { + homepage = "https://github.com/comfyanonymous/ComfyUI"; + description = "The most powerful and modular stable diffusion GUI with a graph/nodes interface."; + license = lib.licenses.gpl3; + platforms = lib.platforms.all; + }; + passthru.nodes = import ./nodes { inherit callPyPackage; }; + } + ( + '' + mkdir -p $out/{bin,custom_nodes,models} + '' + + (lib.concatMapStrings (dir: '' + [[ ${dir.pname} == "was-node-suite" ]] && mkdir -p $out/custom_nodes/was-node-suite + cp -r ${dir}/* $out/ + '') ([ comfyui-base ] ++ customNodes)) + + (lib.concatMapStrings (model: '' + cd ${model} + find . -mindepth 1 -type d -exec mkdir -p $out/models/{} \; + cp -rs ${model}/* $out/models/ + '') installedModels) + + '' + cp ${wrapperScript}/bin/comfyui $out/bin/comfyui + chmod +x $out/bin/comfyui + substituteInPlace $out/bin/comfyui --replace "\$out" "$out" + '' + ) +) diff --git a/packages/comfyui/nodes/default.nix b/packages/comfyui/nodes/default.nix new file mode 100644 index 00000000..4a87b0d4 --- /dev/null +++ b/packages/comfyui/nodes/default.nix @@ -0,0 +1,11 @@ +{ callPyPackage }: +{ + wildcards = callPyPackage ./wildcards.nix { }; + impact-pack = callPyPackage ./impact-pack.nix { }; + # impact-subpack = callPyPackage ./impact-subpack.nix { }; # can't find ultralytics + rgthree-comfy = callPyPackage ./rgthree-comfy.nix { }; + essentials = callPyPackage ./essentials.nix { }; + inspire-pack = callPyPackage ./inspire-pack.nix { }; + ljnodes = callPyPackage ./ljnodes.nix { }; + was-node-suite = callPyPackage ./was-node-suite.nix { }; # needs directory to be writeable, and opencv with ffmpeg +} diff --git a/packages/comfyui/nodes/essentials.nix b/packages/comfyui/nodes/essentials.nix new file mode 100644 index 00000000..added1a8 --- /dev/null +++ b/packages/comfyui/nodes/essentials.nix @@ -0,0 +1,32 @@ +{ + stdenv, + python312, + fetchFromGitHub, + colour-science, + rembg, + pixeloe, + transparent-background, +}: +stdenv.mkDerivation rec { + pname = "essentials"; + version = "unstable"; + src = fetchFromGitHub { + owner = "cubiq"; + repo = "ComfyUI_essentials"; + rev = "9d9f4bedfc9f0321c19faf71855e228c93bd0dc9"; + hash = "sha256-wkwkZVZYqPgbk2G4DFguZ1absVUFRJXYDRqgFrcLrfU="; + }; + installPhase = '' + mkdir -p $out/custom_nodes/${pname} + cp -r $src/* $out/custom_nodes/${pname} + ''; + + dependencies = buildInputs; + buildInputs = with python312.pkgs; [ + numba + colour-science + rembg + pixeloe + transparent-background + ]; +} diff --git a/packages/comfyui/nodes/impact-pack.nix b/packages/comfyui/nodes/impact-pack.nix new file mode 100644 index 00000000..35b8c6ce --- /dev/null +++ b/packages/comfyui/nodes/impact-pack.nix @@ -0,0 +1,33 @@ +{ + stdenv, + python312, + fetchFromGitHub, + segment-anything, + transformersWithCuda, +}: +stdenv.mkDerivation rec { + pname = "impact-pack"; + version = "8.14.2"; + src = fetchFromGitHub { + owner = "ltdrdata"; + repo = "ComfyUI-Impact-Pack"; + rev = version; + hash = "sha256-yPf769ncRD/WoWeYrMUNDNOYySgJihu6kiwQhtFrau8="; + }; + installPhase = '' + mkdir -p $out/custom_nodes/${pname} + cp -r $src/* $out/custom_nodes/${pname} + ''; + + dependencies = with python312.pkgs; [ + segment-anything + scikit-image + piexif + transformersWithCuda + opencv-python-headless + scipy + numpy_1 + dill + matplotlib + ]; +} diff --git a/packages/comfyui/nodes/impact-subpack.nix b/packages/comfyui/nodes/impact-subpack.nix new file mode 100644 index 00000000..e99f85a6 --- /dev/null +++ b/packages/comfyui/nodes/impact-subpack.nix @@ -0,0 +1,30 @@ +{ + stdenv, + python312, + fetchFromGitHub, + ultralytics, + ultralytics-thop, +}: +stdenv.mkDerivation rec { + pname = "impact-subpack"; + version = "1.3.2"; + src = fetchFromGitHub { + owner = "ltdrdata"; + repo = "ComfyUI-Impact-Subpack"; + rev = version; + hash = "sha256-kddOby08UI4dIEL7nHvONRnwNY50FU8Qsj7RRDHw8k4="; + }; + installPhase = '' + mkdir -p $out/custom_nodes/${pname} + cp -r $src/* $out/custom_nodes/${pname} + ''; + + dependencies = with python312.pkgs; [ + matplotlib + ultralytics + ultralytics-thop + numpy_1 + opencv-python-headless + dill + ]; +} diff --git a/packages/comfyui/nodes/inspire-pack.nix b/packages/comfyui/nodes/inspire-pack.nix new file mode 100644 index 00000000..0c1ecba5 --- /dev/null +++ b/packages/comfyui/nodes/inspire-pack.nix @@ -0,0 +1,27 @@ +{ + stdenv, + python312, + fetchFromGitHub, +}: +stdenv.mkDerivation rec { + pname = "inspire-pack"; + version = "1.18"; + src = fetchFromGitHub { + owner = "ltdrdata"; + repo = "ComfyUI-Inspire-Pack"; + rev = version; + hash = "sha256-mRE6RWK4gwc6Hw1gL2xeIWpSzT677QnBTNAy9OdutLM="; + }; + installPhase = '' + mkdir -p $out/custom_nodes/${pname} + cp -r $src/* $out/custom_nodes/${pname} + ''; + + dependencies = with python312.pkgs; [ + matplotlib + cachetools + numpy_1 + webcolors + opencv-python-headless + ]; +} diff --git a/packages/comfyui/nodes/ljnodes.nix b/packages/comfyui/nodes/ljnodes.nix new file mode 100644 index 00000000..3d1b5c9e --- /dev/null +++ b/packages/comfyui/nodes/ljnodes.nix @@ -0,0 +1,21 @@ +{ + stdenv, + python312, + fetchFromGitHub, +}: +stdenv.mkDerivation rec { + pname = "ljnodes"; + version = "unstable"; + src = fetchFromGitHub { + owner = "coolzilj"; + repo = "ComfyUI-LJNodes"; + rev = "8172f7221071bc9b04e0230aed7648944c62c350"; + hash = "sha256-sBEf6bY2/EU7CznR5m20G6CY6+LCdGRhWAHHcRSZNiY="; + }; + installPhase = '' + mkdir -p $out/custom_nodes/${pname} + cp -r $src/* $out/custom_nodes/${pname} + ''; + + dependencies = [ ]; +} diff --git a/packages/comfyui/nodes/rgthree-comfy.nix b/packages/comfyui/nodes/rgthree-comfy.nix new file mode 100644 index 00000000..46d636fe --- /dev/null +++ b/packages/comfyui/nodes/rgthree-comfy.nix @@ -0,0 +1,22 @@ +{ + stdenv, + python312, + fetchFromGitHub, +}: +stdenv.mkDerivation rec { + pname = "rgthree-comfy"; + version = "unstable"; + src = fetchFromGitHub { + owner = "rgthree"; + repo = "rgthree-comfy"; + rev = "aa6c75a30b3ee8f01d7c9f8b0a126cccdc90616a"; + hash = "sha256-TTSBZatQhZFYkOumO30XUzJekqHZBFwLzVGw3JpeJX4="; + }; + installPhase = '' + mkdir -p $out/custom_nodes/${pname} + cp -r $src/* $out/custom_nodes/${pname} + ''; + + dependencies = buildInputs; + buildInputs = [ ]; +} diff --git a/packages/comfyui/nodes/was-node-suite.nix b/packages/comfyui/nodes/was-node-suite.nix new file mode 100644 index 00000000..9922d718 --- /dev/null +++ b/packages/comfyui/nodes/was-node-suite.nix @@ -0,0 +1,52 @@ +{ + stdenv, + python312, + fetchFromGitHub, + rembg, + fairscaleWithCuda, + timmWithCuda, + transformersWithCuda, + pilgram, + img2texture, + cstr, +}: +stdenv.mkDerivation rec { + pname = "was-node-suite"; + version = "unstable"; + src = fetchFromGitHub { + owner = "WASasquatch"; + repo = "was-node-suite-comfyui"; + rev = "1cd8d304eda256c412b8589ce1f00be3c61cf9ec"; + hash = "sha256-wV7MOaAWVPyw+oA5Rhw0+WYkuiZ+Ygr01DbPWbQsXHM="; + }; + installPhase = '' + mkdir -p $out/custom_nodes/${pname} + cp -r $src/* $out/custom_nodes/${pname} + ''; + + dependencies = with python312.pkgs; [ + cmake + fairscaleWithCuda + img2texture + cstr + gitpython + imageio + joblib + matplotlib + numba + numpy + opencv-python-headless + pilgram + #git+https://github.com/WASasquatch/ffmpy.git #WASasquatch's version only changes the version number + ffmpy + rembg + scikit-image + scikit-learn + scipy + timmWithCuda + tqdm + transformersWithCuda + + pip + ]; +} diff --git a/packages/comfyui/nodes/wildcards.nix b/packages/comfyui/nodes/wildcards.nix new file mode 100644 index 00000000..88242729 --- /dev/null +++ b/packages/comfyui/nodes/wildcards.nix @@ -0,0 +1,16 @@ +{ stdenv, fetchFromGitHub }: +stdenv.mkDerivation rec { + pname = "comfyui_wildcards"; + version = "unstable"; + src = fetchFromGitHub { + owner = "lordgasmic"; + repo = "comfyui_wildcards"; + rev = "c14cf0919f2fc6def75c7b34e954e22fc9c5135e"; + hash = "sha256-fRlgrwLpQy3iVhrV+kzCTObH3lWRJ3JYJLVAvDJXPCI="; + }; + installPhase = '' + mkdir -p $out/custom_nodes/${pname} + cp -r $src/* $out/custom_nodes/${pname} + ''; + dependencies = [ ]; +} diff --git a/packages/comfyui/python-env.nix b/packages/comfyui/python-env.nix new file mode 100644 index 00000000..da35c7ed --- /dev/null +++ b/packages/comfyui/python-env.nix @@ -0,0 +1,61 @@ +{ + python312, + comfyui-frontend-package, + comfyui-workflow-templates, + torchWithCuda, + torchsdeWithCuda, + torchvisionWithCuda, + torchaudioWithCuda, + numpy, + einops, + transformersWithCuda, + tokenizers, + sentencepiece, + safetensorsWithCuda, + aiohttp, + yarl, + pyyaml, + pillow, + scipy, + tqdm, + psutil, + + korniaWithCuda, + spandrel, + av, + pydantic, + + customNodes, +}: +python312.buildEnv.override { + extraLibs = ( + [ + comfyui-frontend-package + comfyui-workflow-templates + torchWithCuda + torchsdeWithCuda + torchvisionWithCuda + torchaudioWithCuda + numpy + einops + transformersWithCuda + tokenizers + sentencepiece + safetensorsWithCuda + aiohttp + yarl + pyyaml + pillow + scipy + tqdm + psutil + + korniaWithCuda + spandrel + av + pydantic + ] + ++ (builtins.concatMap (node: node.dependencies) customNodes) + ); + ignoreCollisions = false; +} diff --git a/packages/default.nix b/packages/default.nix index 7416812e..539fa501 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -1,18 +1,14 @@ { lib, ... }: { perSystem = - { - inputs', - pkgs, - ... - }: + { inputs', pkgs, ... }: let inherit (lib) optionalAttrs versionAtLeast; inherit (pkgs) system; inherit (pkgs.hostPlatform) isLinux; in rec { - legacyPackages = { + legacyPackages = rec { inputs = { nixpkgs = rec { inherit (pkgs) cachix; @@ -51,6 +47,21 @@ rustfmt targets.wasm32-wasi.latest.rust-std ]; + + callPyPackage = pkgs.lib.callPackageWith ( + pkgs + // pkgs.python312.pkgs + // pythonPackages + // { + poetry = pkgs.poetry; + } + ); + + pythonPackages = import ./python-packages { + inherit callPyPackage pkgs; + inherit (inputs') nixpkgs-unstable; + }; + }; packages = @@ -65,13 +76,16 @@ // optionalAttrs isLinux { folder-size-metrics = pkgs.callPackage ./folder-size-metrics { }; } - // optionalAttrs (system == "x86_64-linux") { + // optionalAttrs (system == "x86_64-linux") rec { mcl = pkgs.callPackage ./mcl { buildDubPackage = inputs'.dlang-nix.legacyPackages.buildDubPackage.override { dCompiler = inputs'.dlang-nix.packages."ldc-binary-1_38_0"; }; inherit (legacyPackages.inputs.nixpkgs) cachix nix nix-eval-jobs; }; + comfyui = legacyPackages.callPyPackage ./comfyui { + inherit (legacyPackages) callPyPackage; + }; }; }; } diff --git a/packages/python-packages/chkpkg/default.nix b/packages/python-packages/chkpkg/default.nix new file mode 100644 index 00000000..fdd481d1 --- /dev/null +++ b/packages/python-packages/chkpkg/default.nix @@ -0,0 +1,25 @@ +{ + buildPythonPackage, + fetchgit, + python312, +}: +buildPythonPackage rec { + pname = "chkpkg_py"; + version = "0.5.2"; + pyproject = false; + + buildInputs = with python312.pkgs; [ + mypy + ]; + + src = fetchgit { + url = "https://github.com/rtmigo/chkpkg_py"; + rev = version; + hash = "sha256-qfIyrWlU65rryBKwxmWgmWbl1cbDQ1Pkfr6BsYJn+ks="; + }; + + meta = { + description = ""; + homepage = "https://github.com/rtmigo/chkpkg_py"; + }; +} diff --git a/packages/python-packages/colour-science/default.nix b/packages/python-packages/colour-science/default.nix new file mode 100644 index 00000000..08cbb463 --- /dev/null +++ b/packages/python-packages/colour-science/default.nix @@ -0,0 +1,108 @@ +{ + lib, + fetchFromGitHub, + buildPythonPackage, + pythonOlder, + opencolorio, + hatchling, + imageio, + numpy, + scipy, + typing-extensions, + pytestCheckHook, + pytest-xdist, + trimesh, + pydot, + matplotlib, + networkx, + pandas, + tqdm, + xxhash, +}: +buildPythonPackage rec { + pname = "colour-science"; + version = "0.4.6"; + pyproject = true; + disabled = pythonOlder "3.9"; + + src = fetchFromGitHub { + owner = "colour-science"; + repo = "colour"; + rev = "refs/tags/v${version}"; + hash = "sha256-kjJc6D4jhvAJh6rIVvKO2bw++K3XlfjD4Djav6778lk="; + }; + + nativeBuildInputs = [ + hatchling + ]; + + propagatedBuildInputs = [ + imageio + numpy + scipy + typing-extensions + ]; + + passthru.optional-dependencies = { + optional = [ + matplotlib + networkx + opencolorio + pandas + pydot + tqdm + xxhash + ]; + # docs = [ + # # biblib-simple # not available in nixpkgs + # pydata-sphinx-theme + # restructuredtext-lint + # sphinx + # sphinxcontrib-bibtex + # ]; + meshing = [ + trimesh + ]; + }; + + nativeCheckInputs = [ + pytestCheckHook + pytest-xdist + ] ++ lib.flatten (builtins.attrValues passthru.optional-dependencies); + + disabledTests = [ + # slow tests, supposing math is correct and tested upstream + "test_fairchild1990" + "test_jakob2019" + "test_kang2002" + "test_macadam_limits" + "test_mallett2019" + "test_meng2015" + "test_munsell" + "test_ohno2013" + "test_osa_ucs" + "test_otsu2018" + "test_pointer_gamut" + "test_rayleigh" + "test_rgb" + "test_robertson1968" + # not working, problems reading/writing exr files + "test_write_image_Imageio" + "test_read_image_Imageio" + "test_read_image" + "test_write_image" + # not working, uses numpy>2 stuff + "test_machado2009" + "test_photometry" + ]; + + pythonImportsCheck = [ "colour" ]; + + meta = { + description = "Algorithms and datasets for colour science"; + homepage = "https://github.com/colour-science/colour"; + changelog = "https://github.com/colour-science/colour/releases/tag/v${version}"; + license = lib.licenses.bsd3; + maintainers = with lib.maintainers; [ laurent-f1z1 ]; + }; +} diff --git a/packages/python-packages/comfyui-frontend-package/default.nix b/packages/python-packages/comfyui-frontend-package/default.nix new file mode 100644 index 00000000..3a3f3c7e --- /dev/null +++ b/packages/python-packages/comfyui-frontend-package/default.nix @@ -0,0 +1,26 @@ +{ + lib, + fetchPypi, + buildPythonPackage, +}: +buildPythonPackage rec { + pname = "comfyui-frontend-package"; + version = "1.17.11"; + + src = fetchPypi { + inherit version; + pname = "comfyui_frontend_package"; + hash = "sha256-v2Yfl730hvGEV+kFXva3lAJFDecVplvl+L5XY3PJdNU="; + }; + + pythonImportsCheck = [ "comfyui_frontend_package" ]; + + env.COMFYUI_FRONTEND_VERSION = version; + + meta = { + description = "ComfyUI frontend package"; + homepage = "https://github.com/Comfy-Org/ComfyUI_frontend"; + changelog = "https://github.com/Comfy-Org/ComfyUI_frontend/releases/tag/v${version}"; + license = lib.licenses.gpl3; + }; +} diff --git a/packages/python-packages/comfyui-workflow-templates/default.nix b/packages/python-packages/comfyui-workflow-templates/default.nix new file mode 100644 index 00000000..dc5b22b8 --- /dev/null +++ b/packages/python-packages/comfyui-workflow-templates/default.nix @@ -0,0 +1,23 @@ +{ + lib, + fetchPypi, + buildPythonPackage, +}: +buildPythonPackage rec { + pname = "comfyui-workflow-templates"; + version = "0.1.3"; + + src = fetchPypi { + inherit version; + pname = "comfyui_workflow_templates"; + hash = "sha256-Ivnf+xOOGzMJpu68RFH37vFPEsT9g/KxWUlMiE+Hglk="; + }; + + pythonImportsCheck = [ "comfyui_workflow_templates" ]; + + meta = { + description = "ComfyUI workflow templates"; + homepage = "https://github.com/Comfy-Org/workflow_templates"; + license = lib.licenses.gpl3; + }; +} diff --git a/packages/python-packages/cstr/default.nix b/packages/python-packages/cstr/default.nix new file mode 100644 index 00000000..a3fa11b1 --- /dev/null +++ b/packages/python-packages/cstr/default.nix @@ -0,0 +1,22 @@ +{ + buildPythonPackage, + fetchgit, +}: +buildPythonPackage { + pname = "cstr"; + version = "unstable"; + pyproject = false; + + buildInputs = [ ]; + + src = fetchgit { + url = "https://github.com/WASasquatch/cstr"; + rev = "0520c29a18a7a869a6e5983861d6f7a4c86f8e9b"; + hash = "sha256-zQDnjUk7IFVkWujPxq8JfUH6XIPHoaEG+xrLOEwXoro="; + }; + + meta = { + description = ""; + homepage = "https://github.com/WASasquatch/cstr"; + }; +} diff --git a/packages/python-packages/default.nix b/packages/python-packages/default.nix new file mode 100644 index 00000000..c8a91788 --- /dev/null +++ b/packages/python-packages/default.nix @@ -0,0 +1,54 @@ +{ + callPyPackage, + pkgs, + nixpkgs-unstable, +}: +let + python312Pkgs = pkgs.python312.pkgs; +in +rec { + spandrel = callPyPackage ./spandrel { }; + + comfyui-frontend-package = callPyPackage ./comfyui-frontend-package { }; + + comfyui-workflow-templates = callPyPackage ./comfyui-workflow-templates { }; + + segment-anything = callPyPackage ./segment-anything { }; + + pixeloe = callPyPackage ./pixeloe { }; + + pilgram = callPyPackage ./pilgram { }; + + transparent-background = callPyPackage ./transparent-background { }; + + colour-science = callPyPackage ./colour-science { }; + + cstr = callPyPackage ./cstr { }; + + img2texture = callPyPackage ./img2texture { }; + + chkpkg = callPyPackage ./chkpkg { }; + + neatest = callPyPackage ./neatest { }; + + inherit (python312Pkgs) torchWithCuda; + torchsdeWithCuda = (python312Pkgs.torchsde.override ({ torch = torchWithCuda; })); + torchvisionWithCuda = (python312Pkgs.torchvision.override ({ torch = torchWithCuda; })); + torchaudioWithCuda = (python312Pkgs.torchaudio.override ({ torch = torchWithCuda; })); + safetensorsWithCuda = (python312Pkgs.safetensors.override ({ torch = torchWithCuda; })); + transformersWithCuda = ( + python312Pkgs.transformers.override ({ safetensors = safetensorsWithCuda; }) + ); + korniaWithCuda = (python312Pkgs.kornia.override ({ torch = torchWithCuda; })); + fairscaleWithCuda = (python312Pkgs.fairscale.override ({ torch = torchWithCuda; })); + timmWithCuda = ( + python312Pkgs.timm.override ({ + safetensors = safetensorsWithCuda; + torchvision = torchvisionWithCuda; + torch = torchWithCuda; + }) + ); + + inherit (nixpkgs-unstable.legacyPackages.python312.pkgs) ultralytics ultralytics-thop rembg; + +} diff --git a/packages/python-packages/img2texture/default.nix b/packages/python-packages/img2texture/default.nix new file mode 100644 index 00000000..23bf4056 --- /dev/null +++ b/packages/python-packages/img2texture/default.nix @@ -0,0 +1,31 @@ +{ + buildPythonPackage, + fetchgit, + python312, + chkpkg, + neatest, +}: +buildPythonPackage { + pname = "img2texture"; + version = "unstable"; + pyproject = false; + + buildInputs = with python312.pkgs; [ + mypy + chkpkg + click + pyinstaller + neatest + ]; + + src = fetchgit { + url = "https://github.com/WASasquatch/img2texture"; + rev = "d6159abea44a0b2cf77454d3d46962c8b21eb9d3"; + hash = "sha256-58me9Rng+hy1ntUBJ8cUVVrk+CEFgmW/ATnzYk7N8U4="; + }; + + meta = { + description = ""; + homepage = "https://github.com/WASasquatch/img2texture"; + }; +} diff --git a/packages/python-packages/neatest/default.nix b/packages/python-packages/neatest/default.nix new file mode 100644 index 00000000..629ff7ab --- /dev/null +++ b/packages/python-packages/neatest/default.nix @@ -0,0 +1,25 @@ +{ + buildPythonPackage, + fetchgit, + chkpkg, +}: +buildPythonPackage rec { + pname = "neatest_py"; + version = "3.9.1"; + pyproject = false; + + buildInputs = [ + chkpkg + ]; + + src = fetchgit { + url = "https://github.com/rtmigo/neatest_py"; + rev = version; + hash = "sha256-bZlbVCqLXLp0ankEArDqxOFdn4ZtEDTMg9CwYnJaiFs="; + }; + + meta = { + description = ""; + homepage = "https://github.com/rtmigo/neatest_py"; + }; +} diff --git a/packages/python-packages/pilgram/default.nix b/packages/python-packages/pilgram/default.nix new file mode 100644 index 00000000..10240753 --- /dev/null +++ b/packages/python-packages/pilgram/default.nix @@ -0,0 +1,40 @@ +{ + buildPythonPackage, + fetchgit, + python312, + poetry, +}: +buildPythonPackage rec { + pname = "pilgram"; + version = "unstable"; + pyproject = true; + + nativeBuildInputs = buildInputs; + preBuild = '' + export HOME=$TMPDIR + ''; + buildInputs = with python312.pkgs; [ + numpy + pillow + poetry + poetry-core + flake8 + black + isort + pytest + pytest-cov + pytest-mock + pytest-benchmark + ]; + + src = fetchgit { + url = "https://github.com/akiomik/pilgram"; + rev = "ecef609b233b2f650dd82ca90d3c3d20148849c7"; + hash = "sha256-j8mqUwMZdyN7XdvJ141GTVyW9XtNN5bQFCOscM7NqbA="; + }; + + meta = { + description = ""; + homepage = "https://github.com/akiomik/pilgram"; + }; +} diff --git a/packages/python-packages/pixeloe/default.nix b/packages/python-packages/pixeloe/default.nix new file mode 100644 index 00000000..32ead2a2 --- /dev/null +++ b/packages/python-packages/pixeloe/default.nix @@ -0,0 +1,30 @@ +{ + buildPythonPackage, + fetchgit, + python312, + korniaWithCuda, +}: +buildPythonPackage { + pname = "pixeloe"; + version = "unstable"; + pyproject = true; + + buildInputs = with python312.pkgs; [ + numpy + opencv-python + pillow + korniaWithCuda + torchWithCuda + ]; + + src = fetchgit { + url = "https://github.com/KohakuBlueleaf/PixelOE"; + rev = "7a77ea53c573e8092a2b1808c0a56b2f4bad8f46"; + hash = "sha256-cnGyQFUrrtEI4YmsNSc4nAxh9wyq7/ouGe8TLF5fjJE="; + }; + + meta = { + description = ""; + homepage = "https://github.com/KohakuBlueleaf/PixelOE"; + }; +} diff --git a/packages/python-packages/segment-anything/default.nix b/packages/python-packages/segment-anything/default.nix new file mode 100644 index 00000000..e5e6d40f --- /dev/null +++ b/packages/python-packages/segment-anything/default.nix @@ -0,0 +1,28 @@ +{ + buildPythonPackage, + fetchgit, + python312, +}: +buildPythonPackage { + pname = "segment-anything"; + version = "unstable"; + + buildInputs = with python312.pkgs; [ + matplotlib + opencv-python-headless + pycocotools + onnxruntime + onnx + ]; + + src = fetchgit { + url = "https://github.com/facebookresearch/segment-anything"; + rev = "dca509fe793f601edb92606367a655c15ac00fdf"; + hash = "sha256-28XHhv/hffVIpbxJKU8wfPvDB63l93Z6r9j1vBOz/P0="; + }; + + meta = { + description = ""; + homepage = "https://github.com/facebookresearch/segment-anything"; + }; +} diff --git a/packages/python-packages/spandrel/default.nix b/packages/python-packages/spandrel/default.nix new file mode 100644 index 00000000..a04186bc --- /dev/null +++ b/packages/python-packages/spandrel/default.nix @@ -0,0 +1,38 @@ +{ + lib, + buildPythonPackage, + fetchPypi, + setuptools, + torchWithCuda, + torchvisionWithCuda, + safetensorsWithCuda, + einops, +}: +buildPythonPackage rec { + pname = "spandrel"; + version = "0.4.1"; + pyproject = true; + + buildInputs = [ + torchWithCuda + torchvisionWithCuda + safetensorsWithCuda + einops + setuptools + ]; + + src = fetchPypi { + inherit pname version; + hash = "sha256-ZG2YFqlC5Z1WqrLckENTlS5X3uSyyz9Z9+pNwPsRofI="; + }; + + pythonImportsCheck = [ "spandrel" ]; + + meta = { + description = "library for loading and running pre-trained PyTorch models"; + homepage = "https://github.com/chaiNNer-org/spandrel/"; + changelog = "https://github.com/chaiNNer-org/spandrel/releases/tag/v${version}"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ scd31 ]; + }; +} diff --git a/packages/python-packages/transparent-background/default.nix b/packages/python-packages/transparent-background/default.nix new file mode 100644 index 00000000..66845e8e --- /dev/null +++ b/packages/python-packages/transparent-background/default.nix @@ -0,0 +1,33 @@ +{ + buildPythonPackage, + fetchgit, + python312, +}: +buildPythonPackage { + pname = "transparent-background"; + version = "unstable"; + + buildInputs = with python312.pkgs; [ + numpy + opencv-python-headless + pillow + ]; + + preBuild = '' + export HOME=$TMPDIR + ''; + preInstall = '' + ls $HOME + ''; + + src = fetchgit { + url = "https://github.com/plemeri/transparent-background"; + rev = "60c6bc4b3d326d592f6e99568a5fdc5a28d9d791"; + hash = "sha256-MSvq7WX9gb9+UmvAh654OMXcCZIVrErL/rKtmjXnT0U="; + }; + + meta = { + description = ""; + homepage = "https://github.com/plemeri/transparent-background"; + }; +}