diff --git a/nixos/modules/services/misc/comfyui.nix b/nixos/modules/services/misc/comfyui.nix index fd9d507eae1a..b7ecede1abd4 100644 --- a/nixos/modules/services/misc/comfyui.nix +++ b/nixos/modules/services/misc/comfyui.nix @@ -10,6 +10,10 @@ let # By default a StateDirectory is used; anything else needs its own directory and a hole in the unit's mount namespace. isDefaultDataDir = cfg.dataDir == "/var/lib/comfyui"; + package = cfg.package.override (oldArgs: { + extraPackages = ps: (oldArgs.extraPackages or (_: [ ]) ps) ++ cfg.extraPackages ps; + }); + modelDrvs = map (m: { inherit m; drv = pkgs.fetchurl (lib.filterAttrs (n: _: n == "name" || n == "url" || n == "hash") m); @@ -43,6 +47,14 @@ in ''; }; + finalPackage = lib.mkOption { + type = lib.types.package; + internal = true; + readOnly = true; + default = package; + description = "The final ComfyUI package which is being used in the service."; + }; + listen = lib.mkOption { type = with lib.types; listOf str; default = [ @@ -138,6 +150,21 @@ in Files placed manually in the `models` directory are left untouched. ''; }; + + extraPackages = lib.mkOption { + type = lib.types.functionTo (lib.types.listOf lib.types.package); + default = _: [ ]; + defaultText = lib.literalExpression "ps: with ps; [ ]"; + example = lib.literalExpression '' + ps: with ps; [ comfyui-manager ] + ''; + description = '' + List of packages to add to ComfyUI's Python environment. + + A popular example is `python3Packages.comfyui-manager` for installing and + managing custom nodes from within ComfyUI. + ''; + }; }; }; @@ -166,7 +193,7 @@ in preStart = '' for d in custom_nodes input output models; do if [[ ! -d "${cfg.dataDir}/$d" ]]; then - cp --no-preserve=all -r ${cfg.package}/share/comfyui/$d "${cfg.dataDir}/" + cp --no-preserve=all -r ${cfg.finalPackage}/share/comfyui/$d "${cfg.dataDir}/" fi done @@ -183,7 +210,7 @@ in ''; serviceConfig = { - ExecStart = "${lib.getExe cfg.package} ${lib.escapeShellArgs cfg.extraArgs}"; + ExecStart = "${lib.getExe cfg.finalPackage} ${lib.escapeShellArgs cfg.extraArgs}"; Group = "comfyui"; Restart = "always"; RestartSec = "5sec"; # don't crash loop immediately diff --git a/pkgs/by-name/co/comfyui/package.nix b/pkgs/by-name/co/comfyui/package.nix index b67123660b0e..b93e12f057d9 100644 --- a/pkgs/by-name/co/comfyui/package.nix +++ b/pkgs/by-name/co/comfyui/package.nix @@ -1,8 +1,8 @@ { lib, - callPackage, common-updater-scripts, cudaPackages, + extraPackages ? (ps: [ ]), fetchFromGitHub, gnutar, gzip, @@ -10,7 +10,6 @@ makeBinaryWrapper, python3, stdenvNoCC, - withManager ? false, writeShellApplication, yq-go, }: @@ -59,9 +58,7 @@ let transformers yarl ] - ++ lib.optionals withManager [ - ps.comfyui-manager - ]; + ++ extraPackages ps; pythonEnv = python.withPackages appDependencies; in @@ -152,11 +149,6 @@ stdenvNoCC.mkDerivation (finalAttrs: { done < "$src/requirements.txt" ''; }); - } - // lib.optionalAttrs (!withManager) { - tests.withManager = callPackage ./package.nix { - withManager = true; - }; }; meta = { @@ -167,6 +159,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { mainProgram = "comfyui"; maintainers = with lib.maintainers; [ caniko + knightfemale SuperSandro2000 ]; platforms = lib.platforms.linux ++ lib.platforms.darwin;