Generative AI using ComfyUI on Nixos
NixOS is notoriously difficult to get AI applications running on. So naturally, I had to try it with ComfyUI, a very popular UI for generative AI models. It took a bit of trial and error, but in the end I got it working.
Installation
I used the following shell.nix
file to get everything set up:
{ pkgs ? import <nixpkgs> {} }: let
deps = with pkgs; [
fish # not strictly necessary, but I like it
(python313.withPackages(p: with p; [
pip
]))
];
libs = with pkgs; [
stdenv.cc.cc.lib
zstd
];
in pkgs.mkShell {
buildInputs = deps;
env.LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath libs;
}
To explain briefly, this file sets up a Nix shell with Python 3.13 and Fish shell (technically unneeded, but I like it for when I'm working interactively). It also includes the necessary libraries for ComfyUI to run. I may have gotten lucky here, but it seems to work without any additional dependencies.
After creating the shell.nix
file, and entering the shell with nix-shell
, I cloned the ComfyUI repository and set up a virtual environment.
This creates a virtual environment in the .venv
directory and activates it. The idea is to keep the Python dependencies isolated from the system Python. But also allow python to manage the dependencies itself. Because Nix seems to interefere with various assumptions made by Python packages. This mostly circumvents that.
Next, I simply followed the instructions in the ComfyUI repository to install the required Python packages.
Running
And last but not least, I could finally run ComfyUI. Using python main.py
. It readily started up, and I could access the web interface at http://localhost:8188
.
I then proceeded to download some models and load them into ComfyUI. Everything worked as expected, and I was able to generate images without any issues. Next step is to try out some of the more advanced features, like using custom nodes and scripts. As well as trying to get other AI applications running on NixOS.
Images
Here are some of the images I generated using ComfyUI on NixOS. I used Flux Schnell FP8 with 5 steps.