Compare commits

..

5 Commits

8 changed files with 59 additions and 304 deletions

View File

@ -71,27 +71,6 @@
"type": "github"
}
},
"codeium-nvim": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1693966170,
"narHash": "sha256-maRkkUCzjSXK04ts+Io0WFBV1MxR7dCw8I6TV03Dpbs=",
"owner": "jcdickinson",
"repo": "codeium.nvim",
"rev": "6a8cbce54c41e0c305b5f77721f61b2ddd4b6c6d",
"type": "github"
},
"original": {
"owner": "jcdickinson",
"repo": "codeium.nvim",
"type": "github"
}
},
"darwin": {
"inputs": {
"nixpkgs": [
@ -224,21 +203,6 @@
}
},
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems"
},
@ -256,7 +220,7 @@
"type": "github"
}
},
"flake-utils_3": {
"flake-utils_2": {
"inputs": {
"systems": "systems_3"
},
@ -274,7 +238,7 @@
"type": "github"
}
},
"flake-utils_4": {
"flake-utils_3": {
"inputs": {
"systems": "systems_4"
},
@ -566,7 +530,7 @@
},
"neovim-flake": {
"inputs": {
"flake-utils": "flake-utils_3",
"flake-utils": "flake-utils_2",
"nixpkgs": [
"neovim-nightly-overlay",
"nixpkgs"
@ -634,6 +598,21 @@
"type": "github"
}
},
"nix-lazy-nvim": {
"locked": {
"lastModified": 1694868321,
"narHash": "sha256-LHPQkD+7ltdo77gpFQOnr8QAgYPdtFf9pm/Alwrs570=",
"ref": "refs/heads/main",
"rev": "1dc6361600111b1c46f6e85221334c8c47f88200",
"revCount": 4,
"type": "git",
"url": "https://git.moritzboeh.me/moritz/NixLazy.nvim"
},
"original": {
"type": "git",
"url": "https://git.moritzboeh.me/moritz/NixLazy.nvim"
}
},
"nix-super": {
"inputs": {
"flake-compat": "flake-compat_2",
@ -855,7 +834,7 @@
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat_3",
"flake-utils": "flake-utils_4",
"flake-utils": "flake-utils_3",
"gitignore": "gitignore",
"nixpkgs": "nixpkgs_7",
"nixpkgs-stable": "nixpkgs-stable"
@ -897,8 +876,7 @@
"agenix": "agenix",
"arkenfox-userjs": "arkenfox-userjs",
"asus-touchpad-numpad-driver": "asus-touchpad-numpad-driver",
"codeium-nvim": "codeium-nvim",
"flake-utils": "flake-utils_2",
"flake-utils": "flake-utils",
"hmts-nvim": "hmts-nvim",
"home-manager": "home-manager_2",
"hypr-contrib": "hypr-contrib",
@ -907,6 +885,7 @@
"master": "master",
"neovim-nightly-overlay": "neovim-nightly-overlay",
"nil": "nil",
"nix-lazy-nvim": "nix-lazy-nvim",
"nix-super": "nix-super",
"nixpkgs": "nixpkgs_6",
"nvim-treesitter": "nvim-treesitter",

View File

@ -53,8 +53,7 @@
actions-preview-nvim.flake = false;
actions-preview-nvim.url = "github:aznhe21/actions-preview.nvim";
codeium-nvim.url = "github:jcdickinson/codeium.nvim";
codeium-nvim.inputs.nixpkgs.follows = "nixpkgs";
nix-lazy-nvim.url = "git+https://git.moritzboeh.me/moritz/NixLazy.nvim";
# Hyprland
hypr-contrib.url = "github:hyprwm/contrib";
@ -127,6 +126,7 @@
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = { inherit inputs self; };
sharedModules = [ inputs.nix-lazy-nvim.homeManagerModules.default ];
};
}
inputs.agenix.nixosModules.age

View File

@ -3,242 +3,11 @@
with lib;
let
cfg = config.my.programs.nvim;
toLua = value: with builtins;
if value == null then "nil" else
if isBool value then boolToString value else
if isInt value || isFloat value then toString value else
if isString value then string value else
if isAttrs value then attrs value else
if isList value then list value else
abort "should never happen (value = ${value})";
string = str: ''"${toString str}"'';
attrs = set:
let
toKeyword = name: value: "${name} = ${toLua value}";
keywords = concatStringsSep ", " (mapAttrsToList toKeyword set);
in
"{ " + keywords + " }";
listContent = values: concatStringsSep ", " (map toLua values);
list = values: "{ " + listContent values + " }";
luaList = values: "{" + (concatStringsSep ", " values) + "}";
keybinding = { key, cmd, func, mode, desc }:
let
cmdString =
if cmd != null then toLua cmd else
if func != null then func else
abort "Either cmd or function must be set";
descString = optionalString (desc != null) "desc = ${toLua desc},";
in
''{ ${toLua key}, ${cmdString}, mode = ${toLua mode}, ${descString} }'';
lazySpecFromPlugin =
{ cmd
, conf
, dependencies
, enabled
, event
, ft
, init
, keys
, lazy
, opts
, plugin
, priority
}:
luaList
([
"dir = ${string plugin}"
"name = ${toLua (getName plugin)}"
]
++ (optional (opts != null) "opts = ${toLua opts}")
++ (optional (lazy != null) "lazy = ${toLua lazy}")
++ (optional (!enabled) "enabled = ${toLua enabled}")
++ (optional (dependencies != [ ]) "dependencies = ${luaList (map lazySpecFromPlugin dependencies)}")
++ (optional (init != null) "init = function(plugin)\n${init}\nend")
++ (optional (conf != null) "config = function(plugin, opts)\n${conf}\nend")
++ (optional (keys != [ ]) "keys = ${luaList (map keybinding keys)}")
++ (optional (event != [ ]) "event = ${toLua event}")
++ (optional (cmd != [ ]) "cmd = ${toLua cmd}")
++ (optional (ft != [ ]) "ft = ${toLua ft}")
++ (optional (priority != null) "priority = ${toLua priority}")
);
lazySpecs = luaList (map lazySpecFromPlugin cfg.plugins);
lazy = /* lua */ ''
require("lazy").setup(${lazySpecs})
'';
initLua =
let
text = lib.concatLines [ (builtins.readFile ./options.lua) lazy ];
in
pkgs.runCommand "init.lua" { inherit text; } ''
touch $out
echo -n "$text" > $out
${getExe pkgs.stylua} $out
'';
in
{
imports = lib.my.listModulesRec ./plugins;
options.my.programs.nvim = {
enable = mkEnableOption "nvim";
plugins = mkOption {
default = [ ];
description = ''
List of plugins with config.
'';
type = with types; listOf (
let
sub = submodule {
options = {
conf = mkOption {
type = nullOr str;
default = null;
description = ''
Lua function to be executed when the plugin is loaded.
'';
};
opts = mkOption {
type =
let
valueType = nullOr
(oneOf [
str
bool
int
float
(listOf valueType)
(attrsOf valueType)
]) // {
description = "Lua value";
};
in
nullOr (attrsOf valueType);
default = null;
description = ''
Lua table to be passed to te plugin config function.
'';
};
dependencies = mkOption {
type = listOf sub;
default = [ ];
description = ''
List of plugins this plugin depends on.
'';
};
init = mkOption {
type = nullOr str;
default = null;
description = ''
Lua code to be executed when the plugin is initialized.
'';
};
event = mkOption {
type = listOf str;
default = [ ];
description = ''
Event to load the plugin on.
'';
};
lazy = mkOption {
type = nullOr bool;
default = null;
description = ''
Whether to load the plugin lazily.
'';
};
plugin = mkOption {
type = package;
description = ''
The plugin package.
'';
};
enabled = mkOption {
type = bool;
default = true;
description = ''
Whether to enable the plugin.
'';
};
cmd = mkOption {
type = listOf str;
default = [ ];
description = ''
Command to load the plugin.
'';
};
ft = mkOption {
type = listOf str;
default = [ ];
description = ''
Filetype to load the plugin on.
'';
};
priority = mkOption {
type = nullOr int;
default = null;
description = ''
Priority to load the plugin.
'';
};
keys = mkOption {
default = [ ];
description = ''
List of keybindings.
'';
type = listOf (submodule {
options = {
key = mkOption {
type = str;
description = ''
Key to bind.
'';
};
cmd = mkOption {
type = nullOr str;
default = null;
description = ''
Command to execute.
'';
};
func = mkOption {
type = nullOr str;
default = null;
description = ''
Function to execute.
'';
};
mode = mkOption {
type = listOf str;
default = [ "n" ];
description = ''
Mode to bind the key in.
'';
};
desc = mkOption {
type = nullOr str;
default = null;
description = ''
Description of the keybinding.
'';
};
};
});
};
};
};
in
sub
);
};
};
options.my.programs.nvim.enable = mkEnableOption "nvim";
config = mkIf cfg.enable {
home-manager.users.moritz = {
@ -250,8 +19,6 @@ in
)
];
xdg.configFile."nvim/init.lua".source = initLua;
programs.neovim = {
enable = true;
package = pkgs.neovim-nightly;
@ -259,14 +26,6 @@ in
vimdiffAlias = true;
withNodeJs = true;
withPython3 = true;
extraPython3Packages = ps:
let
plugins = map (getAttr "plugin") cfg.plugins;
depAttrName = "python3Dependencies";
filtered = filter (hasAttr depAttrName) plugins;
funcs = map (getAttr depAttrName) filtered;
in
foldl (list: f: list ++ (f ps)) [ ] funcs;
extraPackages = with pkgs;
[
alejandra
@ -288,9 +47,8 @@ in
typst-lsp
yamlfmt
];
plugins = [
pkgs.vimPlugins.lazy-nvim
];
extraLuaConfig = readFile ./options.lua;
lazy.enable = true;
};
};
};

