Used variables for filenames to import (env + conf)

This commit is contained in:
2026-02-28 11:08:03 +01:00
parent 4b9992e9f2
commit cdb42fd563
5 changed files with 330 additions and 321 deletions
+314 -311
View File
File diff suppressed because it is too large Load Diff
+8 -5
View File
@@ -1643,13 +1643,15 @@ It ensures the Ollama CLI is available system-wide for interacting with local mo
It automatically pulls and prepares selected coding models (e.g., Qwen2.5-Coder and StarCoder2) at system activation. It automatically pulls and prepares selected coding models (e.g., Qwen2.5-Coder and StarCoder2) at system activation.
#+begin_src nix :tangle home/apps/ai.nix :noweb tangle :mkdirp yes #+begin_src nix :tangle home/apps/ai.nix :noweb tangle :mkdirp yes
{ config, pkgs, lib, ... }: { config, pkgs, lib, flakeRoot ... }:
let let
# Read environment variables (OLLAMA_HOST and MISTRAL_API_KEY) from a local file. # 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. # This keeps sensitive values out of the Nix store and version control.
# File format: one KEY=value per line (e.g., MISTRAL_API_KEY=yourkey)
envVars = lib.genAttrs (builtins.splitStrings "\n" (builtins.readFile (toString ./assets/conf/apps/ai.env))) AiRepoEnv = flakeRoot + "/assets/conf/apps/ai/ai.env";
AiRepoConf = flakeRoot + "/assets/conf/apps/ai/ai.conv";
envVars = lib.genAttrs (builtins.splitStrings "\n" (builtins.readFile (toString AiRepoEnv)))
(nameValue: builtins.splitString "=" nameValue); (nameValue: builtins.splitString "=" nameValue);
in in
{ {
@@ -1664,7 +1666,8 @@ in
# --- Environment Variables --- # --- Environment Variables ---
# Set OLLAMA_HOST and MISTRAL_API_KEY for ZED and other user applications. # Set OLLAMA_HOST and MISTRAL_API_KEY for ZED and other user applications.
# Values are read from ./assets/conf/apps/ai.env. # Values are read from AiRepoEnv.
home.sessionVariables = { home.sessionVariables = {
OLLAMA_HOST = envVars.OLLAMA_HOST or "http://127.0.0.1:11434"; # Default Ollama endpoint 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) MISTRAL_API_KEY = envVars.MISTRAL_API_KEY or ""; # Mistral API key (required for cloud models)
@@ -1707,7 +1710,7 @@ in
# Generate ZED's settings.json with substituted API keys and endpoints. # Generate ZED's settings.json with substituted API keys and endpoints.
# Base config is read from ./assets/conf/apps/ai.conf, with variables injected. # Base config is read from ./assets/conf/apps/ai.conf, with variables injected.
home.file.".config/zed/settings.json".text = lib.mkForce ( home.file.".config/zed/settings.json".text = lib.mkForce (
builtins.readFile (toString ./assets/conf/apps/ai.conf) builtins.readFile (toString AiRepoConf)
// '' // ''
{ {
"mistral": { "mistral": {
+8 -5
View File
@@ -1,10 +1,12 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, flakeRoot ... }:
let let
# Read environment variables (OLLAMA_HOST and MISTRAL_API_KEY) from a local file. # 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. # This keeps sensitive values out of the Nix store and version control.
# File format: one KEY=value per line (e.g., MISTRAL_API_KEY=yourkey)
envVars = lib.genAttrs (builtins.splitStrings "\n" (builtins.readFile (toString ./assets/conf/apps/ai.env))) AiRepoEnv = flakeRoot + "/assets/conf/apps/ai/ai.env";
AiRepoConf = flakeRoot + "/assets/conf/apps/ai/ai.conv";
envVars = lib.genAttrs (builtins.splitStrings "\n" (builtins.readFile (toString AiRepoEnv)))
(nameValue: builtins.splitString "=" nameValue); (nameValue: builtins.splitString "=" nameValue);
in in
{ {
@@ -19,7 +21,8 @@ in
# --- Environment Variables --- # --- Environment Variables ---
# Set OLLAMA_HOST and MISTRAL_API_KEY for ZED and other user applications. # Set OLLAMA_HOST and MISTRAL_API_KEY for ZED and other user applications.
# Values are read from ./assets/conf/apps/ai.env. # Values are read from AiRepoEnv.
home.sessionVariables = { home.sessionVariables = {
OLLAMA_HOST = envVars.OLLAMA_HOST or "http://127.0.0.1:11434"; # Default Ollama endpoint 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) MISTRAL_API_KEY = envVars.MISTRAL_API_KEY or ""; # Mistral API key (required for cloud models)
@@ -62,7 +65,7 @@ in
# Generate ZED's settings.json with substituted API keys and endpoints. # Generate ZED's settings.json with substituted API keys and endpoints.
# Base config is read from ./assets/conf/apps/ai.conf, with variables injected. # Base config is read from ./assets/conf/apps/ai.conf, with variables injected.
home.file.".config/zed/settings.json".text = lib.mkForce ( home.file.".config/zed/settings.json".text = lib.mkForce (
builtins.readFile (toString ./assets/conf/apps/ai.conf) builtins.readFile (toString AiRepoConf)
// '' // ''
{ {
"mistral": { "mistral": {