modules: start breaking down core modules; simplify tree structure

This commit is contained in:
raf 2024-02-17 04:02:15 +03:00
commit 370913e827
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
242 changed files with 178 additions and 124 deletions

185
modules/neovim/config.nix Normal file
View file

@ -0,0 +1,185 @@
{
lib,
config,
...
}: let
inherit (builtins) concatStringsSep;
inherit (lib) optionalString mkIf nvim;
cfg = config.vim;
in {
config = {
vim.startPlugins = ["plenary-nvim"] ++ lib.optionals (cfg.spellChecking.enableProgrammingWordList) ["vim-dirtytalk"];
vim.maps.normal =
mkIf cfg.disableArrows {
"<up>" = {
action = "<nop>";
noremap = false;
};
"<down>" = {
action = "<nop>";
noremap = false;
};
"<left>" = {
action = "<nop>";
noremap = false;
};
"<right>" = {
action = "<nop>";
noremap = false;
};
}
// mkIf cfg.mapLeaderSpace {
"<space>" = {
action = "<nop>";
};
};
vim.maps.insert = mkIf cfg.disableArrows {
"<up>" = {
action = "<nop>";
noremap = false;
};
"<down>" = {
action = "<nop>";
noremap = false;
};
"<left>" = {
action = "<nop>";
noremap = false;
};
"<right>" = {
action = "<nop>";
noremap = false;
};
};
vim.configRC.basic = nvim.dag.entryAfter ["globalsScript"] ''
" Settings that are set for everything
set encoding=utf-8
set mouse=${cfg.mouseSupport}
set tabstop=${toString cfg.tabWidth}
set shiftwidth=${toString cfg.tabWidth}
set softtabstop=${toString cfg.tabWidth}
set expandtab
set cmdheight=${toString cfg.cmdHeight}
set updatetime=${toString cfg.updateTime}
set shortmess+=c
set tm=${toString cfg.mapTimeout}
set hidden
set cursorlineopt=${toString cfg.cursorlineOpt}
set scrolloff=${toString cfg.scrollOffset}
${optionalString cfg.debugMode.enable ''
" Debug mode settings
set verbose=${toString cfg.debugMode.level}
set verbosefile=${cfg.debugMode.logFile}
''}
${optionalString cfg.splitBelow ''
set splitbelow
''}
${optionalString cfg.splitRight ''
set splitright
''}
${optionalString cfg.showSignColumn ''
set signcolumn=yes
''}
${optionalString cfg.autoIndent ''
set autoindent
''}
${optionalString cfg.preventJunkFiles ''
set noswapfile
set nobackup
set nowritebackup
''}
${optionalString (cfg.bell == "none") ''
set noerrorbells
set novisualbell
''}
${optionalString (cfg.bell == "on") ''
set novisualbell
''}
${optionalString (cfg.bell == "visual") ''
set noerrorbells
''}
${optionalString (cfg.lineNumberMode == "relative") ''
set relativenumber
''}
${optionalString (cfg.lineNumberMode == "number") ''
set number
''}
${optionalString (cfg.lineNumberMode == "relNumber") ''
set number relativenumber
''}
${optionalString cfg.useSystemClipboard ''
set clipboard+=unnamedplus
''}
${optionalString cfg.mapLeaderSpace ''
let mapleader=" "
let maplocalleader=" "
''}
${optionalString cfg.syntaxHighlighting ''
syntax on
''}
${optionalString (!cfg.wordWrap) ''
set nowrap
''}
${optionalString cfg.hideSearchHighlight ''
set nohlsearch
set incsearch
''}
${optionalString cfg.colourTerm ''
set termguicolors
set t_Co=256
''}
${optionalString (!cfg.enableEditorconfig) ''
let g:editorconfig = v:false
''}
${optionalString cfg.spellChecking.enable ''
set spell
set spelllang=${concatStringsSep "," cfg.spellChecking.languages}${optionalString cfg.spellChecking.enableProgrammingWordList ",programming"}
''}
${optionalString (cfg.leaderKey != null) ''
let mapleader = "${toString cfg.leaderKey}"
''}
${optionalString (cfg.searchCase == "ignore") ''
set nosmartcase
set ignorecase
''}
${optionalString (cfg.searchCase == "smart") ''
set smartcase
set ignorecase
''}
${optionalString (cfg.searchCase == "sensitive") ''
set nosmartcase
set noignorecase
''}
'';
};
}

View file

