From 2dcc1291c501c1ac53da0a3c9745bfc5aa580432 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 28 Dec 2025 01:09:24 +0100 Subject: [PATCH] Added a temporary zed2.nix file to test things --- hosts/common/home.nix | 9 --- modules/common/zed2.nix | 145 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+), 9 deletions(-) create mode 100644 modules/common/zed2.nix diff --git a/hosts/common/home.nix b/hosts/common/home.nix index 6b7aaf6..e086ab6 100644 --- a/hosts/common/home.nix +++ b/hosts/common/home.nix @@ -5,7 +5,6 @@ imports = [ inputs.spicetify-nix.homeManagerModules.spicetify ../../modules/home-manager/spicetify.nix - ../../modules/home-manager/secrets.nix ../../modules/common/zed.nix ]; @@ -21,14 +20,6 @@ }; }; }; - sops = { - enable = true; - defaultSopsFile = ../../secrets/secrets.yaml; - defaultSopsFormat = "yaml"; - age = { - enable = true; - keyFile = "${config.home.homeDirectory}/.config/sops/age/keys.txt"; - }; # Zed config zed-custom = { enable = true; diff --git a/modules/common/zed2.nix b/modules/common/zed2.nix new file mode 100644 index 0000000..8b2a51f --- /dev/null +++ b/modules/common/zed2.nix @@ -0,0 +1,145 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.programs.zed-ai; + + homeDir = config.home.homeDirectory; + + zedSettings = { + language_models = { + ollama = { + api_url = "http://localhost:11434"; + available_models = [ + { name = "deepseek-r1:8b"; display_name = "DeepSeek-R1 8B (CoT Native)"; max_tokens = 64000; supports_tools = true; supports_thinking = true; supports_images = false; } + { name = "deepseek-r1:14b"; display_name = "DeepSeek-R1 14B (CoT Native)"; max_tokens = 64000; supports_tools = true; supports_thinking = true; supports_images = false; } + { name = "deepseek-coder-v2:16b"; display_name = "Deepseek Coder V2 16B"; max_tokens = 160000; supports_tools = false; supports_thinking = false; supports_images = false; } + { name = "starcoder2:7b"; display_name = "StarCoder2 7B"; max_tokens = 16384; supports_tools = false; supports_thinking = false; supports_images = false; } + { name = "codegemma:7b-instruct"; display_name = "CodeGemma 7B Instruct"; max_tokens = 8192; supports_tools = true; supports_thinking = false; supports_images = false; } + { name = "codegemma:2b"; display_name = "CodeGemma 2B (Fast)"; max_tokens = 8192; supports_tools = false; supports_thinking = false; supports_images = false; } + ]; + }; + }; + + inline_completions = { + provider = "ollama"; + ollama = { + model = "codegemma:2b"; + api_url = "http://localhost:11434"; + low_speed_timeout_in_seconds = 30; + timeout_in_seconds = 5; + }; + }; + + show_edit_predictions = false; + + agent = { + default_profile = "reasoning"; + play_sound_when_agent_done = true; + dock = "right"; + default_model = { + provider = "ollama"; + model = "deepseek-r1:14b"; + }; + + profiles = lib.mapAttrs (name: profile: + profile // { + context_servers = cfg.mcpServers; + } + ) { + reasoning = { + name = "Deep Reasoning (CoT)"; + tools = { + copy_path = true; create_directory = true; delete_path = true; diagnostics = true; edit_file = true; + fetch = true; list_directory = true; move_path = true; now = true; find_path = true; read_file = true; + grep = true; terminal = true; thinking = true; web_search = true; project_notifications = false; + }; + enable_all_context_servers = true; + system_prompt = '' + You are an expert programming assistant. Break down problems, think step by step, consider edge cases. + ''; + }; + + fast = { + name = "Fast Development"; + tools = { + copy_path = true; create_directory = true; delete_path = true; diagnostics = true; edit_file = true; + fetch = true; list_directory = true; move_path = true; now = true; find_path = true; read_file = true; + grep = true; terminal = true; thinking = false; web_search = true; project_notifications = false; + }; + enable_all_context_servers = true; + default_model = { provider = "ollama"; model = "codegemma:7b-instruct"; }; + system_prompt = "Fast assistant: concise, clear, efficient."; + }; + }; + }; + + ui_font_size = 16; + buffer_font_size = 16; + theme = "Dracula"; + icon_theme = "Material Icon Theme"; + }; + +in +{ + options.programs.zed-ai = { + enable = lib.mkEnableOption "Enable Zed AI with CoT"; + + mcpServers = lib.mkOption { + type = lib.types.attrs; + default = {}; + description = "MCP servers config"; + }; + + githubToken = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + description = "Github token for MCP"; + }; + + braveSearchApiKey = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + description = "Brave Search API key"; + }; + }; + + config = lib.mkIf cfg.enable { + # Déclarer secrets SOPS dans HM + sops.secrets = lib.mkIf (cfg.githubToken != null || cfg.braveSearchApiKey != null) { + "zed/github_token" = lib.mkIf (cfg.githubToken != null) {}; + "zed/brave_api_key" = lib.mkIf (cfg.braveSearchApiKey != null) {}; + }; + + # MCP servers dynamiques + programs.zed-ai.mcpServers = lib.mkDefault ( + lib.recursiveUpdate { + filesystem = { + command = "npx"; + args = ["-y" "@modelcontextprotocol/server-filesystem" "${homeDir}/Developer"]; + }; + + github = lib.optionalAttrs (cfg.githubToken != null) { + command = "npx"; + args = ["-y" "@modelcontextprotocol/server-github"]; + env = { GITHUB_PERSONAL_ACCESS_TOKEN = "$(cat ${config.sops.secrets."zed/github_token".path})"; }; + }; + + git = { command = "npx"; args = ["-y" "@modelcontextprotocol/server-git"]; }; + + brave-search = lib.optionalAttrs (cfg.braveSearchApiKey != null) { + command = "npx"; + args = ["-y" "@modelcontextprotocol/server-brave-search"]; + env = { BRAVE_API_KEY = "$(cat ${config.sops.secrets."zed/brave_api_key".path})"; }; + }; + } {} + ); + + # Générer settings.json + home.file.".config/zed/settings.json" = { + text = builtins.toJSON zedSettings; + }; + + # SOPS AGE keyFile portable + programs.sops.age.keyFile = "${homeDir}/.config/sops/age/keys.txt"; + }; +}