dotfiles/modules/nixos/services/comfyui/default.nix

100 lines
2.4 KiB
Nix
Raw Normal View History

2025-07-18 14:57:37 -05:00
{
2025-07-19 19:06:11 -05:00
config,
lib,
pkgs,
2025-07-19 19:11:24 -05:00
flake,
2025-07-19 19:06:11 -05:00
...
}:
let
2025-07-19 19:11:24 -05:00
inherit (flake.config.people) user0;
2025-07-19 19:06:11 -05:00
cfg = config.services.comfyui;
in
{
imports = [ ];
options = {
services.comfyui = with lib; {
enable = mkEnableOption "ComfyUI service";
package = mkOption {
type = types.package;
2025-08-03 21:31:58 -05:00
default = pkgs.comfyuiPackages.comfyui;
2025-07-19 19:06:11 -05:00
description = "The ComfyUI package to use";
};
2025-08-03 21:31:58 -05:00
# mkOption {
# type = types.package;
# default = pkgs.comfyuiPackages.comfyui.override {
# extensions = with pkgs.comfyuiPackages.extensions; [
# # Add desired extensions here
# # Example extensions:
# # acly-inpaint
# # acly-tooling
# # cubiq-ipadapter-plus
# # fannovel16-controlnet-aux
# ];
# commandLineArgs = [
# "--preview-method"
# "auto"
# ];
# };
# description = "The ComfyUI package to use";
# };
2025-07-19 19:06:11 -05:00
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";
2025-08-03 21:46:53 -05:00
ExecStartPre = [
"${pkgs.coreutils}/bin/mkdir -p /var/lib/comfyui/custom_nodes"
"${pkgs.coreutils}/bin/chown comfyui:comfyui /var/lib/comfyui/custom_nodes"
];
2025-07-19 19:06:11 -05:00
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;
2025-07-18 16:56:51 -05:00
};
2025-07-19 19:06:11 -05:00
users.groups.comfyui = { };
2025-07-18 16:56:51 -05:00
};
2025-07-18 14:57:37 -05:00
}