rebuilding nix files

This commit is contained in:
2026-02-28 11:25:30 +01:00
parent d5958d7e98
commit 895e3cb90b
3 changed files with 381 additions and 438 deletions
+25 -44
View File
@@ -1651,95 +1651,76 @@ let
# Path to the ZED configuration template
AiRepoConf = flakeRoot + "/assets/conf/apps/ai/ai.conf";
# Parse the environment file into an attribute set (key-value pairs)
# Steps:
# 1. Read the file as a string
# 2. Split into lines using newline character
# 3. Filter out empty lines
# 4. Split each line by '=' to separate keys and values
# 5. Use lib.genAttrs to create a Nix attribute set
# Improved environment file parser that handles:
# - Lines with multiple '=' characters
# - Empty values
# - Whitespace around keys and values
# - Comments (lines starting with #)
envVars = lib.genAttrs (
builtins.map (
line: builtins.split "=" line # Split each line into [key, value]
) (builtins.filter (line: line != "") (builtins.split "\n" (builtins.readFile (toString AiRepoEnv))))
) (parts: builtins.elemAt parts 0) # First element is the key
(parts: builtins.elemAt parts 1); # Second element is the value
line: let
# Remove comments and trim whitespace
cleanLine = builtins.trim (builtins.replaceStrings [ "#" ] [ "" ] (builtins.elemAt (builtins.split "#" line) 0));
# Split on first '=' only
parts = builtins.split "=" cleanLine;
# Get key (first part) and trim whitespace
key = builtins.trim (builtins.elemAt parts 0);
# Get value (everything after first '=') and trim whitespace
value = builtins.trim (builtins.concatStringsSep "=" (builtins.drop 1 parts));
in { inherit key value; }
) (builtins.filter (line: line != "" && !builtins.startsWith "#" line)
(builtins.split "\n" (builtins.readFile (toString AiRepoEnv))))
) (entry: entry.key);
in
{
# Install required packages:
# - ollama-vulkan: Ollama with Vulkan support (for AMD/CPU)
# - zed: The ZED code editor
# Install required packages
home.packages = [
pkgs.ollama-vulkan
pkgs.zed
];
# Set environment variables for the user session
# These will be available to all user processes
home.sessionVariables = {
# Ollama server address, default to localhost if not set in ai.env
OLLAMA_HOST = envVars.OLLAMA_HOST or "http://127.0.0.1:11434";
# Mistral API key, empty string if not set in ai.env
MISTRAL_API_KEY = envVars.MISTRAL_API_KEY or "";
};
# Configure Ollama as a user service (runs when user logs in)
# Configure Ollama as a user service
systemd.user.services.ollama = {
description = "Ollama service for local AI models";
# Start with the user session
wantedBy = [ "default.target" ];
# Ensure network is available before starting
after = [ "network.target" ];
serviceConfig = {
# Run as a background process
Type = "forking";
# Command to start the Ollama server
ExecStart = ''
${pkgs.ollama-vulkan}/bin/ollama serve
'';
# Commands to run after the server starts
ExecStartPost = ''
# Wait for server to initialize
sleep 5
# Pull default models
${pkgs.ollama-vulkan}/bin/ollama pull codellama:70b # Coding model
${pkgs.ollama-vulkan}/bin/ollama pull mixtral:8x7b # Chat model
${pkgs.ollama-vulkan}/bin/ollama pull codellama:70b
${pkgs.ollama-vulkan}/bin/ollama pull mixtral:8x7b
'';
# Restart if the service crashes
Restart = "on-failure";
};
};
# Generate ZED's settings.json with API keys and endpoints
# Steps:
# 1. Read the template JSON file
# 2. Parse it from JSON to a Nix attribute set
# 3. Override specific values with our environment variables
# 4. Convert back to JSON and write to the config file
# Generate ZED's settings.json
home.file.".config/zed/settings.json".text = lib.mkForce (
builtins.toJSON (
# Start with the base config from ai.conf
(builtins.fromJSON (builtins.readFile (toString AiRepoConf)))
# Override specific values
// {
mistral = {
# Use the API key from ai.env, or empty string if not set
apiKey = envVars.MISTRAL_API_KEY or "";
defaultModel = "mistral-pro"; # Default Mistral model
defaultModel = "mistral-pro";
};
ollama = {
# Use the host from ai.env, or default localhost
endpoint = envVars.OLLAMA_HOST or "http://127.0.0.1:11434";
defaultModel = "codellama:70b"; # Default Ollama model for coding
defaultModel = "codellama:70b";
};
}
)
);
# --- Usage Notes ---
# 1. Pulling Additional Models:
# To add more models later, run: