feat: added comfyui

This commit is contained in:
Nick 2025-11-16 03:53:16 -06:00
parent ae3e0126d7
commit 2e9f5e5260
7 changed files with 391 additions and 219 deletions

170
flake.lock generated
View file

@ -125,6 +125,28 @@
"type": "github" "type": "github"
} }
}, },
"filesorter": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": [
"nixpkgs"
],
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1759453916,
"narHash": "sha256-Bl2flsWHfKPtbj6N/xNHrRNhWv8jxOuKBEzBoLplI3M=",
"ref": "refs/heads/main",
"rev": "079b099b8f3e35df796bdc89e65e5971aa235a43",
"revCount": 24,
"type": "git",
"url": "ssh://git@gitlab.com/uprootnutrition/filesorter.git"
},
"original": {
"type": "git",
"url": "ssh://git@gitlab.com/uprootnutrition/filesorter.git"
}
},
"flake-compat": { "flake-compat": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -188,6 +210,24 @@
} }
}, },
"flake-parts": { "flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1759362264,
"narHash": "sha256-wfG0S7pltlYyZTM+qqlhJ7GMw2fTF4mLKCIVhLii/4M=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "758cf7296bee11f1706a574c77d072b8a7baa881",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-parts_2": {
"inputs": { "inputs": {
"nixpkgs-lib": [ "nixpkgs-lib": [
"nixpkgs" "nixpkgs"
@ -207,9 +247,9 @@
"type": "github" "type": "github"
} }
}, },
"flake-parts_2": { "flake-parts_3": {
"inputs": { "inputs": {
"nixpkgs-lib": "nixpkgs-lib" "nixpkgs-lib": "nixpkgs-lib_2"
}, },
"locked": { "locked": {
"lastModified": 1756770412, "lastModified": 1756770412,
@ -225,9 +265,9 @@
"type": "github" "type": "github"
} }
}, },
"flake-parts_3": { "flake-parts_4": {
"inputs": { "inputs": {
"nixpkgs-lib": "nixpkgs-lib_2" "nixpkgs-lib": "nixpkgs-lib_3"
}, },
"locked": { "locked": {
"lastModified": 1754091436, "lastModified": 1754091436,
@ -243,7 +283,7 @@
"type": "github" "type": "github"
} }
}, },
"flake-parts_4": { "flake-parts_5": {
"inputs": { "inputs": {
"nixpkgs-lib": [ "nixpkgs-lib": [
"nur", "nur",
@ -264,9 +304,9 @@
"type": "github" "type": "github"
} }
}, },
"flake-parts_5": { "flake-parts_6": {
"inputs": { "inputs": {
"nixpkgs-lib": "nixpkgs-lib_3" "nixpkgs-lib": "nixpkgs-lib_4"
}, },
"locked": { "locked": {
"lastModified": 1759362264, "lastModified": 1759362264,
@ -282,9 +322,9 @@
"type": "github" "type": "github"
} }
}, },
"flake-parts_6": { "flake-parts_7": {
"inputs": { "inputs": {
"nixpkgs-lib": "nixpkgs-lib_4" "nixpkgs-lib": "nixpkgs-lib_5"
}, },
"locked": { "locked": {
"lastModified": 1759362264, "lastModified": 1759362264,
@ -821,11 +861,11 @@
}, },
"linkpage": { "linkpage": {
"inputs": { "inputs": {
"flake-parts": "flake-parts_2", "flake-parts": "flake-parts_3",
"mkElmDerivation": "mkElmDerivation", "mkElmDerivation": "mkElmDerivation",
"nixpkgs": "nixpkgs_2", "nixpkgs": "nixpkgs_3",
"nixpkgs-stable": "nixpkgs-stable", "nixpkgs-stable": "nixpkgs-stable",
"treefmt-nix": "treefmt-nix" "treefmt-nix": "treefmt-nix_2"
}, },
"locked": { "locked": {
"lastModified": 1762929110, "lastModified": 1762929110,
@ -904,7 +944,7 @@
"inputs": { "inputs": {
"elm-spa": "elm-spa", "elm-spa": "elm-spa",
"elm-watch": "elm-watch", "elm-watch": "elm-watch",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1762652710, "lastModified": 1762652710,
@ -924,7 +964,7 @@
"inputs": { "inputs": {
"elm-spa": "elm-spa_2", "elm-spa": "elm-spa_2",
"elm-watch": "elm-watch_2", "elm-watch": "elm-watch_2",
"nixpkgs": "nixpkgs_5" "nixpkgs": "nixpkgs_6"
}, },
"locked": { "locked": {
"lastModified": 1759023814, "lastModified": 1759023814,
@ -1001,7 +1041,7 @@
"nixcord": { "nixcord": {
"inputs": { "inputs": {
"flake-compat": "flake-compat_2", "flake-compat": "flake-compat_2",
"flake-parts": "flake-parts_3", "flake-parts": "flake-parts_4",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
] ]
@ -1022,11 +1062,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1696757521, "lastModified": 1754340878,
"narHash": "sha256-cfgtLNCBLFx2qOzRLI6DHfqTdfWI+UbvsKYa3b3fvaA=", "narHash": "sha256-lgmUyVQL9tSnvvIvBp7x1euhkkCho7n3TMzgjdvgPoU=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "2646b294a146df2781b1ca49092450e8a32814e1", "rev": "cab778239e705082fe97bb4990e0d24c50924c04",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -1052,6 +1092,21 @@
} }
}, },
"nixpkgs-lib_2": { "nixpkgs-lib_2": {
"locked": {
"lastModified": 1754788789,
"narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "a73b9c743612e4244d865a2fdee11865283c04e6",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs-lib_3": {
"locked": { "locked": {
"lastModified": 1753579242, "lastModified": 1753579242,
"narHash": "sha256-zvaMGVn14/Zz8hnp4VWT9xVnhc8vuL3TStRqwk22biA=", "narHash": "sha256-zvaMGVn14/Zz8hnp4VWT9xVnhc8vuL3TStRqwk22biA=",
@ -1066,7 +1121,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-lib_3": { "nixpkgs-lib_4": {
"locked": { "locked": {
"lastModified": 1754788789, "lastModified": 1754788789,
"narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=", "narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=",
@ -1081,7 +1136,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-lib_4": { "nixpkgs-lib_5": {
"locked": { "locked": {
"lastModified": 1754788789, "lastModified": 1754788789,
"narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=", "narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=",
@ -1161,6 +1216,22 @@
} }
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": {
"lastModified": 1696757521,
"narHash": "sha256-cfgtLNCBLFx2qOzRLI6DHfqTdfWI+UbvsKYa3b3fvaA=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "2646b294a146df2781b1ca49092450e8a32814e1",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": { "locked": {
"lastModified": 1758690382, "lastModified": 1758690382,
"narHash": "sha256-NY3kSorgqE5LMm1LqNwGne3ZLMF2/ILgLpFr1fS4X3o=", "narHash": "sha256-NY3kSorgqE5LMm1LqNwGne3ZLMF2/ILgLpFr1fS4X3o=",
@ -1176,7 +1247,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_3": { "nixpkgs_4": {
"locked": { "locked": {
"lastModified": 1754340878, "lastModified": 1754340878,
"narHash": "sha256-lgmUyVQL9tSnvvIvBp7x1euhkkCho7n3TMzgjdvgPoU=", "narHash": "sha256-lgmUyVQL9tSnvvIvBp7x1euhkkCho7n3TMzgjdvgPoU=",
@ -1192,7 +1263,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_4": { "nixpkgs_5": {
"locked": { "locked": {
"lastModified": 1761907660, "lastModified": 1761907660,
"narHash": "sha256-kJ8lIZsiPOmbkJypG+B5sReDXSD1KGu2VEPNqhRa/ew=", "narHash": "sha256-kJ8lIZsiPOmbkJypG+B5sReDXSD1KGu2VEPNqhRa/ew=",
@ -1208,7 +1279,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_5": { "nixpkgs_6": {
"locked": { "locked": {
"lastModified": 1696757521, "lastModified": 1696757521,
"narHash": "sha256-cfgtLNCBLFx2qOzRLI6DHfqTdfWI+UbvsKYa3b3fvaA=", "narHash": "sha256-cfgtLNCBLFx2qOzRLI6DHfqTdfWI+UbvsKYa3b3fvaA=",
@ -1224,7 +1295,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_6": { "nixpkgs_7": {
"locked": { "locked": {
"lastModified": 1759036355, "lastModified": 1759036355,
"narHash": "sha256-0m27AKv6ka+q270dw48KflE0LwQYrO7Fm4/2//KCVWg=", "narHash": "sha256-0m27AKv6ka+q270dw48KflE0LwQYrO7Fm4/2//KCVWg=",
@ -1240,7 +1311,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_7": { "nixpkgs_8": {
"locked": { "locked": {
"lastModified": 1754340878, "lastModified": 1754340878,
"narHash": "sha256-lgmUyVQL9tSnvvIvBp7x1euhkkCho7n3TMzgjdvgPoU=", "narHash": "sha256-lgmUyVQL9tSnvvIvBp7x1euhkkCho7n3TMzgjdvgPoU=",
@ -1256,7 +1327,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_8": { "nixpkgs_9": {
"locked": { "locked": {
"lastModified": 1754340878, "lastModified": 1754340878,
"narHash": "sha256-lgmUyVQL9tSnvvIvBp7x1euhkkCho7n3TMzgjdvgPoU=", "narHash": "sha256-lgmUyVQL9tSnvvIvBp7x1euhkkCho7n3TMzgjdvgPoU=",
@ -1352,7 +1423,7 @@
}, },
"nur": { "nur": {
"inputs": { "inputs": {
"flake-parts": "flake-parts_4", "flake-parts": "flake-parts_5",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
] ]
@ -1441,7 +1512,8 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-parts": "flake-parts", "filesorter": "filesorter",
"flake-parts": "flake-parts_2",
"home-manager": "home-manager", "home-manager": "home-manager",
"hyprland": "hyprland", "hyprland": "hyprland",
"hyprland-portal": "hyprland-portal", "hyprland-portal": "hyprland-portal",
@ -1452,14 +1524,14 @@
"microvm": "microvm", "microvm": "microvm",
"niri": "niri", "niri": "niri",
"nixcord": "nixcord", "nixcord": "nixcord",
"nixpkgs": "nixpkgs_4", "nixpkgs": "nixpkgs_5",
"nixpkgs-stable": "nixpkgs-stable_3", "nixpkgs-stable": "nixpkgs-stable_3",
"nur": "nur", "nur": "nur",
"plasma-manager": "plasma-manager", "plasma-manager": "plasma-manager",
"pre-commit-hooks-nix": "pre-commit-hooks-nix", "pre-commit-hooks-nix": "pre-commit-hooks-nix",
"sops-nix": "sops-nix", "sops-nix": "sops-nix",
"systems": "systems_5", "systems": "systems_5",
"treefmt-nix": "treefmt-nix_2", "treefmt-nix": "treefmt-nix_3",
"upRootNutrition": "upRootNutrition", "upRootNutrition": "upRootNutrition",
"waybar": "waybar", "waybar": "waybar",
"wpaperd": "wpaperd", "wpaperd": "wpaperd",
@ -1615,7 +1687,7 @@
}, },
"treefmt-nix": { "treefmt-nix": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs_3" "nixpkgs": "nixpkgs"
}, },
"locked": { "locked": {
"lastModified": 1758728421, "lastModified": 1758728421,
@ -1632,6 +1704,24 @@
} }
}, },
"treefmt-nix_2": { "treefmt-nix_2": {
"inputs": {
"nixpkgs": "nixpkgs_4"
},
"locked": {
"lastModified": 1758728421,
"narHash": "sha256-ySNJ008muQAds2JemiyrWYbwbG+V7S5wg3ZVKGHSFu8=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "5eda4ee8121f97b218f7cc73f5172098d458f1d1",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
},
"treefmt-nix_3": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
@ -1651,9 +1741,9 @@
"type": "github" "type": "github"
} }
}, },
"treefmt-nix_3": { "treefmt-nix_4": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs_7" "nixpkgs": "nixpkgs_8"
}, },
"locked": { "locked": {
"lastModified": 1758728421, "lastModified": 1758728421,
@ -1669,9 +1759,9 @@
"type": "github" "type": "github"
} }
}, },
"treefmt-nix_4": { "treefmt-nix_5": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs_8" "nixpkgs": "nixpkgs_9"
}, },
"locked": { "locked": {
"lastModified": 1760120816, "lastModified": 1760120816,
@ -1689,11 +1779,11 @@
}, },
"upRootNutrition": { "upRootNutrition": {
"inputs": { "inputs": {
"flake-parts": "flake-parts_5", "flake-parts": "flake-parts_6",
"mkElmDerivation": "mkElmDerivation_2", "mkElmDerivation": "mkElmDerivation_2",
"nixpkgs": "nixpkgs_6", "nixpkgs": "nixpkgs_7",
"nixpkgs-stable": "nixpkgs-stable_4", "nixpkgs-stable": "nixpkgs-stable_4",
"treefmt-nix": "treefmt-nix_3" "treefmt-nix": "treefmt-nix_4"
}, },
"locked": { "locked": {
"lastModified": 1761538643, "lastModified": 1761538643,
@ -1828,11 +1918,11 @@
}, },
"zookeeper": { "zookeeper": {
"inputs": { "inputs": {
"flake-parts": "flake-parts_6", "flake-parts": "flake-parts_7",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
], ],
"treefmt-nix": "treefmt-nix_4" "treefmt-nix": "treefmt-nix_5"
}, },
"locked": { "locked": {
"lastModified": 1763275059, "lastModified": 1763275059,

View file

@ -78,10 +78,10 @@
linkpage = { linkpage = {
url = "git+ssh://git@gitlab.com/uprootnutrition/linkpage.git"; url = "git+ssh://git@gitlab.com/uprootnutrition/linkpage.git";
}; };
# filesorter = { filesorter = {
# url = "git+ssh://git@gitlab.com/uprootnutrition/filesorter.git"; url = "git+ssh://git@gitlab.com/uprootnutrition/filesorter.git";
# inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
# }; };
zookeeper = { zookeeper = {
url = "git+ssh://git@gitlab.com/uprootnutrition/zookeeper.git"; url = "git+ssh://git@gitlab.com/uprootnutrition/zookeeper.git";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -146,7 +146,6 @@
config.nixosModules.ceres config.nixosModules.ceres
config.nixosModules.core config.nixosModules.core
config.nixosModules.mantle config.nixosModules.mantle
# inputs.filesorter.nixosModules.default
inputs.home-manager.nixosModules.home-manager inputs.home-manager.nixosModules.home-manager
inputs.impermanence.nixosModules.impermanence inputs.impermanence.nixosModules.impermanence
# inputs.lix-module.nixosModules.default # inputs.lix-module.nixosModules.default

View file

@ -1,41 +1,38 @@
{ moduleFunctions }: { moduleFunctions }:
let let
inherit (moduleFunctions.instancesFunctions) inherit (moduleFunctions.instancesFunctions)
domain0 varPath
servicePath mntPath
sslPath
sopsPath
; ;
label = "ComfyUI"; label = "ComfyUI";
name = "comfyui"; name = "comfyui";
subdomain = "comfyui";
domain = "${subdomain}.${domain0}";
in in
{ {
label = label; label = label;
name = name; name = name;
short = label; short = label;
sops = {
path0 = "${sopsPath}/${name}";
};
domains = {
url0 = domain;
};
subdomain = subdomain;
tags = [ tags = [
name name
"comfy" "comfy"
"ui" "ui"
]; ];
paths = {
path0 = "${servicePath}/${label}";
};
ports = { ports = {
port0 = 8188; port0 = 8188;
}; };
ssl = { interface = {
cert = "${sslPath}/${domain}/fullchain.pem"; id = "vm-comfy";
key = "${sslPath}/${domain}/key.pem"; mac = "02:00:00:00:54:24";
idUser = "vmuser-comfy";
macUser = "02:00:00:00:00:24";
ip = "192.168.50.214";
gate = "192.168.50.1";
ssh = 2304;
}; };
varPaths = {
path0 = "${varPath}/${name}";
};
mntPaths = {
path0 = "${mntPath}/${name}";
};
} }

View file

@ -51,7 +51,7 @@ in
acme acme
# audiobookshelf # audiobookshelf
caddy caddy
# comfyui comfyui
# filesorter # filesorter
# firefly-iii # firefly-iii
forgejo forgejo

View file

@ -0,0 +1,239 @@
{
flake,
...
}:
let
inherit (flake.config.people) user0;
inherit (flake.config.services) instances;
serviceCfg = instances.comfyui;
hostCfg = instances.web;
in
{
microvm.vms = {
${serviceCfg.name} = {
autostart = true;
restartIfChanged = true;
config = {
system.stateVersion = "24.05";
time.timeZone = "America/Winnipeg";
users.users.root.openssh.authorizedKeys.keys = flake.config.people.users.${user0}.sshKeys;
imports = [
flake.inputs.filesorter.nixosModules.default
];
services = {
filesorter.enable = true;
caddy = {
enable = true;
virtualHosts = {
":80" = {
extraConfig = ''
# Main reverse proxy with WebSocket support
reverse_proxy ${hostCfg.localhost.address1}:${toString serviceCfg.ports.port0} {
header_up Host {host}
header_up X-Real-IP {remote}
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Proto {scheme}
# WebSocket support - critical for ComfyUI real-time updates
header_up Connection {>Connection}
header_up Upgrade {>Upgrade}
# Longer timeouts for generation tasks
transport http {
read_timeout 300s
write_timeout 300s
}
}
# Security headers
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
X-Frame-Options "DENY"
X-Content-Type-Options "nosniff"
X-XSS-Protection "1; mode=block"
Referrer-Policy "strict-origin-when-cross-origin"
-Server
}
# Logging
log {
output file /var/log/caddy/comfyui-access.log
format json
}
'';
};
};
};
openssh = {
enable = true;
settings = {
PasswordAuthentication = false;
PermitRootLogin = "prohibit-password";
};
};
};
virtualisation = {
docker = {
enable = true;
autoPrune = {
enable = true;
dates = "weekly";
};
};
oci-containers = {
backend = "docker";
containers.comfyui = {
image = "yanwk/comfyui-boot:cu126-slim";
autoStart = true;
ports = [
"${hostCfg.localhost.address1}:${builtins.toString serviceCfg.ports.port0}:8188"
];
volumes = [
"${serviceCfg.varPaths.path0}:/root"
"${serviceCfg.varPaths.path0}/models:/root/models"
"${serviceCfg.varPaths.path0}/custom_nodes:/root/custom_nodes"
"${serviceCfg.varPaths.path0}/output:/root/output"
"${serviceCfg.varPaths.path0}/input:/root/input"
"${serviceCfg.varPaths.path0}/user:/root/user"
# Mount the device nodes into the container
"/dev/nvidia0:/dev/nvidia0"
"/dev/nvidiactl:/dev/nvidiactl"
"/dev/nvidia-uvm:/dev/nvidia-uvm"
"/dev/nvidia-modeset:/dev/nvidia-modeset"
];
environment = {
CLI_ARGS = "--listen 0.0.0.0 --port 8188 --preview-method auto --dont-print-server";
NVIDIA_VISIBLE_DEVICES = "all";
NVIDIA_DRIVER_CAPABILITIES = "compute,utility,graphics";
};
extraOptions = [
"--privileged"
"--device=/dev/nvidia0"
"--device=/dev/nvidiactl"
"--device=/dev/nvidia-uvm"
"--device=/dev/nvidia-modeset"
"--memory=32g"
"--memory-swap=32g"
"--shm-size=16g"
"--security-opt=no-new-privileges:true"
"--network=bridge"
"--health-cmd=curl -f http://localhost:8188/ || exit 1"
"--health-interval=30s"
"--health-timeout=10s"
"--health-retries=3"
];
};
};
};
users.users.caddy.extraGroups = [ serviceCfg.name ];
networking.firewall.allowedTCPPorts = [
22
80
];
systemd = {
services.docker-comfyui = {
after = [
"network-online.target"
"docker.service"
];
wants = [ "network-online.target" ];
requires = [ "docker.service" ];
};
network = {
enable = true;
networks."20-lan" = {
matchConfig.Name = "enp0s5";
addresses = [ { Address = "${serviceCfg.interface.ip}/24"; } ];
routes = [
{
Destination = "${hostCfg.localhost.address1}/0";
Gateway = serviceCfg.interface.gate;
}
];
dns = [
"1.1.1.1"
"8.8.8.8"
];
};
};
tmpfiles.rules = [
"Z ${serviceCfg.varPaths.path0} 0755 ${serviceCfg.name} ${serviceCfg.name} -"
"d /var/lib/docker/tmp/ 755 docker docker -"
"d /var/log/caddy 755 caddy caddy -"
];
};
boot.kernel.sysctl = {
"kernel.shmmax" = 68719476736;
"kernel.shmall" = 4194304;
"vm.swappiness" = 1;
"vm.dirty_ratio" = 15;
"vm.dirty_background_ratio" = 5;
};
microvm = {
vcpu = 6;
mem = 8192;
hypervisor = "qemu";
interfaces = [
{
type = "tap";
id = serviceCfg.interface.id;
mac = serviceCfg.interface.mac;
}
{
type = "user";
id = serviceCfg.interface.idUser;
mac = serviceCfg.interface.macUser;
}
];
forwardPorts = [
{
from = "host";
host.port = serviceCfg.interface.ssh;
guest.port = 22;
}
];
shares = [
{
mountPoint = "/nix/.ro-store";
proto = "virtiofs";
source = "/nix/store";
tag = "read_only_nix_store";
}
{
mountPoint = "/var/lib/${serviceCfg.name}";
proto = "virtiofs";
source = "${serviceCfg.mntPaths.path0}/data";
tag = "${serviceCfg.name}_data";
}
{
mountPoint = "/var/lib/docker";
proto = "virtiofs";
source = "${serviceCfg.mntPaths.path0}/docker"; # Store on host
tag = "docker_data";
}
];
};
};
};
};
systemd.tmpfiles.rules = [
"d ${serviceCfg.mntPaths.path0}/data 0751 microvm wheel - -"
"d ${serviceCfg.mntPaths.path0}/docker 0751 microvm wheel - -"
];
}

View file

@ -1,148 +0,0 @@
{
config,
pkgs,
flake,
...
}:
let
inherit (flake.config.services.instances) comfyui web;
service = comfyui;
localhost = web.localhost.address1;
host = service.domains.url0;
in
{
# Enable Docker (nvidia-container-toolkit will auto-enable via graphics.nix)
virtualisation.docker = {
enable = true;
enableNvidia = true;
autoPrune = {
enable = true;
dates = "weekly";
};
};
# hardware.nvidia-container-toolkit.enable = true;
# Create ComfyUI Docker container
virtualisation.oci-containers = {
backend = "docker";
containers.comfyui = {
image = "yanwk/comfyui-boot:cu126-slim";
autoStart = true;
ports = [
"${localhost}:${toString service.ports.port0}:8188"
];
volumes = [
# Main data directory
"${service.paths.path0}:/root"
# Specific subdirectories for better control
"${service.paths.path0}/models:/root/models"
"${service.paths.path0}/custom_nodes:/root/custom_nodes"
"${service.paths.path0}/output:/root/output"
"${service.paths.path0}/input:/root/input"
"${service.paths.path0}/user:/root/user"
];
environment = {
CLI_ARGS = "--listen 0.0.0.0 --port 8188 --preview-method auto --dont-print-server";
NVIDIA_VISIBLE_DEVICES = "0";
NVIDIA_DRIVER_CAPABILITIES = "compute,utility,graphics";
};
extraOptions = [
"--runtime=nvidia"
"--gpus=device=0"
# Memory limits to prevent OOM
"--memory=32g"
"--memory-swap=32g"
"--shm-size=16g"
# Security
"--security-opt=no-new-privileges:true"
# Network
"--network=bridge"
# Health check
"--health-cmd=curl -f http://localhost:8188/ || exit 1"
"--health-interval=30s"
"--health-timeout=10s"
"--health-retries=3"
];
};
};
# Caddy reverse proxy with WebSocket support
services.caddy = {
virtualHosts = {
"${host}" = {
extraConfig = ''
basicauth {
{$CADDY_AUTH_USER} {$CADDY_AUTH_PASSWORD_HASH}
}
# Main reverse proxy with WebSocket support
reverse_proxy ${localhost}:${toString service.ports.port0} {
header_up Host {host}
header_up X-Real-IP {remote}
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Proto {scheme}
# WebSocket support - critical for ComfyUI real-time updates
header_up Connection {>Connection}
header_up Upgrade {>Upgrade}
# Longer timeouts for generation tasks
transport http {
read_timeout 300s
write_timeout 300s
}
}
tls ${service.ssl.cert} ${service.ssl.key}
# Security headers
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
X-Frame-Options "DENY"
X-Content-Type-Options "nosniff"
X-XSS-Protection "1; mode=block"
Referrer-Policy "strict-origin-when-cross-origin"
-Server
}
# Logging
log {
output file /var/log/caddy/comfyui-access.log
format json
}
'';
};
};
};
# Setup directories with proper permissions
systemd.tmpfiles.rules = [
"d ${service.paths.path0} 755 root root -"
"Z ${service.sops.path0} 755 caddy caddy -"
"d /var/log/caddy 755 caddy caddy -"
];
# Kernel tuning for AI workloads
boot.kernel.sysctl = {
"kernel.shmmax" = 68719476736;
"kernel.shmall" = 4194304;
"vm.swappiness" = 1;
"vm.dirty_ratio" = 15;
"vm.dirty_background_ratio" = 5;
};
# Ensure Docker service waits for network
systemd.services.docker-comfyui = {
after = [
"network-online.target"
"docker.service"
];
wants = [ "network-online.target" ];
requires = [ "docker.service" ];
};
}

View file

@ -1,5 +0,0 @@
{
services.filesorter = {
enable = true;
};
}