feat: add codecompanion

This commit is contained in:
Naxdy 2025-06-04 12:13:56 +02:00
parent f0bbfc09a7
commit 97c0f8cd6d
Signed by: Naxdy
GPG key ID: CC15075846BCE91B
3 changed files with 237 additions and 97 deletions

158
flake.lock generated
View file

@ -1,5 +1,39 @@
{
"nodes": {
"crane": {
"locked": {
"lastModified": 1748970125,
"narHash": "sha256-UDyigbDGv8fvs9aS95yzFfOKkEjx1LO3PL3DsKopohA=",
"owner": "ipetkov",
"repo": "crane",
"rev": "323b5746d89e04b22554b061522dfce9e4c49b18",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": "nixpkgs_2",
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1749019266,
"narHash": "sha256-W7T6/KdLCqs4Dmpfkcs0/pAKHeIW9odWRHIUauST06M=",
"owner": "nix-community",
"repo": "fenix",
"rev": "b6378decc0543a7d64f51fcca7f5727b47812365",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
@ -39,24 +73,6 @@
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"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": [
@ -87,11 +103,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1748693115,
"narHash": "sha256-StSrWhklmDuXT93yc3GrTlb0cKSS0agTAxMGjLKAsY8=",
"lastModified": 1748929857,
"narHash": "sha256-lcZQ8RhsmhsK8u7LIFsJhsLh/pzR9yZ8yqpTzyGdj+Q=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "910796cabe436259a29a72e8d3f5e180fc6dfacc",
"rev": "c2a03962b8e24e669fb37b7df10e7c79531ff1a4",
"type": "github"
},
"original": {
@ -101,33 +117,33 @@
"type": "github"
}
},
"nixpkgs-stable": {
"nixpkgs_2": {
"locked": {
"lastModified": 1748982674,
"narHash": "sha256-NDzUbDb9SnbhVZsLji/KNzYSE9V3FZrHemqSUWsI7lM=",
"lastModified": 1748929857,
"narHash": "sha256-lcZQ8RhsmhsK8u7LIFsJhsLh/pzR9yZ8yqpTzyGdj+Q=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "1a164d9fef152d083811a975b57d46f4c9241d60",
"rev": "c2a03962b8e24e669fb37b7df10e7c79531ff1a4",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "release-24.11",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"nixpkgs_3": {
"locked": {
"lastModified": 1748406211,
"narHash": "sha256-B3BsCRbc+x/d0WiG1f+qfSLUy+oiIfih54kalWBi+/M=",
"owner": "NixOS",
"lastModified": 1747958103,
"narHash": "sha256-qmmFCrfBwSHoWw7cVK4Aj+fns+c54EBP8cGqp/yK410=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "3d1f29646e4b57ed468d60f9d286cde23a8d1707",
"rev": "fe51d34885f7b5e3e7b59572796e1bcb427eccb1",
"type": "github"
},
"original": {
"owner": "NixOS",
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
@ -136,16 +152,18 @@
"nixvim": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs_2",
"nixpkgs": [
"nixpkgs"
],
"nuschtosSearch": "nuschtosSearch",
"systems": "systems_3"
"systems": "systems_2"
},
"locked": {
"lastModified": 1748942960,
"narHash": "sha256-gJf3WxvDbvCpzIBVju/5GY/olW7zs/B1zDmB52AWMUM=",
"lastModified": 1749028068,
"narHash": "sha256-ebxyRA7rK6Jb3eXvz+0QcyKLHzUnUQWRFDbKleLdLZ8=",
"owner": "nix-community",
"repo": "nixvim",
"rev": "9328f4437d5f788d1c066b274a0aea492dc5fde2",
"rev": "1d8724144cef98dad6638e0b6333cc84d0b2f5c3",
"type": "github"
},
"original": {
@ -156,7 +174,7 @@
},
"nuschtosSearch": {
"inputs": {
"flake-utils": "flake-utils_2",
"flake-utils": "flake-utils",
"ixx": "ixx",
"nixpkgs": [
"nixvim",
@ -179,10 +197,49 @@
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"nixpkgs-stable": "nixpkgs-stable",
"nixvim": "nixvim"
"nixvim": "nixvim",
"sscli": "sscli"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1748931088,
"narHash": "sha256-OqpRHL9wdrOjmC7eWIOdDC64n96dN1uTokJA6dsCuWs=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "cf969d21c30fed7eac32d9e485dca4b39df826f8",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"sscli": {
"inputs": {
"crane": "crane",
"fenix": "fenix",
"nixpkgs": [
"nixpkgs"
],
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1749023626,
"narHash": "sha256-+EDj3YM+sraJQERSzUyf8Ke4M30hOC41JcvrN+IJIiI=",
"owner": "Naxdy",
"repo": "sscli",
"rev": "bdc177bbe0a0a3197ab82d6893eddc1140a7fc74",
"type": "github"
},
"original": {
"owner": "Naxdy",
"repo": "sscli",
"type": "github"
}
},
"systems": {
@ -215,18 +272,21 @@
"type": "github"
}
},
"systems_3": {
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"lastModified": 1748243702,
"narHash": "sha256-9YzfeN8CB6SzNPyPm2XjRRqSixDopTapaRsnTpXUEY8=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "1f3f7b784643d488ba4bf315638b2b0a4c5fb007",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}

View file

@ -3,65 +3,69 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
nixpkgs-stable.url = "github:nixos/nixpkgs?ref=release-24.11";
flake-utils.url = "github:numtide/flake-utils";
nixvim = {
url = "github:nix-community/nixvim";
inputs.nixpkgs.follows = "nixpkgs";
};
nixvim.url = "github:nix-community/nixvim";
sscli = {
url = "github:Naxdy/sscli";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
nixpkgs-stable,
flake-utils,
nixvim,
sscli,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlays.default
];
};
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
in
{
packages = {
forEachSupportedSystem =
f:
nixpkgs.lib.genAttrs supportedSystems (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlays.default
];
};
in
f {
inherit system pkgs;
}
);
in
{
packages = forEachSupportedSystem (
{ pkgs, system, ... }:
{
default = self.packages.${system}.naxvim;
naxvim = pkgs.naxvim;
};
}
)
// {
}
);
overlays.default = self.overlays.naxvim;
overlays.naxvim =
final: prev:
(
let
pkgs-stable = import nixpkgs-stable {
system = final.hostPlatform.system;
};
in
{
naxvim = final.callPackage ./package.nix { };
nodePackages =
# TODO: graphql-language-service-cli is currently missing in nixos unstable
if !(prev.nodePackages ? graphql-language-service-cli) then
(
prev.nodePackages
// {
inherit (pkgs-stable.nodePackages) graphql-language-service-cli;
}
)
else
prev.nodePackages;
naxvim = final.callPackage ./package.nix {
sscli = sscli.packages.${final.system}.default;
};
}
// (nixvim.overlays.default final prev)
);

View file

@ -16,6 +16,9 @@
gdb,
inferno,
luau-lsp,
sscli,
codecompanionUrl ? null,
codecompanionModel ? null,
}:
let
js-i18n = vimUtils.buildVimPlugin {
@ -628,7 +631,7 @@ nixvim.makeNixvim {
gh-dash
gh
luau-lsp
];
] ++ (lib.optional (codecompanionUrl != null) sscli);
# extraFiles = {
# "queries/rust/highlights.scm".text = ''
@ -700,6 +703,87 @@ nixvim.makeNixvim {
];
plugins = {
codecompanion = lib.mkIf (codecompanionUrl != null) {
enable = true;
settings = {
strategies = {
chat.adapter = "naxllm";
inline.adapter = "naxllm";
cmd.adapter = "naxllm";
};
adapters = {
naxllm = {
__raw = ''
function()
return require('codecompanion.adapters').extend('openai_compatible', {
env = {
url = "${codecompanionUrl}",
api_key = "cmd:sscli get-entry --props xdg:schema=org.naxdy.llm",
chat_url = "/v1/chat/completions",
models_endpoint = "/v1/moels",
},
schema = {
model = {
default = "${codecompanionModel}"
}
},
temperature = {
order = 2,
mapping = "parameters",
type = "number",
optional = true,
default = 0.8,
desc = "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both.",
validate = function(n)
return n >= 0 and n <= 2, "Must be between 0 and 2"
end,
},
max_completion_tokens = {
order = 3,
mapping = "parameters",
type = "integer",
optional = true,
default = nil,
desc = "An upper bound for the number of tokens that can be generated for a completion.",
validate = function(n)
return n > 0, "Must be greater than 0"
end,
},
stop = {
order = 4,
mapping = "parameters",
type = "string",
optional = true,
default = nil,
desc = "Sets the stop sequences to use. When this pattern is encountered the LLM will stop generating text and return. Multiple stop patterns may be set by specifying multiple separate stop parameters in a modelfile.",
validate = function(s)
return s:len() > 0, "Cannot be an empty string"
end,
},
logit_bias = {
order = 5,
mapping = "parameters",
type = "map",
optional = true,
default = nil,
desc = "Modify the likelihood of specified tokens appearing in the completion. Maps tokens (specified by their token ID) to an associated bias value from -100 to 100. Use https://platform.openai.com/tokenizer to find token IDs.",
subtype_key = {
type = "integer",
},
subtype = {
type = "integer",
validate = function(n)
return n >= -100 and n <= 100, "Must be between -100 and 100"
end,
},
},
})
end
'';
};
};
};
};
spectre = {
enable = true;
};
@ -826,14 +910,6 @@ nixvim.makeNixvim {
];
};
spec = whichKeySpec;
# spec = [
# {
# __unkeyed-1 = "<leader>e";
# __unkeyed-2 = "<cmd>NvimTreeToggle<CR>";
# desc = "Explorer";
# mode = [ "n" "v" ];
# }
# ];
};
};
nvim-tree = {