@ -0,0 +1,6 @@
_: {
imports = [
./config.nix
./module.nix
];
}

200
modules/neovim/module.nix Normal file
View file

@ -0,0 +1,200 @@
{
pkgs,
lib,
...
}: let
inherit (lib) mkEnableOption mkOption;
inherit (lib.types) types;
in {
options.vim = {
package = mkOption {
type = types.package;
default = pkgs.neovim-unwrapped;
description = ''
The neovim package to use. You will need to use an unwrapped package for this option to work as intended.
'';
};
debugMode = {
enable = mkEnableOption "debug mode";
level = mkOption {
type = types.int;
default = 20;
description = "Set the debug level";
};
logFile = mkOption {
type = types.path;
default = "/tmp/nvim.log";
description = "Set the log file";
};
};
enableLuaLoader = mkEnableOption "experimental Lua module loader to speed up the start up process";
leaderKey = mkOption {
type = with types; nullOr str;
default = null;
description = "The leader key to be used internally";
};
spellChecking = {
enable = mkEnableOption "neovim's built-in spellchecking";
enableProgrammingWordList = mkEnableOption "vim-dirtytalk, a wordlist for programmers, that includes programming words";
languages = mkOption {
type = with types; listOf str;
description = "The languages to be used for spellchecking";
default = ["en"];
example = ["en" "de"];
};
};
colourTerm = mkOption {
type = types.bool;
default = true;
description = "Set terminal up for 256 colours";
};
disableArrows = mkOption {
type = types.bool;
default = false;
description = "Set to prevent arrow keys from moving cursor";
};
hideSearchHighlight = mkOption {
type = types.bool;
default = false;
description = "Hide search highlight so it doesn't stay highlighted";
};
scrollOffset = mkOption {
type = types.int;
default = 8;
description = "Start scrolling this number of lines from the top or bottom of the page.";
};
wordWrap = mkOption {
type = types.bool;
default = true;
description = "Enable word wrapping.";
};
syntaxHighlighting = mkOption {
type = types.bool;
default = true;
description = "Enable syntax highlighting";
};
mapLeaderSpace = mkOption {
type = types.bool;
default = true;
description = "Map the space key to leader key";
};
useSystemClipboard = mkOption {
type = types.bool;
default = false;
description = "Make use of the clipboard for default yank and paste operations. Don't use * and +";
};
mouseSupport = mkOption {
type = with types; enum ["a" "n" "v" "i" "c"];
default = "a";
description = ''
Set modes for mouse support.
* a - all
* n - normal
* v - visual
* i - insert
* c - command
'';
};
lineNumberMode = mkOption {
type = with types; enum ["relative" "number" "relNumber" "none"];
default = "relNumber";
description = ''
How line numbers are displayed. Available options are
none, relative, number, relNumber
'';
};
preventJunkFiles = mkOption {
type = types.bool;
default = false;
description = "Prevent swapfile, backupfile from being created";
};
tabWidth = mkOption {
type = types.int;
default = 4;
description = "Set the width of tabs";
};
autoIndent = mkOption {
type = types.bool;
default = true;
description = "Enable auto indent";
};
cmdHeight = mkOption {
type = types.int;
default = 1;
description = "Height of the command pane";
};
updateTime = mkOption {
type = types.int;
default = 300;
description = "The number of milliseconds till Cursor Hold event is fired";
};
showSignColumn = mkOption {
type = types.bool;
default = true;
description = "Show the sign column";
};
bell = mkOption {
type = types.enum ["none" "visual" "on"];
default = "none";
description = "Set how bells are handled. Options: on, visual or none";
};
mapTimeout = mkOption {
type = types.int;
default = 500;
description = "Timeout in ms that neovim will wait for mapped action to complete";
};
splitBelow = mkOption {
type = types.bool;
default = true;
description = "New splits will open below instead of on top";
};
splitRight = mkOption {
type = types.bool;
default = true;
description = "New splits will open to the right";
};
enableEditorconfig = mkOption {
type = types.bool;
default = true;
description = "Follow editorconfig rules in current directory";
};
cursorlineOpt = mkOption {
type = types.enum ["line" "screenline" "number" "both"];
default = "line";
description = "Highlight the text line of the cursor with CursorLine hl-CursorLine";
};
searchCase = mkOption {
type = types.enum ["ignore" "smart" "sensitive"];
default = "sensitive";
description = "Set the case sensitivity of search";
};
};
}