setup codecompanion with ollama models

This commit is contained in:
♥ Minnie ♥ 2025-09-28 12:07:55 +08:00
parent 939e8a45f5
commit 2bf9f7345c
Signed by: jasmine
GPG key ID: 8563E358D4E8040E
4 changed files with 419 additions and 3 deletions

View file

@ -17,6 +17,7 @@
# Completion & AI Assistancee # Completion & AI Assistancee
./plugins/cmp/cmp.nix ./plugins/cmp/cmp.nix
./plugins/cmp/codecompanion.nix
# Editor Enhancements # Editor Enhancements
./plugins/editor/commentary.nix ./plugins/editor/commentary.nix

View file

@ -0,0 +1,196 @@
{...}: {
plugins.codecompanion = {
enable = true;
# Configuration options for CodeCompanion
settings = {
# Customize the UI of the chat buffer
display.chat.window = {
layout = "vertical";
position = "right";
width = 0.25;
};
# Setup ollama adapter for self-hosted LLM
adapters = {
http = {
"ollama:qwen2.5-coder" = {
__raw = ''
function()
return require('codecompanion.adapters').extend('ollama', {
name = "ollama:qwen2.5-coder",
env = {
url = "http://127.0.0.1:11434",
},
schema = {
model = {
default = "qwen2.5-coder:7b",
},
num_ctx = {
default = 32768,
},
},
})
end
'';
};
"ollama:deepseek-r1" = {
__raw = ''
function()
return require('codecompanion.adapters').extend('ollama', {
name = "ollama:deepseek-r1",
env = {
url = "http://127.0.0.1:11434",
},
schema = {
model = {
default = "deepseek-r1:8b",
},
num_ctx = {
default = 131072,
},
},
})
end
'';
};
"ollama:gemma3" = {
__raw = ''
function()
return require('codecompanion.adapters').extend('ollama', {
name = "ollama:gemma3",
env = {
url = "http://127.0.0.1:11434",
},
schema = {
model = {
default = "gemma3:4b",
},
num_ctx = {
default = 131072,
},
},
})
end
'';
};
"ollama:qwen3" = {
__raw = ''
function()
return require('codecompanion.adapters').extend('ollama', {
name = "ollama:qwen3",
env = {
url = "http://127.0.0.1:11434",
},
schema = {
model = {
default = "qwen3:8b",
},
num_ctx = {
default = 40960,
},
},
})
end
'';
};
"ollama:llama3" = {
__raw = ''
function()
return require('codecompanion.adapters').extend('ollama', {
name = "ollama:llama3",
env = {
url = "http://127.0.0.1:11434",
},
schema = {
model = {
default = "llama3:8b",
},
num_ctx = {
default = 8192,
},
},
})
end
'';
};
# Disable default adapters
opts.show_defaults = false;
};
acp = {
# Disable default adapters
opts.show_defaults = false;
};
};
# Global options for CodeCompanion
opts = {
log_level = "TRACE";
send_code = true;
use_default_actions = true;
use_default_prompts = true;
};
# Interaction strategies
strategies = {
agent = {
adapter = "ollama:qwen2.5-coder";
};
chat = {
adapter = "ollama:qwen2.5-coder";
};
inline = {
adapter = "ollama:qwen2.5-coder";
};
};
};
};
keymaps = [
# Main toggle for the CodeCompanion plugin
{
mode = ["n" "v"];
key = "<leader>c";
action = "<Nop>";
options = {
desc = "+companion";
};
}
# Toggle the chat buffer on/off
{
mode = ["n" "v"];
key = "<leader>cc";
action = "<cmd>CodeCompanionChat Toggle<cr>";
options = {
desc = "Toggle chat";
};
}
# Open the actions palette
{
mode = ["n" "v"];
key = "<leader>cA";
action = "<cmd>CodeCompanionActions<cr>";
options = {
desc = "Open actions palette";
};
}
# Add selected text to the chat buffer
{
mode = ["v"];
key = "<leader>ca";
action = "<cmd>CodeCompanionChat Add<cr>";
options = {
desc = "Add selected text to chat";
};
}
];
}

