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-IA7g96u5QY8cOuTbJEWw7+U+hSFBzIQVk4Kv3qHKAdM=";
29 npmDepsHash = "sha256-3M0BZ9KZZ0ONwvTLycfMR8skMQf8mzjeqYCwJY4l040=";
32 # nextjs tries to download google fonts from the internet during buildPhase and fails in Nix sandbox.
33 # We patch the code to expect a local font from src/app/Inter.ttf that we load from Nixpkgs in preBuild phase.
34 ./0002-use-local-google-fonts.patch
37 # Adjust buildNpmPackage phases with nextjs quirk workarounds.
38 # These are adapted from
39 # https://github.com/NixOS/nixpkgs/blob/485125d667747f971cfcd1a1cfb4b2213a700c79/pkgs/servers/homepage-dashboard/default.nix
40 #######################3
42 # We have to pass and bake in the Ollama URL into the package
43 echo "NEXT_PUBLIC_OLLAMA_URL=${ollamaUrl}" > .env
45 # Replace the googleapis.com Inter font with a local copy from nixpkgs
46 cp "${inter}/share/fonts/truetype/InterVariable.ttf" src/app/Inter.ttf
50 # Add a shebang to the server js file, then patch the shebang to use a nixpkgs nodejs binary.
51 sed -i '1s|^|#!/usr/bin/env node\n|' .next/standalone/server.js
52 patchShebangs .next/standalone/server.js
58 mkdir -p $out/{share,bin}
60 cp -r .next/standalone $out/share/homepage/
61 cp -r .env $out/share/homepage/
62 cp -r public $out/share/homepage/public
64 mkdir -p $out/share/homepage/.next
65 cp -r .next/static $out/share/homepage/.next/static
67 # https://github.com/vercel/next.js/discussions/58864
68 ln -s /var/cache/nextjs-ollama-llm-ui $out/share/homepage/.next/cache
70 chmod +x $out/share/homepage/server.js
72 # we set a default port to support "nix run ..."
73 makeWrapper $out/share/homepage/server.js $out/bin/nextjs-ollama-llm-ui \
74 --set-default PORT ${toString defaultPort} \
75 --set-default HOSTNAME ${defaultHostname}
81 #######################
85 inherit (nixosTests) nextjs-ollama-llm-ui;
90 description = "Simple chat web interface for Ollama LLMs";
91 changelog = "https://github.com/jakobhoeg/nextjs-ollama-llm-ui/releases/tag/v${version}";
92 mainProgram = "nextjs-ollama-llm-ui";
93 homepage = "https://github.com/jakobhoeg/nextjs-ollama-llm-ui";
94 license = lib.licenses.mit;
95 maintainers = with lib.maintainers; [ malteneuss ];
96 platforms = lib.platforms.all;