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