diff --git a/flake.lock b/flake.lock index 8ec369a..912fdce 100644 --- a/flake.lock +++ b/flake.lock @@ -315,6 +315,22 @@ "type": "github" } }, + "gen-nvim": { + "flake": false, + "locked": { + "lastModified": 1702112421, + "narHash": "sha256-oF6LT8Q6Dp4mKDNTcm/hx0F8a6iN/HvpZKgGRkctrI4=", + "owner": "David-Kunz", + "repo": "gen.nvim", + "rev": "1319b03357fd7017bbaf1d45cd6b72bd9e106226", + "type": "github" + }, + "original": { + "owner": "David-Kunz", + "repo": "gen.nvim", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ @@ -1043,6 +1059,7 @@ "disko": "disko", "flake-parts": "flake-parts", "flake-utils": "flake-utils", + "gen-nvim": "gen-nvim", "hmts-nvim": "hmts-nvim", "home-manager": "home-manager_2", "hypr-contrib": "hypr-contrib", diff --git a/flake.nix b/flake.nix index 43692cf..c1ced19 100644 --- a/flake.nix +++ b/flake.nix @@ -54,6 +54,8 @@ neotest-python.url = "github:MoritzBoehme/neotest-python/fix-runtimepath-search"; statuscol-nvim.flake = false; statuscol-nvim.url = "github:luukvbaal/statuscol.nvim/0.10"; # HACK: fix for neovim-nightly + gen-nvim.flake = false; + gen-nvim.url = "github:David-Kunz/gen.nvim"; # Hyprland hypr-contrib.url = "github:hyprwm/contrib"; diff --git a/hosts/nixos-desktop/default.nix b/hosts/nixos-desktop/default.nix index 6e23ad9..60e71f4 100644 --- a/hosts/nixos-desktop/default.nix +++ b/hosts/nixos-desktop/default.nix @@ -26,6 +26,7 @@ keyboardLayouts = [ "us" "de" ]; }; services.wallpaper.enable = true; + services.ollama.enable = true; programs.ledger.enable = true; }; diff --git a/modules/programs/nvim/plugins/coding.nix b/modules/programs/nvim/plugins/coding.nix index 12621d9..4b2526c 100644 --- a/modules/programs/nvim/plugins/coding.nix +++ b/modules/programs/nvim/plugins/coding.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ pkgs, lib, ... }: with builtins; { @@ -332,5 +332,25 @@ with builtins; }; cmd = [ "Neogen" ]; } + { + plugin = gen-nvim; + init = /* lua */ '' + require("gen").setup({ + model = "zephyr:7b-beta", -- The default model to use. + display_mode = "float", -- The display mode. Can be "float" or "split". + show_prompt = false, -- Shows the Prompt submitted to Ollama. + show_model = false, -- Displays which model you are using at the beginning of your chat session. + no_auto_close = false, -- Never closes the window automatically. + init = function(options) end, + -- Function to initialize Ollama + command = "${lib.getExe pkgs.curl} --silent --no-buffer -X POST http://localhost:11434/api/generate -d $body", + -- The command for the Ollama service. You can use placeholders $prompt, $model and $body (shellescaped). + -- This can also be a lua function returning a command string, with options as the input parameter. + -- The executed command must return a JSON object with { response, context } + -- (context property is optional). + debug = false -- Prints errors and the command which is run. + }) + ''; + } ]; } diff --git a/modules/services/ollama.nix b/modules/services/ollama.nix new file mode 100644 index 0000000..275d2c4 --- /dev/null +++ b/modules/services/ollama.nix @@ -0,0 +1,27 @@ +{ lib, config, pkgs, ... }: + +with lib; +let + cfg = config.my.services.ollama; +in +{ + options.my.services.ollama = { + enable = mkEnableOption "ollama"; + package = mkOption { + type = types.package; + default = pkgs.ollama; + }; + }; + + config = mkIf cfg.enable { + systemd.user.services.ollama = { + after = [ "network.target" ]; + serviceConfig = { + Type = "simple"; + Restart = "on-failure"; + RestartSec = "1s"; + ExecStart = "${getExe cfg.package} serve"; + }; + }; + }; +} diff --git a/overlays/vimPlugins.nix b/overlays/vimPlugins.nix index fc07f32..1a4f6c8 100644 --- a/overlays/vimPlugins.nix +++ b/overlays/vimPlugins.nix @@ -61,5 +61,11 @@ with lib.my; version = mkVersionInput inputs.neotest-python; src = inputs.neotest-python; }); + + gen-nvim = prev.vimUtils.buildVimPlugin { + pname = "gen-nvim"; + version = mkVersionInput inputs.gen-nvim; + src = inputs.gen-nvim; + }; }; }