rebuilding nix files

This commit is contained in:
2026-02-28 11:21:53 +01:00
parent b0d5b4a1f3
commit 91ff5583c3
3 changed files with 389 additions and 474 deletions
+334 -362
View File
File diff suppressed because it is too large Load Diff
+28 -56
View File
@@ -1647,8 +1647,6 @@ It automatically pulls and prepares selected coding models (e.g., Qwen2.5-Coder
let
# Read environment variables (OLLAMA_HOST and MISTRAL_API_KEY) from a local file.
# This keeps sensitive values out of the Nix store and version control.
AiRepoEnv = flakeRoot + "/assets/conf/apps/ai/ai.env";
AiRepoConf = flakeRoot + "/assets/conf/apps/ai/ai.conf";
envVars = lib.genAttrs (builtins.splitStrings "\n" (builtins.readFile (toString AiRepoEnv)))
@@ -1656,98 +1654,72 @@ let
in
{
# Install ZED editor and Ollama with Vulkan support (for CPU/AMD).
# For NVIDIA GPUs, replace `ollama-vulkan` with `ollama`.
# For AMD ROCm, use `ollama-rocm` and ensure ROCm is installed.
home.packages = [
pkgs.ollama-vulkan
pkgs.zed
];
# --- Environment Variables ---
# Set OLLAMA_HOST and MISTRAL_API_KEY for ZED and other user applications.
# Values are read from AiRepoEnv.
home.sessionVariables = {
OLLAMA_HOST = envVars.OLLAMA_HOST or "http://127.0.0.1:11434"; # Default Ollama endpoint
MISTRAL_API_KEY = envVars.MISTRAL_API_KEY or ""; # Mistral API key (required for cloud models)
OLLAMA_HOST = envVars.OLLAMA_HOST or "http://127.0.0.1:11434";
MISTRAL_API_KEY = envVars.MISTRAL_API_KEY or "";
};
# --- Ollama User Service ---
# Configure Ollama to run as a user service (starts on login).
# This avoids root privileges and allows per-user model management.
systemd.user.services.ollama = {
description = "Ollama service for local AI models";
wantedBy = [ "default.target" ]; # Start with user session
after = [ "network.target" ]; # Ensure network is ready
wantedBy = [ "default.target" ];
after = [ "network.target" ];
serviceConfig = {
Type = "forking"; # Run as a background process
Type = "forking";
# Start Ollama server
ExecStart = ''
${pkgs.ollama-vulkan}/bin/ollama serve
'';
# Pull default models after server starts
ExecStartPost = ''
sleep 5 # Wait for server to initialize
sleep 5
# Pull coding and chat models at startup
${pkgs.ollama-vulkan}/bin/ollama pull codellama:70b # Best for coding tasks
${pkgs.ollama-vulkan}/bin/ollama pull mixtral:8x7b # Best for chat/conversation
# Uncomment to pull additional models:
# ${pkgs.ollama-vulkan}/bin/ollama pull llama3:8b # General-purpose model
# ${pkgs.ollama-vulkan}/bin/ollama pull qwen2.5-coder:7b # Multilingual coding
# ${pkgs.ollama-vulkan}/bin/ollama pull starcoder2:15b # Alternative for code
${pkgs.ollama-vulkan}/bin/ollama pull codellama:70b
${pkgs.ollama-vulkan}/bin/ollama pull mixtral:8x7b
'';
Restart = "on-failure"; # Restart if Ollama crashes
Restart = "on-failure";
};
};
# --- ZED Configuration ---
# Generate ZED's settings.json with substituted API keys and endpoints.
# Base config is read from ./assets/conf/apps/ai.conf, with variables injected.
home.file.".config/zed/settings.json".text = lib.mkForce (
builtins.readFile (toString AiRepoConf)
// ''
{
"mistral": {
"apiKey": "${envVars.MISTRAL_API_KEY}", # Inject Mistral API key
"defaultModel": "mistral-pro" # Default Mistral model
},
"ollama": {
"endpoint": "${envVars.OLLAMA_HOST}", # Inject Ollama endpoint
"defaultModel": "codellama:70b" # Default Ollama model for coding
}
builtins.toJSON (
(builtins.fromJSON (builtins.readFile (toString AiRepoConf)))
// {
mistral = {
apiKey = envVars.MISTRAL_API_KEY or "";
defaultModel = "mistral-pro";
};
ollama = {
endpoint = envVars.OLLAMA_HOST or "http://127.0.0.1:11434";
defaultModel = "codellama:70b";
};
}
''
)
);
# --- Usage Notes ---
# 1. Pulling Additional Models:
# To add more models later, run:
# ollama pull <model-name>
# Example: ollama pull llama3:8b
# ollama pull <model-name>
# 2. Switching GPU Backends:
# - For NVIDIA: Replace all `ollama-vulkan` with `ollama` (uses CUDA)
# - For AMD: Use `ollama-rocm` and ensure ROCm is installed
# - NVIDIA: Replace `ollama-vulkan` with `ollama`
# - 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
# - Install Ollama and Mistral plugins in ZED
# 4. Security:
# - Never commit ./assets/conf/apps/ai.env to version control
# - For extra security, encrypt ai.env using sops-nix or age
# - Never commit ai.env to version control
# 5. Persistent Service:
# To keep Ollama running after logout, enable lingering:
# loginctl enable-linger $(whoami)
# loginctl enable-linger $(whoami)
}
#+end_src
** NCSway
+27 -56
View File
@@ -2,8 +2,6 @@
let
# Read environment variables (OLLAMA_HOST and MISTRAL_API_KEY) from a local file.
# This keeps sensitive values out of the Nix store and version control.
AiRepoEnv = flakeRoot + "/assets/conf/apps/ai/ai.env";
AiRepoConf = flakeRoot + "/assets/conf/apps/ai/ai.conf";
envVars = lib.genAttrs (builtins.splitStrings "\n" (builtins.readFile (toString AiRepoEnv)))
@@ -11,94 +9,67 @@ let
in
{
# Install ZED editor and Ollama with Vulkan support (for CPU/AMD).
# For NVIDIA GPUs, replace `ollama-vulkan` with `ollama`.
# For AMD ROCm, use `ollama-rocm` and ensure ROCm is installed.
home.packages = [
pkgs.ollama-vulkan
pkgs.zed
];
# --- Environment Variables ---
# Set OLLAMA_HOST and MISTRAL_API_KEY for ZED and other user applications.
# Values are read from AiRepoEnv.
home.sessionVariables = {
OLLAMA_HOST = envVars.OLLAMA_HOST or "http://127.0.0.1:11434"; # Default Ollama endpoint
MISTRAL_API_KEY = envVars.MISTRAL_API_KEY or ""; # Mistral API key (required for cloud models)
OLLAMA_HOST = envVars.OLLAMA_HOST or "http://127.0.0.1:11434";
MISTRAL_API_KEY = envVars.MISTRAL_API_KEY or "";
};
# --- Ollama User Service ---
# Configure Ollama to run as a user service (starts on login).
# This avoids root privileges and allows per-user model management.
systemd.user.services.ollama = {
description = "Ollama service for local AI models";
wantedBy = [ "default.target" ]; # Start with user session
after = [ "network.target" ]; # Ensure network is ready
wantedBy = [ "default.target" ];
after = [ "network.target" ];
serviceConfig = {
Type = "forking"; # Run as a background process
Type = "forking";
# Start Ollama server
ExecStart = ''
${pkgs.ollama-vulkan}/bin/ollama serve
'';
# Pull default models after server starts
ExecStartPost = ''
sleep 5 # Wait for server to initialize
sleep 5
# Pull coding and chat models at startup
${pkgs.ollama-vulkan}/bin/ollama pull codellama:70b # Best for coding tasks
${pkgs.ollama-vulkan}/bin/ollama pull mixtral:8x7b # Best for chat/conversation
# Uncomment to pull additional models:
# ${pkgs.ollama-vulkan}/bin/ollama pull llama3:8b # General-purpose model
# ${pkgs.ollama-vulkan}/bin/ollama pull qwen2.5-coder:7b # Multilingual coding
# ${pkgs.ollama-vulkan}/bin/ollama pull starcoder2:15b # Alternative for code
${pkgs.ollama-vulkan}/bin/ollama pull codellama:70b
${pkgs.ollama-vulkan}/bin/ollama pull mixtral:8x7b
'';
Restart = "on-failure"; # Restart if Ollama crashes
Restart = "on-failure";
};
};
# --- ZED Configuration ---
# Generate ZED's settings.json with substituted API keys and endpoints.
# Base config is read from ./assets/conf/apps/ai.conf, with variables injected.
home.file.".config/zed/settings.json".text = lib.mkForce (
builtins.readFile (toString AiRepoConf)
// ''
{
"mistral": {
"apiKey": "${envVars.MISTRAL_API_KEY}", # Inject Mistral API key
"defaultModel": "mistral-pro" # Default Mistral model
},
"ollama": {
"endpoint": "${envVars.OLLAMA_HOST}", # Inject Ollama endpoint
"defaultModel": "codellama:70b" # Default Ollama model for coding
}
builtins.toJSON (
(builtins.fromJSON (builtins.readFile (toString AiRepoConf)))
// {
mistral = {
apiKey = envVars.MISTRAL_API_KEY or "";
defaultModel = "mistral-pro";
};
ollama = {
endpoint = envVars.OLLAMA_HOST or "http://127.0.0.1:11434";
defaultModel = "codellama:70b";
};
}
''
)
);
# --- Usage Notes ---
# 1. Pulling Additional Models:
# To add more models later, run:
# ollama pull <model-name>
# Example: ollama pull llama3:8b
# ollama pull <model-name>
# 2. Switching GPU Backends:
# - For NVIDIA: Replace all `ollama-vulkan` with `ollama` (uses CUDA)
# - For AMD: Use `ollama-rocm` and ensure ROCm is installed
# - NVIDIA: Replace `ollama-vulkan` with `ollama`
# - 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
# - Install Ollama and Mistral plugins in ZED
# 4. Security:
# - Never commit ./assets/conf/apps/ai.env to version control
# - For extra security, encrypt ai.env using sops-nix or age
# - Never commit ai.env to version control
# 5. Persistent Service:
# To keep Ollama running after logout, enable lingering:
# loginctl enable-linger $(whoami)
# loginctl enable-linger $(whoami)
}