New Ollama.nix, the ai.nix did not work out. Added ZED-editor as separate app

This commit is contained in:
2026-02-28 15:04:36 +01:00
parent c71062b835
commit d0314fab5e
3 changed files with 327 additions and 419 deletions
+7 -38
View File
@@ -1641,50 +1641,19 @@ This module will import all necessities.
This Home Manager Nix module (ai.nix) installs the Ollama package and configures it by reading a simple key-value configuration file (ollama.conf) for settings like the server host and default model. It sets environment variables (OLLAMA_HOST and OLAMA_DEFAULT_MODEL) for easy access in your shell or applications, with fallback defaults if the config file is missing or empty. Optionally, it also defines a user-level systemd service to automatically start the Ollama server on NixOS or systems with Home Managers systemd support enabled.
#+begin_src nix :tangle home/apps/ollama.nix :noweb tangle :mkdirp yes
{ lib, config, pkgs, flakeRoot, ... }:
{ lib, pkgs, flakeRoot }:
let
# Path to the config file
ollamaConfPath = flakeRoot + "/apps/ai/ollama/ollama.conf";
ollamaConf = builtins.readFile ollamaConfPath;
# Simple parser for key="value" format that takes the last value
parseConf = lines:
lib.foldl' (acc, line)
(if builtins.match "^[^=]+=\"[^\"]+\"$" line != null
then let
parts = builtins.splitString "\"" line;
key = builtins.substring 0 (builtins.stringLength parts.0 - 1) parts.0;
value = parts.1;
in acc // { ${key} = value; }
else acc)
{}
(lib.filter (line: line != "" && ! (lib.hasPrefix "#" line)) (lib.splitString "\n" ollamaConf));
conf = parseConf ollamaConf;
in
{
# Install Ollama package
home.packages = with pkgs; [ ollama ];
# Set environment variables
home.sessionVariables = {
OLLAMA_HOST = conf.OLLAMA_HOST or "http://127.0.0.1:11434";
OLAMA_DEFAULT_MODEL = conf.OLAMA_DEFAULT_MODEL or "codellama:70b";
};
# Configure and enable Ollama service
systemd.user.services.ollama = {
description = "Ollama service";
wantedBy = [ "default.target" ];
serviceConfig = {
ExecStart = "${pkgs.ollama}/bin/ollama serve";
Restart = "on-failure";
Environment = "OLLAMA_HOST=${conf.OLLAMA_HOST or "http://127.0.0.1:11434"}";
};
services.ollama = {
enable = true;
package = pkgs.ollama;
configFile = ollamaConfPath;
environmentFile = builtins.readFile ollamaConfPath;
wantedBy = [ "multi-user.target" ];
};
}
#+end_src
** NCSway