systemd.services.init-ollama-model = { description = "Initialize nemotron 3 with extra context in Ollama Docker"; after = [ "docker-ollama.service" ]; # Ensure it runs after your ollama container wantedBy = [ "multi-user.target" ]; script = '' # Wait for Ollama while ! ${pkgs.curl}/bin/curl -s http://localhost:11434/api/tags > /dev/null; do sleep 2 done # Check if the model already exists in the persistent volume if ! ${pkgs.docker}/bin/docker exec ollama ollama list | grep -q "nemotron-3-nano:30b-128k"; then echo "nemotron-3-nano:30b-128k not found, creating..." ${pkgs.docker}/bin/docker exec ollama sh -c 'cat < /root/.ollama/nemotron-3-nano:30b-128k.modelfile FROM nemotron-3-nano:30b PARAMETER num_ctx 131072 PARAMETER num_predict 4096 PARAMETER repeat_penalty 1.1 EOF' ${pkgs.docker}/bin/docker exec ollama ollama create nemotron-3-nano:30b-128k -f /root/.ollama/nemotron-3-nano:30b-128k.modelfile else echo "nemotron-3-nano:30b-128k already exists, skipping creation." fi ''; serviceConfig = { Type = "oneshot"; RemainAfterExit = true; }; };