7 # This is a app can only be used in a browser and starts a web server only accessible at
8 # localhost/127.0.0.1 from the local computer at the given port.
9 defaultHostname ? "127.0.0.1",
11 # Where to find the Ollama service; this url gets baked into the Nix package
12 ollamaUrl ? "http://127.0.0.1:11434",
20 pname = "nextjs-ollama-llm-ui";
23 src = fetchFromGitHub {
25 repo = "nextjs-ollama-llm-ui";
27 hash = "sha256-pZJgiopm0VGwaZxsNcyRawevvzEcK1j5WhngX1Pn6YE=";
29 npmDepsHash = "sha256-wtHOW0CyEOszgiZwDkF2/cSxbw6WFRLbhDnd2FlY70E=";
32 # Update to a newer nextjs version that buildNpmPackage is able to build.
33 # Remove at nextjs update.
34 ./0001-update-nextjs.patch
35 # nextjs tries to download google fonts from the internet during buildPhase and fails in Nix sandbox.
36 # We patch the code to expect a local font from src/app/Inter.ttf that we load from Nixpkgs in preBuild phase.
37 ./0002-use-local-google-fonts.patch
38 # Modify next.config.js to produce a production "standalone" output at .next/standalone.
39 # This output is easy to package with Nix and run with "node .next/standalone/server.js" later.
40 ./0003-add-standalone-output.patch
43 # Adjust buildNpmPackage phases with nextjs quirk workarounds.
44 # These are adapted from
45 # https://github.com/NixOS/nixpkgs/blob/485125d667747f971cfcd1a1cfb4b2213a700c79/pkgs/servers/homepage-dashboard/default.nix
46 #######################3
48 # We have to pass and bake in the Ollama URL into the package
49 echo "NEXT_PUBLIC_OLLAMA_URL=${ollamaUrl}" > .env
51 # Replace the googleapis.com Inter font with a local copy from nixpkgs
52 cp "${inter}/share/fonts/truetype/InterVariable.ttf" src/app/Inter.ttf
56 # Add a shebang to the server js file, then patch the shebang to use a nixpkgs nodejs binary.
57 sed -i '1s|^|#!/usr/bin/env node\n|' .next/standalone/server.js
58 patchShebangs .next/standalone/server.js
64 mkdir -p $out/{share,bin}
66 cp -r .next/standalone $out/share/homepage/
67 cp -r .env $out/share/homepage/
68 cp -r public $out/share/homepage/public
70 mkdir -p $out/share/homepage/.next
71 cp -r .next/static $out/share/homepage/.next/static
73 chmod +x $out/share/homepage/server.js
75 # we set a default port to support "nix run ..."
76 makeWrapper $out/share/homepage/server.js $out/bin/nextjs-ollama-llm-ui \
77 --set-default PORT ${toString defaultPort} \
78 --set-default HOSTNAME ${defaultHostname}
84 #######################
88 inherit (nixosTests) nextjs-ollama-llm-ui;
93 description = "Simple chat web interface for Ollama LLMs";
94 changelog = "https://github.com/jakobhoeg/nextjs-ollama-llm-ui/releases/tag/v${version}";
95 mainProgram = "nextjs-ollama-llm-ui";
96 homepage = "https://github.com/jakobhoeg/nextjs-ollama-llm-ui";
97 license = lib.licenses.mit;
98 maintainers = with lib.maintainers; [ malteneuss ];
99 platforms = lib.platforms.all;