From 57a73bbcae6facfc9cc4efc8d6b438e16edac514 Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Tue, 6 May 2025 15:54:26 +0800 Subject: [PATCH] refactor(nvf): move core nvf config to a module --- configs/programs/nvf.nix | 83 -------------------------------- hosts/common.nix | 4 +- modules/hm/default.nix | 7 +++ modules/hm/programs/editor.nix | 29 +++++++++++ modules/hm/programs/nvf/core.nix | 79 ++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 84 deletions(-) create mode 100644 modules/hm/programs/editor.nix create mode 100644 modules/hm/programs/nvf/core.nix diff --git a/configs/programs/nvf.nix b/configs/programs/nvf.nix index e52c962..27ef7d8 100644 --- a/configs/programs/nvf.nix +++ b/configs/programs/nvf.nix @@ -1,93 +1,10 @@ -{ inputs, pkgs, ... }: { - nix.settings.substituters = [ "https://nvf.cachix.org" ]; - nix.settings.trusted-public-keys = [ - "nvf.cachix.org-1:GMQWiUhZ6ux9D5CvFFMwnc2nFrUHTeGaXRlVBXo+naI=" - ]; - home-manager.users.rafiq = { imports = [ - inputs.nvf.homeManagerModules.default ./nvf/input.nix ./nvf/languages.nix ./nvf/ui.nix ./nvf/utilities.nix ]; - home.sessionVariables.EDITOR = "nvim"; - programs.nvf = { - enable = true; - enableManpages = true; - settings.vim = { - viAlias = true; - vimAlias = true; - options = { - # Indentation - autoindent = true; - smartindent = true; - expandtab = true; - smarttab = true; - wrap = true; - shiftwidth = 2; - tabstop = 2; - foldlevel = 1000; # Open all folds by default - - # Search - hlsearch = true; - ignorecase = true; - incsearch = true; - smartcase = true; # case-sensitive if search contains uppercase - - # Visual - number = true; - cursorline = true; - visualbell = true; - termguicolors = true; - - # Input - backspace = "indent,eol,start"; - }; - keymaps = [ - { - desc = "Open the file path under the cursor, making the file if it doesn't exist."; - key = "gf"; - mode = "n"; - action = ":cd %:p:h:e "; - silent = true; - } - { - desc = "Delete the previous word."; - key = ""; - mode = "i"; - action = ""; - silent = true; - } - { - desc = "Open the filetree."; - key = "t"; - mode = "n"; - action = ":Yazi"; - silent = true; - } - ]; - luaConfigRC.turn_off_inline_diagnostics = - # lua - '' - vim.diagnostic.config({ - virtual_text = false -- turn off inline diagnostics - }) - ''; - extraPlugins = with pkgs.vimPlugins; { - yuck-vim = { - package = yuck-vim; - }; - nvim-treesitter-parsers = { - package = nvim-treesitter-parsers.yuck; - }; - nvim-parinfer = { - package = nvim-parinfer; - }; - }; - }; - }; }; } diff --git a/hosts/common.nix b/hosts/common.nix index 4533ddf..5f67304 100644 --- a/hosts/common.nix +++ b/hosts/common.nix @@ -18,9 +18,11 @@ nixosModules.enable = true; nixosModules.hostname = hostname; nixosModules.mainUser = "rafiq"; - hmModules.enable = true; nix-config.enable = true; boot-config.enable = true; hardware-config.usbAutoMount = true; nw-config.backend = "networkmanager"; + + hmModules.enable = true; + hmModules.mainApps.editor = "nvf"; } diff --git a/modules/hm/default.nix b/modules/hm/default.nix index 9cdf622..520b87f 100644 --- a/modules/hm/default.nix +++ b/modules/hm/default.nix @@ -14,6 +14,7 @@ in imports = [ inputs.home-manager.nixosModules.home-manager ./hardware.nix + ./programs/editor.nix ]; options = { @@ -32,6 +33,12 @@ in example = "firefox"; description = "What browser is the default."; }; + editor = lib.mkOption { + type = lib.types.str; + default = "nvf"; + example = "nvf"; + description = "What editor is the default."; + }; launcher = lib.mkOption { type = lib.types.str; default = "fuzzel"; diff --git a/modules/hm/programs/editor.nix b/modules/hm/programs/editor.nix new file mode 100644 index 0000000..a201661 --- /dev/null +++ b/modules/hm/programs/editor.nix @@ -0,0 +1,29 @@ +{ + config, + lib, + inputs, + pkgs, + ... +}: +let + username = config.nixosModules.mainUser; +in +{ + config = lib.mkIf (config.hmModules.mainApps.editor == "nvf") ( + lib.mkMerge [ + { + nix.settings.substituters = [ "https://nvf.cachix.org" ]; + nix.settings.trusted-public-keys = [ + "nvf.cachix.org-1:GMQWiUhZ6ux9D5CvFFMwnc2nFrUHTeGaXRlVBXo+naI=" + ]; + + home-manager.users.${username} = { + imports = [ + inputs.nvf.homeManagerModules.default + ./nvf/core.nix + ]; + }; + } + ] + ); +} diff --git a/modules/hm/programs/nvf/core.nix b/modules/hm/programs/nvf/core.nix new file mode 100644 index 0000000..cc44243 --- /dev/null +++ b/modules/hm/programs/nvf/core.nix @@ -0,0 +1,79 @@ +{ pkgs, ... }: +{ + home.sessionVariables.EDITOR = "nvim"; + programs.nvf = { + enable = true; + enableManpages = true; + settings.vim = { + viAlias = true; + vimAlias = true; + options = { + # Indentation + autoindent = true; + smartindent = true; + expandtab = true; + smarttab = true; + wrap = true; + shiftwidth = 2; + tabstop = 2; + foldlevel = 1000; # Open all folds by default + + # Search + hlsearch = true; + ignorecase = true; + incsearch = true; + smartcase = true; # case-sensitive if search contains uppercase + + # Visual + number = true; + cursorline = true; + visualbell = true; + termguicolors = true; + + # Input + backspace = "indent,eol,start"; + }; + keymaps = [ + { + desc = "Open the file path under the cursor, making the file if it doesn't exist."; + key = "gf"; + mode = "n"; + action = ":cd %:p:h:e "; + silent = true; + } + { + desc = "Delete the previous word."; + key = ""; + mode = "i"; + action = ""; + silent = true; + } + { + desc = "Open the filetree."; + key = "t"; + mode = "n"; + action = ":Yazi"; + silent = true; + } + ]; + luaConfigRC.turn_off_inline_diagnostics = + # lua + '' + vim.diagnostic.config({ + virtual_text = false -- turn off inline diagnostics + }) + ''; + extraPlugins = with pkgs.vimPlugins; { + yuck-vim = { + package = yuck-vim; + }; + nvim-treesitter-parsers = { + package = nvim-treesitter-parsers.yuck; + }; + nvim-parinfer = { + package = nvim-parinfer; + }; + }; + }; + }; +}