From 053429b0b8389a51d6c3ef2af437d50a453420bf Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 18 Jul 2025 16:56:51 -0500 Subject: [PATCH] feat: added comfy ui --- modules/nixos/services/comfyui/default.nix | 85 +++++++++++++++++++--- 1 file changed, 75 insertions(+), 10 deletions(-) diff --git a/modules/nixos/services/comfyui/default.nix b/modules/nixos/services/comfyui/default.nix index 2ca2d4d..cc8e7ca 100644 --- a/modules/nixos/services/comfyui/default.nix +++ b/modules/nixos/services/comfyui/default.nix @@ -1,17 +1,82 @@ { - flake, + config, + lib, + pkgs, ... }: + let - pkgs = import flake.inputs.nixpkgs { - system = "x86_64-linux"; - overlays = [ - flake.inputs.nix-comfyui.overlays.default - ]; - }; + cfg = config.services.comfyui; in { - environment.comfyuiPackages = [ - pkgs.comfyui - ]; + options.services.comfyui = with lib; { + enable = mkEnableOption "ComfyUI service"; + + package = mkOption { + type = types.package; + default = pkgs.comfyuiPackages.comfyui.override { + extensions = with pkgs.comfyuiPackages.extensions; [ + acly-inpaint + acly-tooling + cubiq-ipadapter-plus + fannovel16-controlnet-aux + ]; + commandLineArgs = [ + "--preview-method" + "auto" + ]; + }; + description = "The ComfyUI package to use"; + }; + + port = mkOption { + type = types.port; + default = 8188; + description = "Port to listen on"; + }; + + host = mkOption { + type = types.str; + default = "127.0.0.1"; + description = "Host to bind to"; + }; + + openFirewall = mkOption { + type = types.bool; + default = false; + description = "Open ports in the firewall"; + }; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = [ cfg.package ]; + + networking.firewall = lib.mkIf cfg.openFirewall { + allowedTCPPorts = [ cfg.port ]; + }; + + systemd.services.comfyui = { + description = "ComfyUI Service"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + serviceConfig = { + Type = "simple"; + ExecStart = "${cfg.package}/bin/comfyui --port ${toString cfg.port} --listen ${cfg.host}"; + Restart = "on-failure"; + User = "comfyui"; + Group = "comfyui"; + WorkingDirectory = "/var/lib/comfyui"; + }; + }; + + users.users.comfyui = { + group = "comfyui"; + isSystemUser = true; + home = "/var/lib/comfyui"; + createHome = true; + }; + + users.groups.comfyui = { }; + }; }