New Ollama.nix, the ai.nix did not work out. Added ZED-editor as separate app
This commit is contained in:
+326
-334
File diff suppressed because it is too large
Load Diff
+20
-28
@@ -1645,50 +1645,42 @@ This Home Manager Nix module (ai.nix) installs the Ollama package and configures
|
|||||||
|
|
||||||
let
|
let
|
||||||
# Path to the config file
|
# 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;
|
ollamaConf = builtins.readFile ollamaConfPath;
|
||||||
|
|
||||||
# Helper function to extract values from key="value" lines
|
# Simple parser for key="value" format that takes the last value
|
||||||
extractValue = key:
|
parseConf = lines:
|
||||||
let
|
lib.foldl' (acc, line)
|
||||||
# Split into lines and filter out comments/empty lines
|
(if builtins.match "^[^=]+=\"[^\"]+\"$" line != null
|
||||||
lines = lib.filter (line: line != "" && ! (lib.hasPrefix "#" line))
|
then let
|
||||||
(lib.splitString "\n" ollamaConf);
|
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
|
conf = parseConf ollamaConf;
|
||||||
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";
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Install Ollama
|
# Install Ollama package
|
||||||
home.packages = with pkgs; [ ollama ];
|
home.packages = with pkgs; [ ollama ];
|
||||||
|
|
||||||
# Configure Ollama environment variables
|
# Set environment variables
|
||||||
home.sessionVariables = {
|
home.sessionVariables = {
|
||||||
OLLAMA_HOST = if ollamaHost != null then ollamaHost else "http://127.0.0.1:11434";
|
OLLAMA_HOST = conf.OLLAMA_HOST or "http://127.0.0.1:11434";
|
||||||
OLAMA_DEFAULT_MODEL = if ollamaDefaultModel != null then ollamaDefaultModel else "codellama:70b";
|
OLAMA_DEFAULT_MODEL = conf.OLAMA_DEFAULT_MODEL or "codellama:70b";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Start Ollama service
|
# Configure and enable Ollama service
|
||||||
systemd.user.services.ollama = {
|
systemd.user.services.ollama = {
|
||||||
description = "Ollama service";
|
description = "Ollama service";
|
||||||
wantedBy = [ "default.target" ];
|
wantedBy = [ "default.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${pkgs.ollama}/bin/ollama serve";
|
ExecStart = "${pkgs.ollama}/bin/ollama serve";
|
||||||
Restart = "on-failure";
|
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"
|
OLLAMA_HOST="http://127.0.0.1:11434"
|
||||||
OLAMA_DEFAULT_MODEL="codellama:70b"
|
OLAMA_DEFAULT_MODEL="codellama:70b"
|
||||||
OLAMA_DEFAULT_MODEL="llama3.1:70b"
|
OLAMA_DEFAULT_MODEL="llama3.1:70b"
|
||||||
|
|||||||
@@ -2,50 +2,42 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
# Path to the config file
|
# 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;
|
ollamaConf = builtins.readFile ollamaConfPath;
|
||||||
|
|
||||||
# Helper function to extract values from key="value" lines
|
# Simple parser for key="value" format that takes the last value
|
||||||
extractValue = key:
|
parseConf = lines:
|
||||||
let
|
lib.foldl' (acc, line)
|
||||||
# Split into lines and filter out comments/empty lines
|
(if builtins.match "^[^=]+=\"[^\"]+\"$" line != null
|
||||||
lines = lib.filter (line: line != "" && ! (lib.hasPrefix "#" line))
|
then let
|
||||||
(lib.splitString "\n" ollamaConf);
|
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
|
conf = parseConf ollamaConf;
|
||||||
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";
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Install Ollama
|
# Install Ollama package
|
||||||
home.packages = with pkgs; [ ollama ];
|
home.packages = with pkgs; [ ollama ];
|
||||||
|
|
||||||
# Configure Ollama environment variables
|
# Set environment variables
|
||||||
home.sessionVariables = {
|
home.sessionVariables = {
|
||||||
OLLAMA_HOST = if ollamaHost != null then ollamaHost else "http://127.0.0.1:11434";
|
OLLAMA_HOST = conf.OLLAMA_HOST or "http://127.0.0.1:11434";
|
||||||
OLAMA_DEFAULT_MODEL = if ollamaDefaultModel != null then ollamaDefaultModel else "codellama:70b";
|
OLAMA_DEFAULT_MODEL = conf.OLAMA_DEFAULT_MODEL or "codellama:70b";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Start Ollama service
|
# Configure and enable Ollama service
|
||||||
systemd.user.services.ollama = {
|
systemd.user.services.ollama = {
|
||||||
description = "Ollama service";
|
description = "Ollama service";
|
||||||
wantedBy = [ "default.target" ];
|
wantedBy = [ "default.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${pkgs.ollama}/bin/ollama serve";
|
ExecStart = "${pkgs.ollama}/bin/ollama serve";
|
||||||
Restart = "on-failure";
|
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"}";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user