nixnix-flakeollama

Why can I use ollama with in a virtual environemt created by nix-shell but not when created by a flake


the command nix-shell -p ollama works fine. In the virtual environment I can do that.

 ollama start &
 ollama run mistral

I can now use the mistral llm chatbot.

But when I use a flake like this one.

{

 inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";  inputs.flake-utils.url = "github:numtide/flake-utils";

 outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        ollama=pkgs.ollama;
       in {
        devShells.default = pkgs.mkShell {
          buildInputs = [
            pkgs.curl
            ollama
           ];
        };
      }); }

it doesn't work. although the command to create the environment

nix develop works

fine

THe problem occurs when I try to use ollama inside the environment

ollama.start # if don't do that before ollama.run I get a message that say that ollama hasn't started yet.

returns this error:

Error: $HOME is not defined

I have the same problem ollama.serve


Solution

  • YOu have to run nix develop alone not nix develop -i or you should at least write --keep HOME

    If you tried to use ollama with nix-shell. Check that ollama process is not running anymore int the background.

    Otherwise you have this error:

    Error: listen tcp 127.0.0.1:11434: bind: address already in use

    to solve this error:

      netstat -ltnup | grep ':11434'
    

    You get 51454/ollama

       kill 51454
    

    now ollama run mistral works