diff --git a/home.nix b/home.nix index 53bc7dc..c281f62 100644 --- a/home.nix +++ b/home.nix @@ -1,5 +1,88 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: with builtins; +let + mkSettings = s: + concatStringsSep + "\n" + (attrValues + (mapAttrs + (k: v: + if typeOf v == "bool" then + if v then "set ${k}" else "set no${k}" + else + "set ${k}=${toString v}") + s + ) + ); + boolToString = b: if b then "true" else "false"; + toLuaTable = as: + "{" + + ( concatStringsSep + ", " + ( filter + (attr: !isNull attr) + ( attrValues + ( mapAttrs + (k: v: if v then "${k}=true" else null) + as + ) + ) + ) + ) + + "}"; + mkMapping = { + mode, + binding, + command, + nowait?false, + silent?false, + unique?false, + expr?false + }: + "vim.api.nvim_set_keymap(${toJSON mode}, ${toJSON binding}, ${toJSON command}, ${toLuaTable {inherit nowait silent unique expr;}})"; + mkMappings = + m: + "lua << END-OF-KEYBINDS\n" + + (concatStringsSep "\n" (map mkMapping m)) + + "\nEND-OF-KEYBINDS"; + mkRuntimes = rs: + if rs == [] then "" else + "set runtimepath+=" + + ( concatStringsSep + "," + (map (rt: "${rt}") rs) + ); + mkVimHeader = h: "\"\"\"\"\"\"\"\" ${h} \"\"\"\"\"\"\"\"\""; + mkVimSection = section: + (concatStringsSep "\n\n\n" + (filter + (v: !isNull v) + (attrValues + (mapAttrs + (k: v: if "" == v then null else (mkVimHeader k) + "\n" + v) + section + ) + ) + ) + ); + mkVimSections = sections: concatStringsSep "\n\n\n" (map mkVimSection sections); + mkConfig = { settings?{}, mappings?[], runtimes?[], extra?"" }: + mkVimSections [ + {"ADDITIONAL RUNTIME DIRS" = mkRuntimes runtimes;} + {"SETTINGS" = mkSettings settings;} + {"KEY BINGINGS" = mkMappings mappings;} + {"MANUAL SETTINGS" = extra;} + ]; + # Via https://gist.github.com/nat-418/d76586da7a5d113ab90578ed56069509 + fromGitHub = ref: repo: pkgs.vimUtils.buildVimPluginFrom2Nix { + pname = "${lib.strings.sanitizeDerivationName repo}"; + version = ref; + src = builtins.fetchGit { + url = "https://github.com/${repo}.git"; + ref = ref; + }; + }; +in { # Home Manager needs a bit of information about you and the paths it should # manage. @@ -38,6 +121,7 @@ ripgrep tmate comic-mono + comfortaa btop firefox apostrophe @@ -46,7 +130,6 @@ mpv wl-clipboard adw-gtk3 - # some bullshit to get gnome apps to install withotu a prefix ] ++ ( with pkgs.gnome; [ gnome-boxes gnome-tweaks @@ -75,7 +158,6 @@ home.sessionVariables = { # system configuration -# EDITOR = "nvim"; VISUAL = "neovide --nofork"; NEOVIDE_MULTIGRID = 1; @@ -118,6 +200,43 @@ vimdiffAlias = true; withNodeJs = true; + plugins = with pkgs.vimPlugins; [ + editorconfig-nvim + vim-airline + vim-airline-themes + lsp_signature-nvim + nvim-colorizer-lua + nnn-vim + nvim-surround + nvim-treesitter.withAllGrammars + (fromGitHub "HEAD" "hiphish/rainbow-delimiters.nvim") + nvim-lspconfig + ]; + extraConfig = mkConfig { + settings = { + number = true; + linebreak = true; + showbreak = "+>"; + textwidth = 100; + showmatch = true; + + hlsearch = true; + smartcase = true; + ignorecase = true; + + autoindent = true; + smartindent = true; + smarttab = true; + tabstop = 3; + shiftwidth = 3; + + display = "lastline"; + formatoptions = "jt"; + ruler = true; + cc = 101; + termguicolors = true; + }; + }; coc = { enable = true; }; diff --git a/modules/neovim-config.nix b/modules/neovim-config.nix new file mode 100644 index 0000000..51dd75c --- /dev/null +++ b/modules/neovim-config.nix @@ -0,0 +1,84 @@ +{ + mkSettings = s: + concatStringsSep + "\n" + (attrValues + (mapAttrs + (k: v: + if typeOf v == "bool" then + if v then "set ${k}" else "set no${k}" + else + "set ${k}=${toString v}") + s + ) + ); + boolToString = b: if b then "true" else "false"; + toLuaTable = as: + "{" + + ( concatStringsSep + ", " + ( filter + (attr: !isNull attr) + ( attrValues + ( mapAttrs + (k: v: if v then "${k}=true" else null) + as + ) + ) + ) + ) + + "}"; + mkMapping = { + mode, + binding, + command, + nowait?false, + silent?false, + unique?false, + expr?false + }: + "vim.api.nvim_set_keymap(${toJSON mode}, ${toJSON binding}, ${toJSON command}, ${toLuaTable {inherit nowait silent unique expr;}})"; + mkMappings = + m: + "lua << END-OF-KEYBINDS\n" + + (concatStringsSep "\n" (map mkMapping m)) + + "\nEND-OF-KEYBINDS"; + mkRuntimes = rs: + if rs == [] then "" else + "set runtimepath+=" + + ( concatStringsSep + "," + (map (rt: "${rt}") rs) + ); + mkVimHeader = h: "\"\"\"\"\"\"\"\" ${h} \"\"\"\"\"\"\"\"\""; + mkVimSection = section: + (concatStringsSep "\n\n\n" + (filter + (v: !isNull v) + (attrValues + (mapAttrs + (k: v: if "" == v then null else (mkVimHeader k) + "\n" + v) + section + ) + ) + ) + ); + mkVimSections = sections: concatStringsSep "\n\n\n" (map mkVimSection sections); + mkConfig = { settings?{}, mappings?[], runtimes?[], extra?"" }: + mkVimSections [ + {"ADDITIONAL RUNTIME DIRS" = mkRuntimes runtimes;} + {"SETTINGS" = mkSettings settings;} + {"KEY BINGINGS" = mkMappings mappings;} + {"MANUAL SETTINGS" = extra;} + ]; + + # Via https://gist.github.com/nat-418/d76586da7a5d113ab90578ed56069509 + fromGitHub = ref: repo: pkgs.vimUtils.buildVimPluginFrom2Nix { + pname = "${lib.strings.sanitizeDerivationName repo}"; + version = ref; + src = builtins.fetchGit { + url = "https://github.com/${repo}.git"; + ref = ref; + }; + }; +}