View File

@ -1,8 +1,8 @@
{ pkgs, ... }:
{ pkgs, lib, ... }:
with builtins;
{
config.my.programs.nvim.plugins = with pkgs.vimPlugins; [
config.home-manager.users.moritz.programs.neovim.lazy.plugins = with pkgs.vimPlugins; [
{
plugin = formatter-nvim;
cmd = [ "Format" "Fmt" ];
@ -86,13 +86,26 @@ with builtins;
{ plugin = cmp-cmdline; }
{ plugin = cmp-nvim-lsp; }
{ plugin = cmp_luasnip; }
{
plugin = codeium-nvim;
opts = { };
}
{ plugin = friendly-snippets; }
{ plugin = lspkind-nvim; }
{ plugin = luasnip; }
{
plugin = copilot-cmp;
opts = { };
dependencies = [
{
plugin = copilot-lua;
opts = {
suggestion = { enabled = false; };
panel = { enabled = false; };
};
conf = /* lua */ ''
require("copilot").setup(opts)
vim.cmd("Copilot disable")
'';
}
];
}
];
}
{
@ -192,7 +205,6 @@ with builtins;
];
dependencies = [
{ plugin = plenary-nvim; }
{ plugin = which-key-nvim; }
{ plugin = telescope-fzf-native-nvim; }
];
}

View File

@ -2,6 +2,14 @@ local cmp = require("cmp")
local luasnip = require("luasnip")
require("luasnip.loaders.from_vscode").lazy_load()
local has_words_before = function()
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
return false
end
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil
end
cmp.setup({
formatting = {
format = require("lspkind").cmp_format({
@ -9,7 +17,7 @@ cmp.setup({
maxwidth = 50, -- prevent the popup from showing more than provided characters
ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead
symbol_map = {
Codeium = "",
Copilot = "",
},
}),
},
@ -26,8 +34,8 @@ cmp.setup({
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
if cmp.visible() and has_words_before() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
@ -48,7 +56,7 @@ cmp.setup({
{ name = "async_path", priority = 1 },
{ name = "buffer", priority = 1 },
{ name = "luasnip", priority = 2 },
{ name = "codeium", priority = 3 },
{ name = "copilot", group_index = 3 },
{ name = "nvim_lsp", priority = 4 },
},
})

View File

@ -2,7 +2,7 @@
with builtins;
{
config.my.programs.nvim.plugins = with pkgs.vimPlugins; [
config.home-manager.users.moritz.programs.neovim.lazy.plugins = with pkgs.vimPlugins; [
{
plugin = nvim-treesitter;
event = [ "BufReadPost" "BufNewFile" ];

View File

@ -2,7 +2,7 @@
with builtins;
{
config.my.programs.nvim.plugins = with pkgs.vimPlugins; [
config.home-manager.users.moritz.programs.neovim.lazy.plugins = with pkgs.vimPlugins; [
{
plugin = which-key-nvim;
lazy = false;

View File

@ -4,8 +4,6 @@ _: prev:
with lib.my;
{
vimPlugins = prev.vimPlugins // {
inherit (inputs.codeium-nvim.packages.${prev.system}.vimPlugins) codeium-nvim;
smartcolumn-nvim = prev.vimUtils.buildVimPluginFrom2Nix {
pname = "smartcolumn-nvim";
version = mkVersionInput inputs.smartcolumn-nvim;