From d92e1426ba84fd5dbdd6b1ce8a55af12f4a673da Mon Sep 17 00:00:00 2001 From: Thierry Pouplier Date: Thu, 1 Jan 2026 02:25:25 -0500 Subject: [PATCH] chore: update service modules and remove deprecated systemd services --- .../services/ollama_init_custom_models.nix | 70 +++++++++------ modules/nixos/services/open_code_server.nix | 86 +++++++++++++++++-- modules/nixos/services/podman.nix | 8 +- modules/nixos/services/systemd/default.nix | 16 ---- modules/nixos/services/systemd/fancontrol.nix | 37 -------- modules/nixos/services/systemd/network.nix | 35 -------- .../services/systemd/passwordmanager.nix | 31 ------- .../nixos/services/systemd/versioncontrol.nix | 33 ------- 8 files changed, 121 insertions(+), 195 deletions(-) delete mode 100644 modules/nixos/services/systemd/default.nix delete mode 100644 modules/nixos/services/systemd/fancontrol.nix delete mode 100644 modules/nixos/services/systemd/network.nix delete mode 100644 modules/nixos/services/systemd/passwordmanager.nix delete mode 100644 modules/nixos/services/systemd/versioncontrol.nix diff --git a/modules/nixos/services/ollama_init_custom_models.nix b/modules/nixos/services/ollama_init_custom_models.nix index 766727b..812849e 100644 --- a/modules/nixos/services/ollama_init_custom_models.nix +++ b/modules/nixos/services/ollama_init_custom_models.nix @@ -1,31 +1,45 @@ -systemd.services.init-ollama-model = { - description = "Initialize nemotron 3 with extra context in Ollama Docker"; - after = [ "docker-ollama.service" ]; # Ensure it runs after your ollama container - wantedBy = [ "multi-user.target" ]; - script = '' - # Wait for Ollama - while ! ${pkgs.curl}/bin/curl -s http://localhost:11434/api/tags > /dev/null; do - sleep 2 - done +{ pkgs, ... }: { + systemd.services.init-ollama-model = { + description = "Initialize LLM models with extra context in Ollama Docker"; + after = [ "docker-ollama.service" ]; + wantedBy = [ "multi-user.target" ]; + script = '' + # Wait for Ollama + while ! ${pkgs.curl}/bin/curl -s http://localhost:11434/api/tags > /dev/null; do + sleep 2 + done - # Check if the model already exists in the persistent volume - if ! ${pkgs.docker}/bin/docker exec ollama ollama list | grep -q "nemotron-3-nano:30b-128k"; then - echo "nemotron-3-nano:30b-128k not found, creating..." + create_model_if_missing() { + local model_name=$1 + local base_model=$2 + if ! ${pkgs.docker}/bin/docker exec ollama ollama list | grep -q "$model_name"; then + echo "$model_name not found, creating from $base_model..." + ${pkgs.docker}/bin/docker exec ollama sh -c "cat < /root/.ollama/$model_name.modelfile +FROM $base_model +PARAMETER num_ctx 131072 +PARAMETER num_predict 4096 +PARAMETER num_keep 1024 +PARAMETER repeat_penalty 1.1 +PARAMETER top_k 40 +PARAMETER stop \"[INST]\" +PARAMETER stop \"[/INST]\" +PARAMETER stop \"\" +EOF" + ${pkgs.docker}/bin/docker exec ollama ollama create "$model_name" -f "/root/.ollama/$model_name.modelfile" + else + echo "$model_name already exists, skipping." + fi + } + + # Create Nemotron + create_model_if_missing "nemotron-3-nano:30b-128k" "nemotron-3-nano:30b" - ${pkgs.docker}/bin/docker exec ollama sh -c 'cat < /root/.ollama/nemotron-3-nano:30b-128k.modelfile - FROM nemotron-3-nano:30b - PARAMETER num_ctx 131072 - PARAMETER num_predict 4096 - PARAMETER repeat_penalty 1.1 - EOF' - - ${pkgs.docker}/bin/docker exec ollama ollama create nemotron-3-nano:30b-128k -f /root/.ollama/nemotron-3-nano:30b-128k.modelfile - else - echo "nemotron-3-nano:30b-128k already exists, skipping creation." - fi - ''; - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; + # Create Devstral + create_model_if_missing "devstral-small-2:24b-128k" "devstral-small-2:24b" + ''; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + }; }; -}; +} diff --git a/modules/nixos/services/open_code_server.nix b/modules/nixos/services/open_code_server.nix index f66c713..604abbe 100644 --- a/modules/nixos/services/open_code_server.nix +++ b/modules/nixos/services/open_code_server.nix @@ -18,45 +18,113 @@ in { config = lib.mkIf cfg.enable { programs.nix-ld.enable = true; + # We inject the Context7 MCP requirement directly into your nix-generated config environment.etc."opencode/opencode.json".text = builtins.toJSON { "$schema" = "https://opencode.ai/config.json"; + "model" = "devstral-2-small-llama_cpp"; - "model" = "ollama/nemotron-3-nano:30b"; - + # Added the MCP section required by GSD + "mcp" = { + "context7" = { + "type" = "remote"; + "url" = "https://mcp.context7.com/mcp"; + }; + }; + "provider" = { + "llamacpp" = { + "name" = "Llama.cpp (Local MI50)"; + "npm" = "@ai-sdk/openai-compatible"; + "options" = { + "baseURL" = "http://localhost:8300/v1"; + "apiKey" = "not-needed"; + }; + "models" = { + "devstral-2-small-llama_cpp" = { + "name" = "Devstral 2 small 24B Q8 (llama.cpp)"; + "tools" = true; + "reasoning" = false; + }; + }; + }; "ollama" = { "name" = "Ollama (Local)"; "npm" = "@ai-sdk/openai-compatible"; "options" = { "baseURL" = cfg.ollamaUrl; + "headers" = { "Content-Type" = "application/json"; }; }; "models" = { - # The exact model ID as seen in 'ollama list' - "nemotron-3-nano:30b" = { - "name" = "NVIDIA Nemotron 3 Nano (30B)"; + "devstral-small-2:24b-128k" = { + "name" = "Mistral Devstral Small 2 (Ollama)"; + "tools" = true; + "reasoning" = false; }; }; }; }; }; + # This service runs the GSD installer directly from the source + systemd.services.opencode-gsd-install = { + description = "Install Get Shit Done OpenCode Components"; + after = [ "network-online.target" ]; + wantedBy = [ "multi-user.target" ]; + path = with pkgs; [ + nodejs + git + coreutils + bash + ]; + serviceConfig = { + Type = "oneshot"; + User = "gortium"; + RemainAfterExit = true; + Environment = [ + "HOME=/home/gortium" + "SHELL=${pkgs.bash}/bin/bash" + "PATH=${lib.makeBinPath [ pkgs.nodejs pkgs.git pkgs.bash pkgs.coreutils ]}" + ]; + }; + script = '' + # Check if the GSD directory exists + if [ ! -d "/home/gortium/.config/opencode/gsd" ]; then + echo "GSD not found. Installing..." + ${pkgs.nodejs}/bin/npx -y github:dbachelder/get-shit-done-opencode --global --force + else + echo "GSD already installed. Skipping auto-reinstall." + echo "To force update, run: sudo systemctl restart opencode-gsd-install.service" + fi + ''; + }; + systemd.services.opencode = { description = "OpenCode AI Coding Agent Server"; - after = [ "network.target" "ai_stack.service" ]; - requires = [ "ai_stack.service" ]; + after = [ "network.target" "ai_stack.service" "opencode-gsd-install.service" ]; + requires = [ "ai_stack.service" "opencode-gsd-install.service" ]; wantedBy = [ "multi-user.target" ]; + path = with pkgs; [ + bash + coreutils + nodejs + git + nix + ripgrep + fd + ]; + serviceConfig = { Type = "simple"; User = "gortium"; + WorkingDirectory = "/home/gortium/infra"; ExecStart = "${pkgs.nodejs}/bin/npx -y opencode-ai serve --hostname 0.0.0.0 --port ${toString cfg.port}"; Restart = "on-failure"; - # Loads your ANTHROPIC_API_KEY etc from your single Agenix file - # EnvironmentFile = config.age.secrets.opencode-secrets.path; }; environment = { OLLAMA_BASE_URL = "http://127.0.0.1:11434"; + # Important: GSD looks at ~/.config/opencode, so we ensure the server sees our /etc config OPENCODE_CONFIG = "/etc/opencode/opencode.json"; HOME = "/home/gortium"; }; diff --git a/modules/nixos/services/podman.nix b/modules/nixos/services/podman.nix index 606a611..1820040 100644 --- a/modules/nixos/services/podman.nix +++ b/modules/nixos/services/podman.nix @@ -1,9 +1,5 @@ -{ - config, - lib, - pkgs, - ... -}: +{ config, lib, pkgs, ... }: + with lib; let cfg = config.services.podman; in { diff --git a/modules/nixos/services/systemd/default.nix b/modules/nixos/services/systemd/default.nix deleted file mode 100644 index fbcaff2..0000000 --- a/modules/nixos/services/systemd/default.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ pkgs, lib, config, self, keys, paths, ... }: { - imports = - [ - ./network.nix - ./passwordmanager.nix - ./versioncontrol.nix - ./fancontrol.nix - ]; - - virtualisation.docker = { - enable = true; - daemon.settings = { - "dns" = [ "1.1.1.1" "8.8.8.8" ]; - }; - }; -} diff --git a/modules/nixos/services/systemd/fancontrol.nix b/modules/nixos/services/systemd/fancontrol.nix deleted file mode 100644 index 8b08ec9..0000000 --- a/modules/nixos/services/systemd/fancontrol.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; - -let - cfg = config.services.systemd-fancon; -in -{ - options.services.systemd-fancon = { - enable = mkEnableOption "systemd-fancon service for fan control"; - config = mkOption { - type = types.lines; - default = ""; - description = "Configuration for systemd-fancon."; - }; - }; - - config = mkIf cfg.enable { - environment.systemPackages = with pkgs; [ - systemd-fancon - lm_sensors - ]; - - boot.kernelModules = [ "amdgpu" ]; - - systemd.services.systemd-fancon = { - description = "systemd-fancon service"; - wantedBy = [ "multi-user.target" ]; - after = [ "network-online.target" ]; - serviceConfig = { - ExecStart = "${pkgs.systemd-fancon}/bin/systemd-fancon -c ${cfg.configFile}"; - Restart = "on-failure"; - }; - configFile = pkgs.writeText "systemd-fancon.conf" cfg.config; - }; - }; -} diff --git a/modules/nixos/services/systemd/network.nix b/modules/nixos/services/systemd/network.nix deleted file mode 100644 index 9db1794..0000000 --- a/modules/nixos/services/systemd/network.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ config, pkgs, self, ... }: - -let - network_compose_dir = builtins.path { - name = "network_compose_dir"; - path = self + "/assets/compose/network"; - }; -in -{ - networking.firewall.allowedTCPPorts = [ 80 443 ]; - - systemd.services.network_stack = { - description = "Traefik + DDNS updater via Docker Compose"; - after = [ "network-online.target" "docker.service" ]; - wants = [ "network-online.target" "docker.service" ]; - serviceConfig = { - WorkingDirectory = "${network_compose_dir}"; - - EnvironmentFile = config.age.secrets.containers_env.path; - - # Stop left over container by the same name - ExecStartPre = "${pkgs.bash}/bin/bash -c '${pkgs.docker-compose}/bin/docker-compose down || true'"; - - # Start the services using Docker Compose - ExecStart = "${pkgs.docker-compose}/bin/docker-compose up -d"; - - # Stop and remove containers on shutdown - ExecStop = "${pkgs.docker-compose}/bin/docker-compose down"; - - RemainAfterExit = true; - TimeoutStartSec = 0; - }; - wantedBy = [ "multi-user.target" ]; - }; -} diff --git a/modules/nixos/services/systemd/passwordmanager.nix b/modules/nixos/services/systemd/passwordmanager.nix deleted file mode 100644 index 6214475..0000000 --- a/modules/nixos/services/systemd/passwordmanager.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ config, pkgs, self, ... }: - -let - passwordmanager_compose_dir = builtins.path { - name = "passwordmanager_compose_dir"; - path = self + "/assets/compose/passwordmanager"; - }; -in -{ - systemd.services.passwordmanager_stack = { - description = "Bitwarden via Docker Compose"; - after = [ "network-online.target" "docker.service" ]; - wants = [ "network-online.target" "docker.service" ]; - serviceConfig = { - WorkingDirectory = "${passwordmanager_compose_dir}"; - - # Stop left over container by the same name - ExecStartPre = "${pkgs.bash}/bin/bash -c '${pkgs.docker-compose}/bin/docker-compose down || true'"; - - # Start the services using Docker Compose - ExecStart = "${pkgs.docker-compose}/bin/docker-compose up -d"; - - # Stop and remove containers on shutdown - ExecStop = "${pkgs.docker-compose}/bin/docker-compose down"; - - RemainAfterExit = true; - TimeoutStartSec = 0; - }; - wantedBy = [ "multi-user.target" ]; - }; -} diff --git a/modules/nixos/services/systemd/versioncontrol.nix b/modules/nixos/services/systemd/versioncontrol.nix deleted file mode 100644 index 5c64546..0000000 --- a/modules/nixos/services/systemd/versioncontrol.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ config, pkgs, self, ... }: - -let - versioncontrol_compose_dir = builtins.path { - name = "versioncontrol_compose_dir"; - path = self + "/assets/compose/versioncontrol"; - }; -in -{ - networking.firewall.allowedTCPPorts = [ 2222 ]; - - systemd.services.versioncontrol_stack = { - description = "Gitea via Docker Compose"; - after = [ "network-online.target" "docker.service" ]; - wants = [ "network-online.target" "docker.service" ]; - serviceConfig = { - WorkingDirectory = "${versioncontrol_compose_dir}"; - - # Stop left over container by the same name - ExecStartPre = "${pkgs.bash}/bin/bash -c '${pkgs.docker-compose}/bin/docker-compose down || true'"; - - # Start the services using Docker Compose - ExecStart = "${pkgs.docker-compose}/bin/docker-compose up -d"; - - # Stop and remove containers on shutdown - ExecStop = "${pkgs.docker-compose}/bin/docker-compose down"; - - RemainAfterExit = true; - TimeoutStartSec = 0; - }; - wantedBy = [ "multi-user.target" ]; - }; -}