about summary refs log tree commit diff
path: root/modules
diff options
context:
space:
mode:
authorAzat Bahawi <azat@bahawi.net>2023-07-03 11:27:19 +0300
committerAzat Bahawi <azat@bahawi.net>2023-07-03 11:27:19 +0300
commitc80598d4e4ffea73647b2ea8440a6080596968fe (patch)
treea6ca4bb82ec20df18022988fa359126fc877d5da /modules
parent2023-06-21 (diff)
2023-07-03
Diffstat (limited to '')
-rw-r--r--modules/common/common/home-manager.nix7
-rw-r--r--modules/common/git.nix6
-rw-r--r--modules/common/profiles/default.nix3
-rw-r--r--modules/common/vim/default.nix62
-rw-r--r--modules/common/vim/rc.vim140
-rw-r--r--modules/darwin/default.nix1
-rw-r--r--modules/darwin/profiles/headful.nix9
-rw-r--r--modules/darwin/vim/default.nix26
-rw-r--r--modules/nixos/default.nix1
-rw-r--r--modules/nixos/ntfy.nix9
-rw-r--r--modules/nixos/vim/default.nix39
11 files changed, 140 insertions, 163 deletions
diff --git a/modules/common/common/home-manager.nix b/modules/common/common/home-manager.nix
index 7fa21f8..44b0eaa 100644
--- a/modules/common/common/home-manager.nix
+++ b/modules/common/common/home-manager.nix
@@ -1,5 +1,5 @@
 {
-  config,
+  inputs,
   lib,
   localUsername ? lib.my.username,
   ...
@@ -11,7 +11,10 @@ with lib; {
 
   hm = {
     news.display = "silent";
-    home = {inherit (config.system) stateVersion;};
+    # NOTE Inheriting directly from `system.stateVersion` does not work on MacOS for
+    # some reason.
+    home.stateVersion = with builtins;
+      head (split "\n" (readFile "${inputs.nixpkgs}/.version"));
   };
 
   home-manager = {
diff --git a/modules/common/git.nix b/modules/common/git.nix
index ce4e505..0bd7720 100644
--- a/modules/common/git.nix
+++ b/modules/common/git.nix
@@ -14,7 +14,7 @@ in {
 
   config = mkIf cfg.client.enable {
     secrets = let
-      # HACK Darwin doesn't support XDG specifications.
+      # HACK MacOS doesn't support XDG specifications.
       configHome = "${config.my.home}/.config";
     in {
       glab-cli-config = {
@@ -97,8 +97,8 @@ in {
             wtc = "!${curl} -sq whatthecommit.com/index.txt | ${git} commit -F -";
           };
 
-          # All helper tools/editor generated files should go here. This must
-          # be kept relatively clean and void of any project-specific residual
+          # All helper tools/editor generated files should go here. This must be
+          # kept relatively clean and void of any project-specific residual
           # files.
           ignores = [
             "*~"
diff --git a/modules/common/profiles/default.nix b/modules/common/profiles/default.nix
index 4f8fa4d..ad5e841 100644
--- a/modules/common/profiles/default.nix
+++ b/modules/common/profiles/default.nix
@@ -81,10 +81,7 @@ in {
     time.timeZone = "Europe/Moscow";
 
     environment.systemPackages = with pkgs; [
-      ddrescue
       file
-      git
-      gnupg
       tree
     ];
   };
diff --git a/modules/common/vim/default.nix b/modules/common/vim/default.nix
index 2ee8a0b..3755201 100644
--- a/modules/common/vim/default.nix
+++ b/modules/common/vim/default.nix
@@ -7,43 +7,37 @@
 with lib; let
   cfg = config.nixfiles.modules.vim;
 in {
-  options.nixfiles.modules.vim.enable = mkEnableOption "Vim";
+  options.nixfiles.modules.vim = {
+    enable = mkEnableOption "Vim";
+
+    rc = mkOption {
+      type = types.str;
+      default = readFile ./rc.vim;
+      description = "Configuration file.";
+    };
+
+    plugins = mkOption {
+      type = with types; listOf package;
+      default = with pkgs.vimPlugins; [
+        editorconfig-vim
+        vim-eunuch
+        vim-nix
+        vim-sensible
+        vim-sleuth
+        vim-surround
+        vim-unimpaired
+      ];
+      description = "Plugins.";
+    };
+  };
 
   config = mkIf cfg.enable {
-    programs.vim.package = with pkgs;
-      (vim_configurable.override {
-        features = "normal";
-        cscopeSupport = false;
-        darwinSupport = pkgs.stdenv.isDarwin;
-        guiSupport = false;
-        luaSupport = false;
-        multibyteSupport = false;
-        netbeansSupport = false;
-        nlsSupport = false;
-        perlSupport = false;
-        pythonSupport = false;
-        rubySupport = false;
-        tclSupport = false;
-        ximSupport = false;
-      })
-      .customize {
-        name = "vim";
-        vimrcConfig = {
-          customRC = readFile ./rc.vim;
-          packages.myVimPackage.start = with vimPlugins; [
-            editorconfig-vim
-            vim-eunuch
-            vim-nix
-            vim-sleuth
-            vim-surround
-            vim-unimpaired
-          ];
-        };
+    environment = with config.programs.vim; {
+      systemPackages = [package];
+      variables = rec {
+        EDITOR = mkOverride 100 "${package}/bin/vim";
+        VISUAL = EDITOR;
       };
-
-    environment = {
-      systemPackages = [config.programs.vim.package];
-      variables.EDITOR = mkOverride 100 "vim";
     };
   };
 }
diff --git a/modules/common/vim/rc.vim b/modules/common/vim/rc.vim
index 945643a..3bd9eb7 100644
--- a/modules/common/vim/rc.vim
+++ b/modules/common/vim/rc.vim
@@ -1,38 +1,31 @@
-set nocompatible
-
 let $VIMFILES = expand('<sfile>:p:h')
 
 let g:skip_defaults_vim = 1
 
 let g:netrw_dirhistmax = 0
 
-set autoread
-set backspace=indent,eol,start
+if has('unnamedplus')
+    set clipboard^=unnamedplus
+else
+    set clipboard^=unnamed
+endif
 
-set clipboard=unnamedplus
+set backspace=indent,eol,start
 set diffopt+=iwhite
 set hidden
-set history=256
 set lazyredraw
 set mouse=
 set path+=**
-set tabpagemax=50
 set viminfo=
 
 set cmdheight=1
-set display+=lastline
 set fillchars=vert:\ "
-set laststatus=2
 set modeline
 set noshowmode
-set ruler
 set shortmess+=I
 set textwidth=0
 set title
 
-set sessionoptions-=options
-set viewoptions-=options
-
 set noerrorbells
 set novisualbell
 
@@ -49,7 +42,6 @@ set completeopt+=longest
 
 set gdefault
 set hlsearch
-set incsearch
 set iskeyword+=-
 set magic
 
@@ -75,7 +67,6 @@ if v:version >= 700
 endif
 
 set wildignorecase
-set wildmenu
 set wildignore=
 
 set nobackup
@@ -97,65 +88,10 @@ set smarttab
 set softtabstop=4
 set tabstop=4
 
-autocmd BufEnter *.* :set colorcolumn=
-
-if &t_Co == 8 && $TERM !~# '^Eterm'
-    set t_Co=16
-endif
-
-if &listchars ==# 'eol:$'
-    set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
-endif
+set colorcolumn=
+let g:EditorConfig_max_line_indicator = "none"
 
-if v:version > 703 || v:version == 703 && has("patch541")
-    set formatoptions+=j
-endif
-
-if has('path_extra')
-    setglobal tags-=./tags tags-=./tags; tags^=./tags;
-endif
-
-if !has('nvim') && &ttimeoutlen == -1
-    set ttimeout
-    set ttimeoutlen=100
-endif
-
-try
-    set encoding=utf-8
-    scriptencoding utf-8
-catch
-endtry
-
-try
-    if &fileencodings !~? "utf-8"
-        let g:added_fenc_utf8 = 1
-        set fileencodings+=utf-8
-    endif
-catch
-endtry
-
-if has('autocmd')
-    filetype plugin indent on
-
-    if exists("+omnifunc")
-        autocmd Filetype *
-                    \ if &omnifunc == "" |
-                    \ setlocal omnifunc=syntaxcomplete#Complete |
-                    \ endif
-    endif
-
-    autocmd BufEnter * set noreadonly
-endif
-
-if has('syntax') && !exists('g:syntax_on')
-    syntax enable
-endif
-
-if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# ''
-    runtime! macros/matchit.vim
-endif
-
-nnoremap        <SPACE>     <nop>
+nnoremap        <Space>     <Nop>
 let mapleader=" "
 
 nnoremap        :W          :w
@@ -163,27 +99,27 @@ nnoremap        :W!         :w!
 nnoremap        :Q          :q
 nnoremap        :Q!         :q!
 
-nnoremap <Expr> j           v:count ? 'j' : 'gj'
-nnoremap <Expr> k           v:count ? 'k' : 'gk'
+nnoremap <expr> j           v:count ? 'j' : 'gj'
+nnoremap <expr> k           v:count ? 'k' : 'gk'
 
 nnoremap        J           gt
 nnoremap        K           gT
 
-nnoremap        <C-a>       ^h
-vnoremap        <C-a>       ^h
+nnoremap        <C-A>       ^h
+vnoremap        <C-A>       ^h
 nnoremap        H           ^h
 vnoremap        H           ^h
 
-nnoremap        <C-e>       $
-vnoremap        <C-e>       $
+nnoremap        <C-E>       $
+vnoremap        <C-E>       $
 nnoremap        L           $
 vnoremap        L           $
 
 nnoremap        N           Nzzzv
 nnoremap        n           nzzzv
 
-inoremap        <C-u>       <C-g>u<C-u>
-inoremap        <C-w>       <C-g>u<C-w>
+inoremap        <C-U>       <C-g>u<C-u>
+inoremap        <C-W>       <C-g>u<C-w>
 
 vnoremap        <           <gv
 vnoremap        >           >gv
@@ -192,24 +128,22 @@ vnoremap        <S-Tab>     <gv
 nnoremap        <Tab>       >>_
 nnoremap        <S-Tab>     <<_
 
-nnoremap        ]b          :<C-u>bnext<CR>
-nnoremap        [b          :<C-u>bprevious<CR>
+nnoremap        ]b          :bnext<CR>
+nnoremap        [b          :bprevious<CR>
 
-nnoremap        <C-h>       <C-w>h
-nnoremap        <C-j>       <C-w>j
-nnoremap        <C-k>       <C-w>k
-nnoremap        <C-l>       <C-w>l
+nnoremap        <C-H>       <C-w>h
+nnoremap        <C-J>       <C-w>j
+nnoremap        <C-K>       <C-w>k
+nnoremap        <C-R>       <C-w>l
 
 nnoremap        *           /\<<C-r>=expand('<cword>')<CR>\><CR>
 nnoremap        #           ?\<<C-r>=expand('<cword>')<CR>\><CR>
 
-nnoremap        <C-L>       :<C-u>nohlsearch<C-r>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-l>
-
 cnoremap        ;/          <C-r>=expand('%:p:h').'/'<CR>
 cnoremap        ;;          <C-r>=expand('%:t')<CR>
 cnoremap        ;.          <C-r>=expand('%:p:r')<CR>
 
-nnoremap        <Leader>.   :<C-u>lcd %:p:h<CR>
+nnoremap        <Leader>.   :lcd %:p:h<CR>
 
 nnoremap        Q           @q
 
@@ -225,29 +159,11 @@ nnoremap        <Leader>P   "+P
 inoremap        <C-v>       <C-c>"+pi
 cnoremap        <C-v>       <C-r>+
 
-nmap            <Leader>w   :<C-u>w!<CR>
-nmap            <Leader>wq  :<C-u>wq!<CR>
+nmap            <Leader>w   :w!<CR>
+nmap            <Leader>wq  :wq!<CR>
 
-nnoremap        ZX          :<C-u>qa!<CR>
+nnoremap        ZX          :qa!<CR>
 
-nnoremap        <Leader>q   :<C-u>q<CR>
+nnoremap        <Leader>q   :q<CR>
 
 command         WS          w !sudo tee "%" >/dev/null
-
-function! SwitchCase()
-    normal! ~
-    if strlen(getline('.')) != virtcol('.')
-        normal! h
-    endif
-endfunction
-nnoremap        ~           :<C-u>call SwitchCase()<CR>
-
-function! s:GM()
-    execute 'normal! ^'
-    let first_col = virtcol('.')
-    execute 'normal! g_'
-    let last_col  = virtcol('.')
-    execute 'normal! ' . (first_col + last_col) / 2 . '|'
-endfunction
-nnoremap        gm          :<C-u>call <SID>GM()<CR>
-onoremap        gm          :<C-u>call <SID>GM()<CR>
diff --git a/modules/darwin/default.nix b/modules/darwin/default.nix
index 153c857..6ea9663 100644
--- a/modules/darwin/default.nix
+++ b/modules/darwin/default.nix
@@ -6,5 +6,6 @@ _: {
     ./gnupg.nix
     ./homebrew.nix
     ./profiles
+    ./vim
   ];
 }
diff --git a/modules/darwin/profiles/headful.nix b/modules/darwin/profiles/headful.nix
index 2a4c773..c50c657 100644
--- a/modules/darwin/profiles/headful.nix
+++ b/modules/darwin/profiles/headful.nix
@@ -1,6 +1,7 @@
 {
   config,
   lib,
+  pkgs,
   ...
 }:
 with lib; let
@@ -9,6 +10,14 @@ in {
   config = mkIf cfg.enable {
     nixfiles.modules.homebrew.enable = true;
 
+    hm.home.packages = with pkgs; [
+      coreutils
+      findutils
+      gnugrep
+      gnused
+      gnutar
+    ];
+
     homebrew.casks = [
       {name = "chromium";}
       {name = "firefox";}
diff --git a/modules/darwin/vim/default.nix b/modules/darwin/vim/default.nix
new file mode 100644
index 0000000..519f120
--- /dev/null
+++ b/modules/darwin/vim/default.nix
@@ -0,0 +1,26 @@
+{
+  config,
+  lib,
+  pkgs,
+  ...
+}:
+with lib; let
+  cfg = config.nixfiles.modules.vim;
+in {
+  config = mkIf cfg.enable {
+    programs.vim.package =
+      (pkgs.macvim.overrideAttrs (_: final: {
+        # TODO https://github.com/NixOS/nixpkgs/pull/239842
+        configureFlags =
+          final.configureFlags
+          ++ [
+            "--disable-perlinterp"
+            "--disable-rubyinterp"
+          ];
+      }))
+      .configure (with cfg; {
+        customRC = rc;
+        packages.myVimPackage.start = plugins;
+      });
+  };
+}
diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix
index f8347cf..466e2e0 100644
--- a/modules/nixos/default.nix
+++ b/modules/nixos/default.nix
@@ -62,6 +62,7 @@ _: {
     ./throttled.nix
     ./unbound.nix
     ./vaultwarden.nix
+    ./vim
     ./wireguard.nix
     ./x11.nix
     ./xmonad.nix
diff --git a/modules/nixos/ntfy.nix b/modules/nixos/ntfy.nix
index edbe7e5..1682b7e 100644
--- a/modules/nixos/ntfy.nix
+++ b/modules/nixos/ntfy.nix
@@ -64,20 +64,11 @@ in {
       settings = {
         listen-http = "127.0.0.1:${toString cfg.port}";
         base-url = "https://${cfg.domain}";
-        cache-file = "/var/cache/ntfy/cache.db";
         behind-proxy = true;
-        attachment-cache-dir = "/var/cache/ntfy/attachments";
-        auth-file = "/var/lib/ntfy/user.db";
         enable-metrics = cfg.prometheus.enable;
         metrics-listen-http = with cfg.prometheus;
           optionalString cfg.prometheus.enable "${address}:${toString port}";
       };
     };
-
-    systemd.tmpfiles.rules = with config.services.ntfy-sh; [
-      "d /var/lib/ntfy 0700 ${user} ${group} - -"
-      "d /var/cache/ntfy 0700 ${user} ${group} - -"
-      "d /var/cache/ntfy/attachments 0700 ${user} ${group} - -"
-    ];
   };
 }
diff --git a/modules/nixos/vim/default.nix b/modules/nixos/vim/default.nix
new file mode 100644
index 0000000..16e2d51
--- /dev/null
+++ b/modules/nixos/vim/default.nix
@@ -0,0 +1,39 @@
+{
+  config,
+  lib,
+  pkgs,
+  this,
+  ...
+}:
+with lib; let
+  cfg = config.nixfiles.modules.vim;
+in {
+  config = mkIf cfg.enable {
+    programs.vim.package =
+      (pkgs.vim-full.override {
+        features = "normal";
+        cscopeSupport = false;
+        darwinSupport = false;
+        guiSupport =
+          if this.isHeadful
+          then "gtk3"
+          else false;
+        luaSupport = false;
+        multibyteSupport = false;
+        netbeansSupport = false;
+        nlsSupport = false;
+        perlSupport = false;
+        pythonSupport = false;
+        rubySupport = false;
+        tclSupport = false;
+        ximSupport = false;
+      })
+      .customize {
+        name = "vim";
+        vimrcConfig = with cfg; {
+          customRC = rc;
+          packages.myVimPackage.start = plugins;
+        };
+      };
+  };
+}

Consider giving Nix/NixOS a try! <3