From e46d874e51e67ffb04d620ffea8332f140696652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 13 Aug 2024 12:44:43 +0200 Subject: [PATCH] fix(home-manager): copy over nixvim configuration --- nixos/nixvim/README.md | 17 ++ nixos/nixvim/config/bufferline.nix | 5 + nixos/nixvim/config/clipboard.nix | 6 + nixos/nixvim/config/cmp.nix | 19 ++ nixos/nixvim/config/dap.nix | 188 +++++++++++++++++ nixos/nixvim/config/default.nix | 29 +++ nixos/nixvim/config/lsp.nix | 32 +++ nixos/nixvim/config/lualine.nix | 5 + nixos/nixvim/config/nix.nix | 3 + nixos/nixvim/config/oil.nix | 5 + nixos/nixvim/config/options.nix | 22 ++ nixos/nixvim/config/telescope.nix | 62 ++++++ nixos/nixvim/config/toggleterm.nix | 8 + nixos/nixvim/config/treesitter.nix | 5 + nixos/nixvim/config/which-key.nix | 3 + nixos/nixvim/flake.lock | 327 +++++++++++++++++++++++++++++ nixos/nixvim/flake.nix | 47 +++++ 17 files changed, 783 insertions(+) create mode 100644 nixos/nixvim/README.md create mode 100644 nixos/nixvim/config/bufferline.nix create mode 100644 nixos/nixvim/config/clipboard.nix create mode 100644 nixos/nixvim/config/cmp.nix create mode 100644 nixos/nixvim/config/dap.nix create mode 100644 nixos/nixvim/config/default.nix create mode 100644 nixos/nixvim/config/lsp.nix create mode 100644 nixos/nixvim/config/lualine.nix create mode 100644 nixos/nixvim/config/nix.nix create mode 100644 nixos/nixvim/config/oil.nix create mode 100644 nixos/nixvim/config/options.nix create mode 100644 nixos/nixvim/config/telescope.nix create mode 100644 nixos/nixvim/config/toggleterm.nix create mode 100644 nixos/nixvim/config/treesitter.nix create mode 100644 nixos/nixvim/config/which-key.nix create mode 100644 nixos/nixvim/flake.lock create mode 100644 nixos/nixvim/flake.nix diff --git a/nixos/nixvim/README.md b/nixos/nixvim/README.md new file mode 100644 index 0000000..bff36b7 --- /dev/null +++ b/nixos/nixvim/README.md @@ -0,0 +1,17 @@ +# Nixvim template + +This template gives you a good starting point for configuring nixvim standalone. + +## Configuring + +To start configuring, just add or modify the nix files in `./config`. +If you add a new configuration file, remember to add it to the +[`config/default.nix`](./config/default.nix) file + +## Testing your new configuration + +To test your configuration simply run the following command + +``` +nix run . +``` diff --git a/nixos/nixvim/config/bufferline.nix b/nixos/nixvim/config/bufferline.nix new file mode 100644 index 0000000..fe5cf05 --- /dev/null +++ b/nixos/nixvim/config/bufferline.nix @@ -0,0 +1,5 @@ +{ + plugins.bufferline = { + enable = true; + }; +} diff --git a/nixos/nixvim/config/clipboard.nix b/nixos/nixvim/config/clipboard.nix new file mode 100644 index 0000000..2dd2be8 --- /dev/null +++ b/nixos/nixvim/config/clipboard.nix @@ -0,0 +1,6 @@ +{ + clipboard = { + providers.xsel.enable = true; + register = "unnamedplus"; + }; +} diff --git a/nixos/nixvim/config/cmp.nix b/nixos/nixvim/config/cmp.nix new file mode 100644 index 0000000..a2fd9c4 --- /dev/null +++ b/nixos/nixvim/config/cmp.nix @@ -0,0 +1,19 @@ +{ + plugins.cmp = { + enable = true; + autoEnableSources = true; + settings = { + sources = [ + { name = "nvim_lsp"; } + { name = "path"; } + { name = "buffer"; } + ]; + + mapping = { + "" = "cmp.mapping.confirm({ select = true })"; + "" = "cmp.mapping(cmp.mapping.select_next_item({'i', 's'}))"; + "" = "cmp.mapping(cmp.mapping.select_prev_item({'i', 's'}))"; + }; + }; + }; +} diff --git a/nixos/nixvim/config/dap.nix b/nixos/nixvim/config/dap.nix new file mode 100644 index 0000000..9d1235c --- /dev/null +++ b/nixos/nixvim/config/dap.nix @@ -0,0 +1,188 @@ +{ + plugins.dap = { + enable = true; + extensions = { + dap-ui.enable = true; + dap-virtual-text.enable = true; + }; + adapters = { + executables = { + gdb = { + command = "gdb"; + args = [ "-i" "dap" ]; + }; + }; + }; + configurations = { + c = [ + { + name = "Launch"; + type = "gdb"; + request = "launch"; + program.__raw = # lua + '' + function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. '/', "file") + end + ''; + args.__raw = # lua + '' + function() + return vim.fn.input("Args: ", "", "file") + end + ''; + cwd = ''''${workspacefolder}''; + stopOnEntry = false; + } + ]; + }; + }; + + keymaps = [ + { + mode = "n"; + key = "db"; + action = ":DapToggleBreakpoint"; + options.desc = "Toggle Breakpoint"; + } + { + mode = "n"; + key = "dc"; + action = ":DapContinue"; + options.desc = "Continue"; + } + { + mode = "n"; + key = "da"; + action = "lua require('dap').continue({ before = get_args })"; + options = { + silent = true; + desc = "Run with Args"; + }; + } + { + mode = "n"; + key = "dC"; + action = "lua require('dap').run_to_cursor()"; + options = { + silent = true; + desc = "Run to cursor"; + }; + } + { + mode = "n"; + key = "dg"; + action = "lua require('dap').goto_()"; + options = { + silent = true; + desc = "Go to line (no execute)"; + }; + } + { + mode = "n"; + key = "di"; + action = ":DapStepInto"; + options = { + silent = true; + desc = "Step into"; + }; + } + { + mode = "n"; + key = "dj"; + action = " + lua require('dap').down() + "; + options = { + silent = true; + desc = "Down"; + }; + } + { + mode = "n"; + key = "dk"; + action = "lua require('dap').up()"; + options = { + silent = true; + desc = "Up"; + }; + } + { + mode = "n"; + key = "dl"; + action = "lua require('dap').run_last()"; + options = { + silent = true; + desc = "Run Last"; + }; + } + { + mode = "n"; + key = "do"; + action = ":DapStepOut"; + options = { + silent = true; + desc = "Step Out"; + }; + } + { + mode = "n"; + key = "dO"; + action = ":DapStepOver"; + options = { + silent = true; + desc = "Step Over"; + }; + } + { + mode = "n"; + key = "dp"; + action = "lua require('dap').pause()"; + options = { + silent = true; + desc = "Pause"; + }; + } + { + mode = "n"; + key = "dr"; + action = ":DapToggleRepl"; + options = { + silent = true; + desc = "Toggle REPL"; + }; + } + { + mode = "n"; + key = "ds"; + action = "lua require('dap').session()"; + options = { + silent = true; + desc = "Session"; + }; + } + { + mode = "n"; + key = "dt"; + action = ":DapTerminate"; + options = { + silent = true; + desc = "Terminate"; + }; + } + { + mode = "n"; + key = "du"; + action.__raw = # lua + '' + function() + require("dapui").toggle() + end + ''; + options = { + desc = "Toggle Debugger UI"; + silent = true; + }; + } + ]; +} diff --git a/nixos/nixvim/config/default.nix b/nixos/nixvim/config/default.nix new file mode 100644 index 0000000..cc4e38b --- /dev/null +++ b/nixos/nixvim/config/default.nix @@ -0,0 +1,29 @@ +{ + # Import all your configuration modules here + imports = [ + # base config + ./options.nix + ./clipboard.nix + + # appearence + ./bufferline.nix + ./lualine.nix + ./which-key.nix + ./toggleterm.nix + + # file and search utilities + ./telescope.nix + ./oil.nix + + # language support & lsp + ./lsp.nix + ./treesitter.nix + ./nix.nix + + # debugging + ./dap.nix + + # autocompletion + ./cmp.nix + ]; +} diff --git a/nixos/nixvim/config/lsp.nix b/nixos/nixvim/config/lsp.nix new file mode 100644 index 0000000..87a9b22 --- /dev/null +++ b/nixos/nixvim/config/lsp.nix @@ -0,0 +1,32 @@ +{ + plugins.lsp = { + enable = true; + inlayHints = true; + servers = { + nixd.enable = true; + cssls.enable = true; + html.enable = true; + rust-analyzer = { + enable = true; + installRustc = true; + installCargo = true; + }; + bashls.enable = true; + clangd.enable = true; + }; + keymaps = { + diagnostic = { + "" = "goto_next"; + "" = "goto_prev"; + }; + lspBuf = { + "K" = "hover"; + "gD" = "references"; + "gd" = "definition"; + "gi" = "implementation"; + "gt" = "type_definition"; + "" = "code_action"; + }; + }; + }; +} diff --git a/nixos/nixvim/config/lualine.nix b/nixos/nixvim/config/lualine.nix new file mode 100644 index 0000000..015eb2a --- /dev/null +++ b/nixos/nixvim/config/lualine.nix @@ -0,0 +1,5 @@ +{ + plugins.lualine = { + enable = true; + }; +} diff --git a/nixos/nixvim/config/nix.nix b/nixos/nixvim/config/nix.nix new file mode 100644 index 0000000..ba302bf --- /dev/null +++ b/nixos/nixvim/config/nix.nix @@ -0,0 +1,3 @@ +{ + plugins.nix.enable = true; +} diff --git a/nixos/nixvim/config/oil.nix b/nixos/nixvim/config/oil.nix new file mode 100644 index 0000000..101ea6e --- /dev/null +++ b/nixos/nixvim/config/oil.nix @@ -0,0 +1,5 @@ +{ + plugins.oil = { + enable = true; + }; +} diff --git a/nixos/nixvim/config/options.nix b/nixos/nixvim/config/options.nix new file mode 100644 index 0000000..d6edf76 --- /dev/null +++ b/nixos/nixvim/config/options.nix @@ -0,0 +1,22 @@ +{ + opts = { + number = true; + }; + + globals.mapleader = " "; + + performance.byteCompileLua = { + enable = true; + nvimRuntime = true; + plugins = true; + }; + + performance.combinePlugins = { + enable = true; + standalonePlugins = [ + "hmts.nvim" + "nvim-treesitter" + "vimplugin-treesitter-grammar-nix" + ]; + }; +} diff --git a/nixos/nixvim/config/telescope.nix b/nixos/nixvim/config/telescope.nix new file mode 100644 index 0000000..d31a96f --- /dev/null +++ b/nixos/nixvim/config/telescope.nix @@ -0,0 +1,62 @@ +{ + plugins.telescope = { + enable = true; + extensions.file-browser = { + enable = true; + # explanation: see :help expand + # % is current file path, :p is full, :h is head (last component removed) + settings.cwd.__raw = "'%:p:h'"; + }; + settings.defaults.mappings = { + i = { + # close telescope when escape pressed in insert mode + "" = "close"; + }; + }; + keymaps = { + # files + "" = { + action = "find_files"; + options = { + desc = "Find files in current directory"; + }; + }; + "ff" = { + action = "file_browser"; + options = { + desc = "Find files in current directory"; + }; + }; + "fr" = { + action = "oldfiles"; + options = { + desc = "Recent files"; + }; + }; + + # search + "/" = { + action = "live_grep"; + options = { + desc = "Grep (root dir)"; + }; + }; + + # buffers + "b" = { + action = "buffers"; + options = { + desc = "Buffer list"; + }; + }; + + # lsp + "sD" = { + action = "diagnostics"; + options = { + desc = "Workspace diagnostics"; + }; + }; + }; + }; +} diff --git a/nixos/nixvim/config/toggleterm.nix b/nixos/nixvim/config/toggleterm.nix new file mode 100644 index 0000000..c79c06c --- /dev/null +++ b/nixos/nixvim/config/toggleterm.nix @@ -0,0 +1,8 @@ +{ + plugins.toggleterm = { + enable = true; + settings = { + open_mapping = "[[]]"; + }; + }; +} diff --git a/nixos/nixvim/config/treesitter.nix b/nixos/nixvim/config/treesitter.nix new file mode 100644 index 0000000..d15124b --- /dev/null +++ b/nixos/nixvim/config/treesitter.nix @@ -0,0 +1,5 @@ +{ + plugins.treesitter = { + enable = true; + }; +} diff --git a/nixos/nixvim/config/which-key.nix b/nixos/nixvim/config/which-key.nix new file mode 100644 index 0000000..6d02309 --- /dev/null +++ b/nixos/nixvim/config/which-key.nix @@ -0,0 +1,3 @@ +{ + plugins.which-key.enable = true; +} diff --git a/nixos/nixvim/flake.lock b/nixos/nixvim/flake.lock new file mode 100644 index 0000000..8ecff89 --- /dev/null +++ b/nixos/nixvim/flake.lock @@ -0,0 +1,327 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722113426, + "narHash": "sha256-Yo/3loq572A8Su6aY5GP56knpuKYRvM2a1meP9oJZCw=", + "owner": "numtide", + "repo": "devshell", + "rev": "67cce7359e4cd3c45296fb4aaf6a19e2a9c757ae", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-compat": { + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "revCount": 57, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_2": { + "inputs": { + "nixpkgs-lib": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": [ + "nixvim", + "flake-compat" + ], + "gitignore": "gitignore", + "nixpkgs": [ + "nixvim", + "nixpkgs" + ], + "nixpkgs-stable": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1721042469, + "narHash": "sha256-6FPUl7HVtvRHCCBQne7Ylp4p+dpP3P/OYuzjztZ4s70=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "f451c19376071a90d8c58ab1a953c6e9840527fd", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "nixvim", + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722407237, + "narHash": "sha256-wcpVHUc2nBSSgOM7UJSpcRbyus4duREF31xlzHV5T+A=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "58cef3796271aaeabaed98884d4abaab5d9d162d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722082646, + "narHash": "sha256-od8dBWVP/ngg0cuoyEl/w9D+TCNDj6Kh4tr151Aax7w=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "0413754b3cdb879ba14f6e96915e5fdf06c6aab6", + "type": "github" + }, + "original": { + "owner": "lnl7", + "repo": "nix-darwin", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1721924956, + "narHash": "sha256-Sb1jlyRO+N8jBXEX9Pg9Z1Qb8Bw9QyOgLDNMEpmjZ2M=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5ad6a14c6bf098e98800b091668718c336effc95", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1719876945, + "narHash": "sha256-Fm2rDDs86sHy0/1jxTOKB1118Q0O3Uc7EC0iXvXKpbI=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1722185531, + "narHash": "sha256-veKR07psFoJjINLC8RK4DiLniGGMgF3QMlS4tb74S6k=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "52ec9ac3b12395ad677e8b62106f0b98c1f8569d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixvim": { + "inputs": { + "devshell": "devshell", + "flake-compat": "flake-compat", + "flake-parts": "flake-parts_2", + "git-hooks": "git-hooks", + "home-manager": "home-manager", + "nix-darwin": "nix-darwin", + "nixpkgs": "nixpkgs_2", + "nuschtosSearch": "nuschtosSearch", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1722492816, + "narHash": "sha256-aZe7oSm/+GM1whS6bxZy+DJgbcy8rDIkygBA0owCvmU=", + "owner": "nix-community", + "repo": "nixvim", + "rev": "820f8d58eafd7121989fea3ae9e71f29699d856b", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixvim", + "type": "github" + } + }, + "nuschtosSearch": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722144272, + "narHash": "sha256-olZbfaEdd+zNPuuyYcYGaRzymA9rOmth8yXOlVm+LUs=", + "owner": "NuschtOS", + "repo": "search", + "rev": "16565307c267ec219c2b5d3494ba66df08e7d403", + "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" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722330636, + "narHash": "sha256-uru7JzOa33YlSRwf9sfXpJG+UAV+bnBEYMjrzKrQZFw=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "768acdb06968e53aa1ee8de207fd955335c754b7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nixos/nixvim/flake.nix b/nixos/nixvim/flake.nix new file mode 100644 index 0000000..8e80918 --- /dev/null +++ b/nixos/nixvim/flake.nix @@ -0,0 +1,47 @@ +{ + description = "A nixvim configuration"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + nixvim.url = "github:nix-community/nixvim"; + flake-parts.url = "github:hercules-ci/flake-parts"; + }; + + outputs = + { nixvim, flake-parts, ... }@inputs: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + perSystem = + { pkgs, system, ... }: + let + nixvimLib = nixvim.lib.${system}; + nixvim' = nixvim.legacyPackages.${system}; + nixvimModule = { + inherit pkgs; + module = import ./config; # import the module directly + # You can use `extraSpecialArgs` to pass additional arguments to your module files + extraSpecialArgs = { + # inherit (inputs) foo; + }; + }; + nvim = nixvim'.makeNixvimWithModule nixvimModule; + in + { + checks = { + # Run `nix flake check .` to verify that your config is not broken + default = nixvimLib.check.mkTestDerivationFromNixvimModule nixvimModule; + }; + + packages = { + # Lets you run `nix run .` to start nixvim + default = nvim; + }; + }; + }; +}