diff --git a/flake.nix b/flake.nix index 6675a2e..4e95e9a 100644 --- a/flake.nix +++ b/flake.nix @@ -36,9 +36,6 @@ # Your custom packages # Accessible through 'nix build', 'nix shell', etc packages = forAllSystems (system: import ./pkgs nixpkgs.legacyPackages.${system}); - # Formatter for your nix files, available through 'nix fmt' - # Other options beside 'alejandra' include 'nixpkgs-fmt' - formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixpkgs-fmt); # Your custom packages and modifications, exported as overlays overlays = import ./overlays {inherit inputs;}; diff --git a/modules/home-manager/nixvim/plugins/default.nix b/modules/home-manager/nixvim/plugins/default.nix index da77697..3c49641 100644 --- a/modules/home-manager/nixvim/plugins/default.nix +++ b/modules/home-manager/nixvim/plugins/default.nix @@ -2,6 +2,7 @@ imports = [ ./cmp.nix ./lsp.nix + ./fmt.nix ./treesitter.nix ./lualine.nix ./nvim-autopairs.nix diff --git a/modules/home-manager/nixvim/plugins/fmt.nix b/modules/home-manager/nixvim/plugins/fmt.nix new file mode 100644 index 0000000..6f2a968 --- /dev/null +++ b/modules/home-manager/nixvim/plugins/fmt.nix @@ -0,0 +1,53 @@ +{ pkgs, ... }: +{ + home.packages = with pkgs; [ + stylua + nixfmt-rfc-style + ]; + + programs.nixvim = { + opts.formatexpr = "v:lua.require'conform'.formatexpr()"; + + plugins.conform-nvim = { + enable = true; + lazyLoad.enable = true; + lazyLoad.settings = { + event = "BufWritePre"; + cmd = "ConformInfo"; + keys = [ + { + __unkeyed-1 = "f"; + __unkeyed-2.__raw = '' + function() require 'conform'.format { async = true } end + ''; + desc = "Format Buffer"; + } + ]; + }; + settings = { + default_format_opts.lsp_format = "fallback"; + format_on_save = '' + function(bufnr) + local disable_filetypes = { c = true, cpp = true } + local lsp_format_opt + if disable_filetypes[vim.bo[bufnr].filetype] then + lsp_format_opt = 'never' + else + lsp_format_opt = 'fallback' + end + return { + timeout_ms = 500, + lsp_format = lsp_format_opt, + } + end + ''; + + formatters_by_ft = { + lua = [ "stylua" ]; + python = [ "black" ]; + nix = [ "nixfmt" ]; + }; + }; + }; + }; +} diff --git a/modules/home-manager/nixvim/plugins/lsp.nix b/modules/home-manager/nixvim/plugins/lsp.nix index 2b63b70..57ad80d 100644 --- a/modules/home-manager/nixvim/plugins/lsp.nix +++ b/modules/home-manager/nixvim/plugins/lsp.nix @@ -23,9 +23,6 @@ pyright.enable = true; }; }; - lsp-format = { - enable = true; - }; }; }; }