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:01:27 +01:00
parent bedf061d3e
commit c71062b835
4 changed files with 366 additions and 391 deletions
+326 -334
View File
File diff suppressed because it is too large Load Diff
+20 -28
View File
@@ -1645,50 +1645,42 @@ This Home Manager Nix module (ai.nix) installs the Ollama package and configures
let
# Path to the config file
ollamaConfPath = flakeRoot + "/assets/conf/apps/ai/ollama/ollama.conf";
ollamaConfPath = flakeRoot + "/apps/ai/ollama/ollama.conf";
ollamaConf = builtins.readFile ollamaConfPath;
# Helper function to extract values from key="value" lines
extractValue = key:
let
# Split into lines and filter out comments/empty lines
lines = lib.filter (line: line != "" && ! (lib.hasPrefix "#" line))
(lib.splitString "\n" ollamaConf);
# 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));
# Find the last matching line
matchingLines = lib.filter (line: builtins.match ("^${key}=\"") line != null) lines;
lastLine = if matchingLines != [] then lib.elemAt matchingLines (lib.length matchingLines - 1) else null;
in
if lastLine != null then
# Extract everything after the ="
builtins.substring
(builtins.stringLength (builtins.match ("^${key}=\"") lastLine) + 1)
(builtins.stringLength lastLine - 1) # Remove trailing quote
lastLine
else
null;
ollamaHost = extractValue "OLLAMA_HOST";
ollamaDefaultModel = extractValue "OLLAMA_DEFAULT_MODEL";
conf = parseConf ollamaConf;
in
{
# Install Ollama
# Install Ollama package
home.packages = with pkgs; [ ollama ];
# Configure Ollama environment variables
# Set environment variables
home.sessionVariables = {
OLLAMA_HOST = if ollamaHost != null then ollamaHost else "http://127.0.0.1:11434";
OLAMA_DEFAULT_MODEL = if ollamaDefaultModel != null then ollamaDefaultModel else "codellama:70b";
OLLAMA_HOST = conf.OLLAMA_HOST or "http://127.0.0.1:11434";
OLAMA_DEFAULT_MODEL = conf.OLAMA_DEFAULT_MODEL or "codellama:70b";
};
# Start Ollama service
# 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=${if ollamaHost != null then ollamaHost else "http://127.0.0.1:11434"}";
Environment = "OLLAMA_HOST=${conf.OLLAMA_HOST or "http://127.0.0.1:11434"}";
};
};
}
@@ -1,4 +1,3 @@
# Ollama configuration
OLLAMA_HOST="http://127.0.0.1:11434"
OLAMA_DEFAULT_MODEL="codellama:70b"
OLAMA_DEFAULT_MODEL="llama3.1:70b"
+20 -28
View File
@@ -2,50 +2,42 @@
let
# Path to the config file
ollamaConfPath = flakeRoot + "/assets/conf/apps/ai/ollama/ollama.conf";
ollamaConfPath = flakeRoot + "/apps/ai/ollama/ollama.conf";
ollamaConf = builtins.readFile ollamaConfPath;
# Helper function to extract values from key="value" lines
extractValue = key:
let
# Split into lines and filter out comments/empty lines
lines = lib.filter (line: line != "" && ! (lib.hasPrefix "#" line))
(lib.splitString "\n" ollamaConf);
# 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));
# Find the last matching line
matchingLines = lib.filter (line: builtins.match ("^${key}=\"") line != null) lines;
lastLine = if matchingLines != [] then lib.elemAt matchingLines (lib.length matchingLines - 1) else null;
in
if lastLine != null then
# Extract everything after the ="
builtins.substring
(builtins.stringLength (builtins.match ("^${key}=\"") lastLine) + 1)
(builtins.stringLength lastLine - 1) # Remove trailing quote
lastLine
else
null;
ollamaHost = extractValue "OLLAMA_HOST";
ollamaDefaultModel = extractValue "OLLAMA_DEFAULT_MODEL";
conf = parseConf ollamaConf;
in
{
# Install Ollama
# Install Ollama package
home.packages = with pkgs; [ ollama ];
# Configure Ollama environment variables
# Set environment variables
home.sessionVariables = {
OLLAMA_HOST = if ollamaHost != null then ollamaHost else "http://127.0.0.1:11434";
OLAMA_DEFAULT_MODEL = if ollamaDefaultModel != null then ollamaDefaultModel else "codellama:70b";
OLLAMA_HOST = conf.OLLAMA_HOST or "http://127.0.0.1:11434";
OLAMA_DEFAULT_MODEL = conf.OLAMA_DEFAULT_MODEL or "codellama:70b";
};
# Start Ollama service
# 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=${if ollamaHost != null then ollamaHost else "http://127.0.0.1:11434"}";
Environment = "OLLAMA_HOST=${conf.OLLAMA_HOST or "http://127.0.0.1:11434"}";
};
};
}