rebuilding nix files

This commit is contained in:
2026-02-28 11:24:33 +01:00
parent 48d2ccfd65
commit d5958d7e98
3 changed files with 504 additions and 354 deletions
+372 -322
View File
File diff suppressed because it is too large Load Diff
+66 -16
View File
@@ -1646,72 +1646,122 @@ It automatically pulls and prepares selected coding models (e.g., Qwen2.5-Coder
{ config, pkgs, lib, flakeRoot, ... }: { config, pkgs, lib, flakeRoot, ... }:
let let
# Path to the environment file containing OLLAMA_HOST and MISTRAL_API_KEY
AiRepoEnv = flakeRoot + "/assets/conf/apps/ai/ai.env"; AiRepoEnv = flakeRoot + "/assets/conf/apps/ai/ai.env";
# Path to the ZED configuration template
AiRepoConf = flakeRoot + "/assets/conf/apps/ai/ai.conf"; AiRepoConf = flakeRoot + "/assets/conf/apps/ai/ai.conf";
# Read and parse the environment file # 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
envVars = lib.genAttrs ( envVars = lib.genAttrs (
builtins.map ( builtins.map (
line: let line: builtins.split "=" line # Split each line into [key, value]
parts = builtins.split "=" line; ) (builtins.filter (line: line != "") (builtins.split "\n" (builtins.readFile (toString AiRepoEnv))))
key = builtins.elemAt parts 0; ) (parts: builtins.elemAt parts 0) # First element is the key
value = builtins.elemAt parts 1; (parts: builtins.elemAt parts 1); # Second element is the value
in { name = key; value = value; }
) (builtins.split "\n" (builtins.readFile (toString AiRepoEnv)))
) (entry: entry.name);
in in
{ {
# Install ZED editor and Ollama with Vulkan support (for CPU/AMD). # 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
]; ];
# --- Environment Variables --- # 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 "";
}; };
# --- Ollama User Service --- # Configure Ollama as a user service (runs when user logs in)
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";
}; };
}; };
# --- ZED Configuration --- # 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
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"; defaultModel = "mistral-pro"; # Default Mistral model
}; };
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"; defaultModel = "codellama:70b"; # Default Ollama model for coding
}; };
} }
) )
); );
# --- Usage Notes ---
# 1. Pulling Additional Models:
# To add more models later, run:
# ollama pull <model-name>
# Example: ollama pull llama3:8b
#
# 2. Switching GPU Backends:
# - For NVIDIA: Replace all `ollama-vulkan` with `ollama` (uses CUDA)
# - For AMD: Use `ollama-rocm` and ensure ROCm is installed
#
# 3. ZED Plugin Setup:
# - Install the Ollama and Mistral plugins in ZED via the plugin marketplace
# - The Ollama plugin will use the local models pulled above
# - The Mistral plugin will use the MISTRAL_API_KEY for cloud access
#
# 4. Security:
# - Never commit ./assets/conf/apps/ai.env to version control
# - For extra security, encrypt ai.env using sops-nix or age
#
# 5. Persistent Service:
# To keep Ollama running after logout, enable lingering:
# loginctl enable-linger $(whoami)
} }
#+end_src #+end_src
+66 -16
View File
@@ -1,70 +1,120 @@
{ config, pkgs, lib, flakeRoot, ... }: { config, pkgs, lib, flakeRoot, ... }:
let let
# Path to the environment file containing OLLAMA_HOST and MISTRAL_API_KEY
AiRepoEnv = flakeRoot + "/assets/conf/apps/ai/ai.env"; AiRepoEnv = flakeRoot + "/assets/conf/apps/ai/ai.env";
# Path to the ZED configuration template
AiRepoConf = flakeRoot + "/assets/conf/apps/ai/ai.conf"; AiRepoConf = flakeRoot + "/assets/conf/apps/ai/ai.conf";
# Read and parse the environment file # 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
envVars = lib.genAttrs ( envVars = lib.genAttrs (
builtins.map ( builtins.map (
line: let line: builtins.split "=" line # Split each line into [key, value]
parts = builtins.split "=" line; ) (builtins.filter (line: line != "") (builtins.split "\n" (builtins.readFile (toString AiRepoEnv))))
key = builtins.elemAt parts 0; ) (parts: builtins.elemAt parts 0) # First element is the key
value = builtins.elemAt parts 1; (parts: builtins.elemAt parts 1); # Second element is the value
in { name = key; value = value; }
) (builtins.split "\n" (builtins.readFile (toString AiRepoEnv)))
) (entry: entry.name);
in in
{ {
# Install ZED editor and Ollama with Vulkan support (for CPU/AMD). # 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
]; ];
# --- Environment Variables --- # 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 "";
}; };
# --- Ollama User Service --- # Configure Ollama as a user service (runs when user logs in)
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";
}; };
}; };
# --- ZED Configuration --- # 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
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"; defaultModel = "mistral-pro"; # Default Mistral model
}; };
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"; defaultModel = "codellama:70b"; # Default Ollama model for coding
}; };
} }
) )
); );
# --- Usage Notes ---
# 1. Pulling Additional Models:
# To add more models later, run:
# ollama pull <model-name>
# Example: ollama pull llama3:8b
#
# 2. Switching GPU Backends:
# - For NVIDIA: Replace all `ollama-vulkan` with `ollama` (uses CUDA)
# - For AMD: Use `ollama-rocm` and ensure ROCm is installed
#
# 3. ZED Plugin Setup:
# - Install the Ollama and Mistral plugins in ZED via the plugin marketplace
# - The Ollama plugin will use the local models pulled above
# - The Mistral plugin will use the MISTRAL_API_KEY for cloud access
#
# 4. Security:
# - Never commit ./assets/conf/apps/ai.env to version control
# - For extra security, encrypt ai.env using sops-nix or age
#
# 5. Persistent Service:
# To keep Ollama running after logout, enable lingering:
# loginctl enable-linger $(whoami)
} }