From de6a1f4529f58441ef1028047da55e8f82efe4c0 Mon Sep 17 00:00:00 2001 From: Hadi <112569860+anotherhadi@users.noreply.github.com> Date: Sat, 1 Mar 2025 02:27:02 +0100 Subject: [PATCH] init nvf Former-commit-id: 027b2dcd24e33b514fd92d35759296e3f1225f3a --- flake.nix | 5 +- home/programs/nvf/default.nix | 15 ++ home/programs/nvf/languages/completion.nix | 10 ++ home/programs/nvf/languages/default.nix | 76 ++++++++ home/programs/nvf/mini.nix | 29 ++++ home/programs/nvf/notes/default.nix | 3 + home/programs/nvf/notes/obsidian.nix | 191 +++++++++++++++++++++ home/programs/nvf/options.nix | 60 +++++++ home/programs/nvf/snippets/default.nix | 57 ++++++ home/programs/nvf/visual.nix | 51 ++++++ 10 files changed, 495 insertions(+), 2 deletions(-) create mode 100644 home/programs/nvf/default.nix create mode 100644 home/programs/nvf/languages/completion.nix create mode 100644 home/programs/nvf/languages/default.nix create mode 100644 home/programs/nvf/mini.nix create mode 100644 home/programs/nvf/notes/default.nix create mode 100644 home/programs/nvf/notes/obsidian.nix create mode 100644 home/programs/nvf/options.nix create mode 100644 home/programs/nvf/snippets/default.nix create mode 100644 home/programs/nvf/visual.nix diff --git a/flake.nix b/flake.nix index aca35ad..694947a 100644 --- a/flake.nix +++ b/flake.nix @@ -36,11 +36,13 @@ nur.url = "github:nix-community/NUR"; zen-browser.url = "git+https://git.sr.ht/~canasta/zen-browser-flake/"; # updated flake + nvf.url = "github:notashelf/nvf"; }; outputs = inputs@{ nixpkgs, ... }: { nixosConfigurations = { - nixy = # CHANGEME: This should match the 'hostname' in your variables.nix file + nixy = + # CHANGEME: This should match the 'hostname' in your variables.nix file nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ @@ -55,7 +57,6 @@ ./hosts/laptop/configuration.nix # CHANGEME: change the path to match your host folder ]; }; - }; }; } diff --git a/home/programs/nvf/default.nix b/home/programs/nvf/default.nix new file mode 100644 index 0000000..71853c3 --- /dev/null +++ b/home/programs/nvf/default.nix @@ -0,0 +1,15 @@ +{ inputs, ... }: +{ + imports = [ + inputs.nvf.homeManagerModules.default + ./mini.nix + ./options.nix + ./languages + ./snippets + ./visual.nix + ]; + + programs.nvf = { + enable = true; + }; +} diff --git a/home/programs/nvf/languages/completion.nix b/home/programs/nvf/languages/completion.nix new file mode 100644 index 0000000..c6243b7 --- /dev/null +++ b/home/programs/nvf/languages/completion.nix @@ -0,0 +1,10 @@ +{ + programs.nvf.settings = { + vim = { + assistant.copilot.cmp.enable = true; + assistant.copilot.enable = true; + autocomplete.nvim-cmp.enable = true; + # autocomplete.nvim-cmp.setupOpts.signature.enabled = true; + }; + }; +} diff --git a/home/programs/nvf/languages/default.nix b/home/programs/nvf/languages/default.nix new file mode 100644 index 0000000..029c3aa --- /dev/null +++ b/home/programs/nvf/languages/default.nix @@ -0,0 +1,76 @@ +{ pkgs, ... }: +{ + imports = [ + ./completion.nix + ]; + + programs.nvf.settings = { + vim = { + languages = { + # Options applied to all languages + enableLSP = true; + enableFormat = true; + enableTreesitter = true; + enableExtraDiagnostics = true; + enableDAP = true; + + # Languages + nix = { + enable = true; + format = { + type = "nixfmt"; + package = pkgs.nixfmt-rfc-style; + }; + }; + markdown = { + enable = true; + lsp.enable = true; + format.type = "prettierd"; + format.enable = false; + }; + ts.enable = true; + html.enable = true; + css.enable = true; + tailwind.enable = true; + go.enable = true; + bash.enable = true; + svelte = { + enable = true; + lsp.enable = true; + treesitter.enable = true; + format.enable = true; + extraDiagnostics.enable = true; + }; + + }; + + lsp = { + formatOnSave = true; + # lspkind.enable = true; + trouble.enable = true; + # lspSignature.enable = true; + otter-nvim.enable = true; + }; + + debugger = { + nvim-dap = { + enable = true; + ui.enable = true; + }; + }; + + # startPlugins = [ pkgs.vimPlugins.nvim-treesitter.withAllGrammars ]; + + treesitter = { + enable = true; + addDefaultGrammars = true; + autotagHtml = true; + # Maybe just install every single one? + grammars = with pkgs.vimPlugins.nvim-treesitter.builtGrammars; [ + yaml # Affects obsidian note frontmatter + latex + ]; + }; + }; + }; +} diff --git a/home/programs/nvf/mini.nix b/home/programs/nvf/mini.nix new file mode 100644 index 0000000..d25dae0 --- /dev/null +++ b/home/programs/nvf/mini.nix @@ -0,0 +1,29 @@ +{ lib, ... }: +{ + programs.nvf.settings = { + vim = { + mini = { + icons.enable = true; + statusline.enable = true; + git.enable = true; + diff.enable = true; + align.enable = true; + notify.enable = true; + operators.enable = true; + starter.enable = true; + comment.enable = true; + move.enable = true; + pairs.enable = true; + splitjoin.enable = true; + bracketed.enable = true; + indentscope = { + enable = true; + setupOpts.draw.animation = lib.generators.mkLuaInline ''require("mini.indentscope").gen_animation.none()''; + }; + }; + + keymaps = [ + ]; + }; + }; +} diff --git a/home/programs/nvf/notes/default.nix b/home/programs/nvf/notes/default.nix new file mode 100644 index 0000000..0db3279 --- /dev/null +++ b/home/programs/nvf/notes/default.nix @@ -0,0 +1,3 @@ +{ + +} diff --git a/home/programs/nvf/notes/obsidian.nix b/home/programs/nvf/notes/obsidian.nix new file mode 100644 index 0000000..164c7c8 --- /dev/null +++ b/home/programs/nvf/notes/obsidian.nix @@ -0,0 +1,191 @@ +{ + lib, + util, + colorScheme', + ... +}: +let + vault_path = "notes/obsidian"; +in +{ + vim = { + notes.obsidian = { + enable = true; + setupOpts = { + mappings = [ ]; + log_level = lib.generators.mkLuaInline "vim.log.levels.ERROR"; + + workspaces = [ + { + name = "personal"; + path = "~/${vault_path}"; + } + ]; + notes_subdir = "Notes"; + attachments.img_folder = "Assets"; + daily_notes = { + folder = "Daily"; + date_format = "%Y-%m-%d"; + default_tags = [ "daily-notes" ]; + }; + + picker = { + name = "fzf-lua"; + mappings.new = ""; + mappings.insert_link = ""; + tag_mappings.tag_note = ""; + tag_mappings.insert_tag = ""; + }; + + # [[this]] type of links + preferred_link_style = "wiki"; + + disable_frontmatter = false; + note_frontmatter_func = + lib.generators.mkLuaInline # lua + '' + function (note) + if note.title then + note:add_alias(note.title) + end + + local out = { id = note.id, aliases = note.aliases, tags = note.tags } + + if not note.date then + local date = tostring(os.date("%Y-%m-%d")) + out.date = date + end + + if note.title then + out.title = note.title + end + + -- Keep existing items + if note.metadata ~= nil and not vim.tbl_isempty(note.metadata) then + for k, v in pairs(note.metadata) do + out[k] = v + end + end + + return out + end + ''; + + note_id_func = + lib.generators.mkLuaInline # lua + '' + function(title) + local name = "" + if title ~= nil then + name = title + else + -- Ask the user for a name + name = vim.fn.input("Enter note name: ") + if name == "" then + -- If no name is given, generate a random one. + for _ = 1, 5 do + name = name .. string.char(math.random(65, 90)) + end + end + end + -- transform the name into a valid file name and append the date in ISO 8601 format + local suffix = name:gsub(" ", "-"):lower():gsub("[^a-z0-9-æøå]", "") + return tostring(os.date("%Y%m%dT%H%M")) .. "-" .. suffix + end + ''; + + follow_url_func = + lib.generators.mkLuaInline # lua + '' + function(url) + vim.fn.jobstart({"wl-copy", url}) + vim.fn.jobstart({"notify-send", "Copied " .. url .. " to clipboard."}) + end + ''; + + follow_img_func = + lib.generators.mkLuaInline # lua + '' + function(url) + vim.ui.open(url) + end + ''; + + attachments = { + img_name_func = + lib.generators.mkLuaInline # lua + '' + function() + return tostring(os.date("%Y%m%dT%H%M")) .. "-" + end + ''; + }; + + ui.hl_groups = with colorScheme'; { + ObsidianTodo.fg = base0A; + ObsidianDone.fg = base0B; + ObsidianRightArrow.fg = base09; + # ObsidianTilde.fg = base0F; + # ObsidianImportant.fg = base08; + ObsidianBullet.fg = base0D; + ObsidianRefText.fg = base0E; + ObsidianExtLinkIcon.fg = base0E; + ObsidianTag.fg = base0C; + ObsidianBlockID.fg = base0C; + ObsidianHighlightText.bg = base0A; + ObsidianHighlightText.fg = base01; + }; + }; + }; + + highlight = + with colorScheme'; + lib.mapAttrs' (name: value: lib.nameValuePair "@markup.heading.${name}.markdown" { fg = value; }) { + "1" = base08; + "2" = base0A; + "3" = base0B; + "4" = base0C; + "5" = base0D; + "6" = base0E; + }; + + keymaps = [ + (util.mkKeymap "n" "od" ":ObsidianToday" "Daily note") + (util.mkKeymap "n" "oD" ":ObsidianDailies" "Daily note history") + + (util.mkKeymap "n" "oo" ":ObsidianQuickSwitch" "Open note") + (util.mkKeymap "n" "os" ":ObsidianSearch" "Search notes") + (util.mkKeymap "n" "oa" ":ObsidianOpen" "Open in app") + (util.mkKeymap "n" "or" ":ObsidianRename" "Rename note") + + (util.mkKeymap "n" "ob" ":ObsidianBacklinks" "Backlinks") + (util.mkKeymap "n" "ot" ":ObsidianTags" "Tags") + + (util.mkKeymap "n" "op" ":ObsidianPasteImg" "Paste image") + ]; + + utility.images.image-nvim = { + enable = true; + setupOpts = { + backend = "kitty"; + integrations.markdown = { + enabled = true; + only_render_image_at_cursor = true; + download_remote_images = true; + clear_in_insert_mode = true; + resolve_image_path = + lib.generators.mkLuaInline # lua + '' + function(document_path, image_path, fallback) + if string.find(document_path, "${vault_path}") then + return os.getenv("HOME") .. "/${vault_path}/" .. image_path + else + return fallback(document_path, image_path) + end + end + ''; + }; + }; + }; + }; +} diff --git a/home/programs/nvf/options.nix b/home/programs/nvf/options.nix new file mode 100644 index 0000000..c153494 --- /dev/null +++ b/home/programs/nvf/options.nix @@ -0,0 +1,60 @@ +{ + programs.nvf.settings = { + vim = { + useSystemClipboard = true; + + options = { + # 2-space indents + tabstop = 2; + softtabstop = 2; + shiftwidth = 2; + expandtab = true; + autoindent = true; + smartindent = true; + breakindent = true; + + # Searching + hlsearch = true; + incsearch = true; + ignorecase = true; + smartcase = true; + + # Splitting + splitbelow = true; + splitright = true; + + # Undo + undofile = true; + undolevels = 10000; + swapfile = false; + backup = false; + + # Disable folding + foldlevel = 99; + foldlevelstart = 99; + + # Misc + termguicolors = true; + timeoutlen = 1000; + preserveindent = true; + showmode = false; + scrolloff = 4; + conceallevel = 3; + cmdheight = 0; + sidescrolloff = 4; + cursorline = true; + linebreak = true; + wrap = false; + writebackup = false; + encoding = "utf-8"; + fileencoding = "utf-8"; + signcolumn = "yes"; + fillchars = "eob: "; # Disable the "~" chars at end of buffer + }; + + globals = { + tex_flavor = "latex"; + }; + }; + }; +} diff --git a/home/programs/nvf/snippets/default.nix b/home/programs/nvf/snippets/default.nix new file mode 100644 index 0000000..6d58230 --- /dev/null +++ b/home/programs/nvf/snippets/default.nix @@ -0,0 +1,57 @@ +{ + programs.nvf.settings = { + vim = { + snippets.luasnip = { + enable = true; + setupOpts = { + update_events = "TextChanged,TextChangedI"; + store_selection_keys = ""; + delete_check_events = "TextChanged"; + enable_autosnippets = true; + history = false; + }; + }; + + lazy.plugins.luasnip.event = "BufEnter"; + + keymaps = [ + { + mode = "i"; + key = ""; + lua = true; + expr = true; + action = # lua + '' + function() + local ls = require("luasnip") + if ls.expand_or_locally_jumpable() then + vim.schedule(function() + ls.expand_or_jump() + end) + return "" + else + return vim.api.nvim_replace_termcodes("", true, true, true) + end + end + ''; + } + { + mode = "i"; + key = ""; + lua = true; + action = # lua + '' + function() + local ls = require("luasnip") + if ls.jumpable(-1) then + vim.schedule(function() + ls.jump(-1) + end) + end + end + ''; + } + ]; + }; + }; +} diff --git a/home/programs/nvf/visual.nix b/home/programs/nvf/visual.nix new file mode 100644 index 0000000..f48d363 --- /dev/null +++ b/home/programs/nvf/visual.nix @@ -0,0 +1,51 @@ +{ config, ... }: +{ + programs.nvf.settings.vim = { + filetree.neo-tree = { + enable = true; + setupOpts = { + add_blank_line_at_top = true; + }; + }; + telescope = { + enable = true; + mappings.findFiles = " "; + }; + ui.noice.enable = true; + binds.whichKey.enable = true; + + keymaps = [ + { + key = "e"; + mode = "n"; + silent = true; + action = ":Neotree toggle"; + } + ]; + visuals = { + nvim-web-devicons.enable = true; + }; + theme = { + enable = true; + name = "base16"; + base16-colors = { + base00 = config.lib.stylix.colors.base00; + base01 = config.lib.stylix.colors.base01; + base02 = config.lib.stylix.colors.base02; + base03 = config.lib.stylix.colors.base03; + base04 = config.lib.stylix.colors.base04; + base05 = config.lib.stylix.colors.base05; + base06 = config.lib.stylix.colors.base06; + base07 = config.lib.stylix.colors.base07; + base08 = config.lib.stylix.colors.base08; + base09 = config.lib.stylix.colors.base09; + base0A = config.lib.stylix.colors.base0A; + base0B = config.lib.stylix.colors.base0B; + base0C = config.lib.stylix.colors.base0C; + base0D = config.lib.stylix.colors.base0D; + base0E = config.lib.stylix.colors.base0E; + base0F = config.lib.stylix.colors.base0F; + }; + }; + }; +}