{ lib, stdenv, fetchFromGitHub, cmake, ninja, pkg-config, # C++ build-time dependencies curl, openssl, zlib, nlohmann_json, libwebsockets, cli11, # Linux system libraries (optional, enable richer features) systemd, libdrm, libcap, }: let # cpp-httplib is not yet in nixpkgs; pre-fetch for CMake FetchContent override. # The CMakeLists.txt version gate requires >= 0.26.0. cpp-httplib-src = fetchFromGitHub { owner = "yhirose"; repo = "cpp-httplib"; rev = "v0.26.0"; hash = "sha256-+VPebnFMGNyChM20q4Z+kVOyI/qDLQjRsaGS0vo8kDM="; }; in stdenv.mkDerivation rec { pname = "lemonade"; version = "10.0.1"; src = fetchFromGitHub { owner = "lemonade-sdk"; repo = "lemonade"; rev = "v${version}"; hash = "sha256-aswK7OXMWTFUNHrrktf1Vx3nvTkLWMEhAgWlil1Zu2c="; }; nativeBuildInputs = [ cmake ninja pkg-config ]; buildInputs = [ curl openssl zlib nlohmann_json libwebsockets cli11 systemd libdrm libcap ]; cmakeFlags = [ # Disable the web app (requires Node.js / npm at build time) "-DBUILD_WEB_APP=OFF" # Disable Linux tray app (requires GTK3 + AppIndicator3; optional) "-DREQUIRE_LINUX_TRAY=OFF" "-DCMAKE_BUILD_TYPE=Release" # Prevent FetchContent from reaching the network (sandbox-safe) "-DFETCHCONTENT_FULLY_DISCONNECTED=ON" # Provide pre-fetched sources for deps not in nixpkgs "-DFETCHCONTENT_SOURCE_DIR_HTTPLIB=${cpp-httplib-src}" ]; installPhase = '' runHook preInstall mkdir -p "$out/bin" # HTTP server — pure OpenAI-compatible REST API, no CLI interface install -Dm755 lemonade-router "$out/bin/lemonade-router" # Console CLI client — primary user-facing tool (serve, list, pull, run, # status, stop, logs, recipes, …); manages the lemonade-router process install -Dm755 lemonade-server "$out/bin/lemonade-server" # Standalone HTTP-only CLI client (newer, lightweight alternative to # lemonade-server for scripting; requires a running lemonade-router) if [ -f lemonade ]; then install -Dm755 lemonade "$out/bin/lemonade" fi # Resources: model registry (server_models.json), backend version config, # and static web UI assets served by lemonade-router. # # get_resource_path() in path_utils.cpp resolves files as: # /resources/ (first check, highest priority) # /usr/share/lemonade-server/resources/ (fallback) # # We install the real files under share/ and symlink bin/resources → # ../share/lemonade-server/resources so the first check succeeds regardless # of whether the Nix store path is in any of the hardcoded fallback prefixes. if [ -d resources ]; then mkdir -p "$out/share/lemonade-server/resources" cp -r resources/. "$out/share/lemonade-server/resources/" ln -s "$out/share/lemonade-server/resources" "$out/bin/resources" fi runHook postInstall ''; meta = with lib; { description = "Local LLM server that serves optimized LLMs from GPUs and NPUs"; longDescription = '' Lemonade helps users discover and run local AI apps by serving optimized LLMs, images, and speech directly from their own GPUs and NPUs. It exposes an OpenAI-compatible REST API at http://localhost:8000/api/v1 and bundles a web UI, model manager, and CLI client. Binaries: lemonade-router — HTTP server (OpenAI-compatible API on :8000) lemonade-server — CLI client: serve, list, pull, run, status, stop, … lemonade — standalone HTTP-only CLI for scripting Typical usage: lemonade-server serve # start the server (headless on Linux) lemonade-server list # browse available models lemonade-server pull Gemma-3-4b-it-GGUF lemonade-server run Gemma-3-4b-it-GGUF ''; homepage = "https://lemonade-server.ai"; license = licenses.asl20; mainProgram = "lemonade-server"; platforms = platforms.linux; maintainers = [ ]; }; }