From 17fb1042ae450e0f41401f74649efe4f274b1ac2 Mon Sep 17 00:00:00 2001 From: x807x Date: Sat, 15 Mar 2025 13:03:16 +0800 Subject: [PATCH 1/2] add nix support with flake --- flake.lock | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 37 +++++++++++++++++++++++++++++ requirements.txt | 2 +- 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..3975be343 --- /dev/null +++ b/flake.lock @@ -0,0 +1,62 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1741708242, + "narHash": "sha256-cNRqdQD4sZpN7JLqxVOze4+WsWTmv2DGH0wNCOVwrWc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b62d2a95c72fb068aecd374a7262b37ed92df82b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1741513245, + "narHash": "sha256-7rTAMNTY1xoBwz0h7ZMtEcd8LELk9R5TzBPoHuhNSCk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e3e32b642a31e6714ec1b712de8c91a3352ce7e1", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pyproject-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1741648141, + "narHash": "sha256-jQEZCSCgm60NGmBg3JPu290DDhNVI1GVVEd0P8VCnME=", + "owner": "pyproject-nix", + "repo": "pyproject.nix", + "rev": "7747e5a058245c7abe033a798f818f0572d8e155", + "type": "github" + }, + "original": { + "owner": "pyproject-nix", + "repo": "pyproject.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "pyproject-nix": "pyproject-nix" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..fb03e36ad --- /dev/null +++ b/flake.nix @@ -0,0 +1,37 @@ +{ + description = "ComfyUI with requirements.txt"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + pyproject-nix.url = "github:pyproject-nix/pyproject.nix"; + }; + + outputs = { + self, + nixpkgs, + pyproject-nix, + ... + } @ inputs: let + system = "x86_64-linux"; + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + config.cudaSupport = true; + }; + python = pkgs.python3; + project = pyproject-nix.lib.project.loadRequirementsTxt { + projectRoot = ./.; + }; + pythonEnv = assert project.validators.validateVersionConstraints {inherit python;} == {}; ( + pkgs.python3.withPackages (project.renderers.withPackages { + inherit python; + }) + ); + in { + formatter.${system} = nixpkgs.legacyPackages.${system}.alejandra; + devShells.${system}.default = pkgs.mkShell { + packages = [ + pythonEnv + ]; + }; + }; +} diff --git a/requirements.txt b/requirements.txt index afbcb7cba..77c1962e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,6 +18,6 @@ psutil #non essential dependencies: kornia>=0.7.1 -spandrel +# spandrel soundfile av From 216a81ab8abc025e3cfc47555d8122b0bac91fd0 Mon Sep 17 00:00:00 2001 From: x807x Date: Tue, 18 Mar 2025 17:14:39 +0800 Subject: [PATCH 2/2] fix missing comfyui-frontend-package & spandrel packages in nixpkgs --- flake.nix | 41 +++++++++++++++++++++++++++++++++++++++-- requirements.txt | 2 +- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index fb03e36ad..dcac07bbe 100644 --- a/flake.nix +++ b/flake.nix @@ -17,12 +17,48 @@ config.allowUnfree = true; config.cudaSupport = true; }; - python = pkgs.python3; + python = let + packageOverrides = self: super: + { + "comfyui-frontend-package" = super.buildPythonPackage + { + pname = "comfyui-frontend-package"; + version = "1.12.14"; + src = fetchTarball { + url = "https://files.pythonhosted.org/packages/cc/33/0ca463657227a7538b8b1d924840e4e25307f8c8d20c683439d7ea97ba6d/comfyui_frontend_package-1.12.14.tar.gz"; + sha256 = "1c5j01xqkzxqzj5nf646jrs7g095b0pzliy9b3b60wrspkaa2296"; + }; + propagatedBuildInputs = [ + super.setuptools + ]; + COMFYUI_FRONTEND_VERSION = "1.12.14"; + }; + "spandrel" = super.buildPythonPackage { + pname = "spandrel"; + pyproject = true; + version = "0.4.1"; + src = fetchTarball { + url = "https://files.pythonhosted.org/packages/45/e0/048cd03119a9f2b685a79601a52311d5910ff6fd710c01f4ed6769a2892f/spandrel-0.4.1.tar.gz"; + sha256 = "1byaq7mzjs27qhs9d7aw6xflqlj3qzm47mgawdxrlcw9qj4gk9w4"; + }; + buildInputs = [ + super.torch + super.torchvision + super.safetensors + super.einops + ]; + }; + }; + in + pkgs.python3.override { + inherit packageOverrides; + self = python; + }; project = pyproject-nix.lib.project.loadRequirementsTxt { projectRoot = ./.; }; pythonEnv = assert project.validators.validateVersionConstraints {inherit python;} == {}; ( - pkgs.python3.withPackages (project.renderers.withPackages { + python.withPackages (project.renderers.withPackages { inherit python; }) ); @@ -31,6 +67,7 @@ devShells.${system}.default = pkgs.mkShell { packages = [ pythonEnv + #(python.withPackages (ps: with ps; [ comfyui-frontend-package ])) ]; }; }; diff --git a/requirements.txt b/requirements.txt index 493b3830a..70689bc99 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,6 +19,6 @@ psutil #non essential dependencies: kornia>=0.7.1 -# spandrel +spandrel soundfile av