6
flake.lock generated
View file

@ -140,11 +140,11 @@
"systems": "systems_2" "systems": "systems_2"
}, },
"locked": { "locked": {
"lastModified": 1758931855, "lastModified": 1759016999,
"narHash": "sha256-jTmbWlOxsy9dDP3UdCB6jEO63FtkM3dQG2FOq0b4foI=", "narHash": "sha256-UhQmUPSWYpKJQutTzy9TKiRBMg/qVJn6AoNsFR+5Zmc=",
"owner": "nix-community", "owner": "nix-community",
"repo": "nixvim", "repo": "nixvim",
"rev": "e0f1e4ae4bb8762b7c51c3a514ca19664fad9c3b", "rev": "4cec67651a6dfdab9a79e68741282e3be8231a61",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -0,0 +1,219 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1756770412,
"narHash": "sha256-+uWLQZccFHwqpGqr2Yt5VsW/PbeJVTn9Dk6SHWhNRPw=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "4524271976b625a4a605beefd893f270620fd751",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-parts_2": {
"inputs": {
"nixpkgs-lib": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1756770412,
"narHash": "sha256-+uWLQZccFHwqpGqr2Yt5VsW/PbeJVTn9Dk6SHWhNRPw=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "4524271976b625a4a605beefd893f270620fd751",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"ixx": {
"inputs": {
"flake-utils": [
"nixvim",
"nuschtosSearch",
"flake-utils"
],
"nixpkgs": [
"nixvim",
"nuschtosSearch",
"nixpkgs"
]
},
"locked": {
"lastModified": 1754860581,
"narHash": "sha256-EM0IE63OHxXCOpDHXaTyHIOk2cNvMCGPqLt/IdtVxgk=",
"owner": "NuschtOS",
"repo": "ixx",
"rev": "babfe85a876162c4acc9ab6fb4483df88fa1f281",
"type": "github"
},
"original": {
"owner": "NuschtOS",
"ref": "v0.1.1",
"repo": "ixx",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1758690382,
"narHash": "sha256-NY3kSorgqE5LMm1LqNwGne3ZLMF2/ILgLpFr1fS4X3o=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "e643668fd71b949c53f8626614b21ff71a07379d",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1754788789,
"narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "a73b9c743612e4244d865a2fdee11865283c04e6",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1758763312,
"narHash": "sha256-puBMviZhYlqOdUUgEmMVJpXqC/ToEqSvkyZ30qQ09xM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e57b3b16ad8758fd681511a078f35c416a8cc939",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixvim": {
"inputs": {
"flake-parts": "flake-parts_2",
"nixpkgs": "nixpkgs_2",
"nuschtosSearch": "nuschtosSearch",
"systems": "systems_2"
},
"locked": {
"lastModified": 1758931855,
"narHash": "sha256-jTmbWlOxsy9dDP3UdCB6jEO63FtkM3dQG2FOq0b4foI=",
"owner": "nix-community",
"repo": "nixvim",
"rev": "e0f1e4ae4bb8762b7c51c3a514ca19664fad9c3b",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixvim",
"type": "github"
}
},
"nuschtosSearch": {
"inputs": {
"flake-utils": "flake-utils",
"ixx": "ixx",
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1758662783,
"narHash": "sha256-igrxT+/MnmcftPOHEb+XDwAMq3Xg1Xy7kVYQaHhPlAg=",
"owner": "NuschtOS",
"repo": "search",
"rev": "7d4c0fc4ffe3bd64e5630417162e9e04e64b27a4",
"type": "github"
},
"original": {
"owner": "NuschtOS",
"repo": "search",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"nixvim": "nixvim"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}