~vonfry/dotfiles

ref: 97bafdd5be42d15f874ef917cd6f34bd192415b0 dotfiles/etc/nixos/modules/user/development.nix -rw-r--r-- 8.9 KiB
97bafdd5Vonfry Merge branch 'release/20220706' 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
{ config, pkgs, lib, ... }:

with lib;
let
  cfg = config.vonfry.development;
  cfg' = config.vonfry;

  emacsExtraBin = with pkgs; buildEnv {
    name = "emacs-extra-bin";
    paths = [ sqlite perl hugo agda ];
    pathsToLink = [ "/bin" "/share" "/lib" ];
  };

  editorMimeApps = listToAttrs
    (map (type: {name = type; value = "emacsclient.desktop"; })
      [ # copy from emacs.desktop
        "text/english" "text/plain" "text/x-makefile" "text/x-c++hdr"
        "text/x-c++src" "text/x-chdr" "text/x-csrc" "text/x-java" "text/x-moc"
        "text/x-pascal" "text/x-tcl" "text/x-tex" "application/x-shellscript"
        "text/x-c" "text/x-c++"
      ]);


  sessions = config.home.sessionVariables;
  inherit (sessions) DOTFILES_DIR CLOUD_DIR ORG_DIR CLONE_LIB;
  inherit (config.xdg) configHome dataHome;

  hasOrg = sessions ? "ORG_DIR";
  hasCloud = sessions ? "CLOUD_DIR";

  emacsLocal = "${CLOUD_DIR}/dotfiles/config/emacs.d/local";
  emacsPriv = "${CLOUD_DIR}/dotfiles/config/emacs.d/private";
  linkOrg = optionalString (hasOrg && hasCloud) ''
    [ -h ${ORG_DIR} ] || $DRY_RUN_CMD ln $VERBOSE_ARG -s ${CLOUD_DIR}/dotfiles/orgmode ${ORG_DIR}
  '';
  linkEmacs = optionalString hasCloud ''
    if [ -d "${emacsLocal}" ]; then
      $DRY_RUN_CMD ln $VERBOSE_ARG -sf ${emacsLocal}/* ${toString configHome}/emacs.d/local/
    fi
    if [ -d "${emacsPriv}" ]; then
      $DRY_RUN_CMD ln $VERBOSE_ARG -sf ${emacsPriv}/* ${toString configHome}/emacs.d/modules/private/
    fi

    [ -h ${toString dataHome}/emacs/dashboard-image.png ] || ln -s ${pkgs.vonfryPackages.desktopBackground} ${toString configHome}/emacs.d/local/dashboard-image.png
  '';
in {
  options.vonfry.development = {
    emacs = {
      preCustom = mkOption {
        default = "";
        type = types.lines;
      };
      postCustom = mkOption {
        default = "";
        type = types.lines;
      };
      excludeModules = mkOption {
        default = [ ];
        type = with types; listOf str;
      };
    };

    git = {
      signKey = mkOption {
        default = null;
        type = with types; nullOr str;
      };
    };
  };

  config = mkIf cfg'.enable {

    xdg = {
      mimeApps.defaultApplications = editorMimeApps;

      configFile = {
        "emacs.d" = {
          source = ./files/emacs.d;
          recursive = true;
        };
        "nvim" = {
          source = ./files/nvim;
          recursive = true;
        };

        "emacs.d/local/pre-custom.el".text =
          concatStringsSep "\n" [
            ''
            (setq-default
              vonfry-exclude-modules '(${concatMapStringsSep " " (e: "\"${e}\"")
                cfg.emacs.excludeModules}))
            (add-to-list 'exec-path "${emacsExtraBin}/bin")
            ''
            cfg.emacs.preCustom
          ];

        "emacs.d/local/post-custom.el".text = cfg.emacs.postCustom;
      };
    };

    services.emacs = {
      enable = true;
      client.enable = true;
      socketActivation.enable = true;
    };

    programs = {
      neovim = {
        enable = true;
        plugins = with pkgs.vimPlugins; [
          vim-logreview
          vim-surround
          auto-pairs
          direnv-vim
          nerdtree
          nerdtree-git-plugin
          vim-rooter
          vim-polyglot
          vim-ragtag
          MatchTagAlways
          nerdcommenter
          vim-orgmode
          vim-easymotion
          fzf-vim
          editorconfig-vim
          vim-better-whitespace
          vim-signature
          incsearch-vim
          vim-over
          tabular
          ultisnips
          vim-snippets
          nvim-lspconfig
          vim-fugitive
          vim-signify
          NeoSolarized
          vim-airline
          vim-airline-clock
          indentLine
          vim-mundo
          { plugin = dracula-vim;
            optional = true;
          }
          vim-gnupg
          supertab
        ];

        extraConfig = ''
          " see github:nixos/nixpkgs#96062
          " This have to be done here instead of config option at below because
          " my configuration will load this.
          packadd! dracula-vim
          call vonfry#init()
        '';
      };

      emacs =  {
        package = pkgs.emacsUnstable;
        enable = true;
        extraPackages = epkgs: with epkgs; [
          all-the-icons
          solarized-theme
          dracula-theme
          general
          whitespace-cleanup-mode
          use-package
          diminish
          dash
          s
          evil
          evil-numbers
          evil-surround
          evil-matchit
          flycheck
          auctex
          dashboard
          proof-general
          nix-mode
          org
          org-superstar
          evil-org
          org-web-tools
          org-journal
          org-ql
          org-roam
          rust-mode
          cargo
          markdown-mode
          haskell-mode
          lsp-haskell
          haskell-snippets
          easy-hugo
          json-mode
          yaml-mode
          magit
          git-modes
          magit-gitflow
          gitlab-ci-mode
          diff-hl
          disaster
          cmake-mode
          realgud-lldb
          mu4e-alert
          elfeed elfeed-org
          emacsql
          sql-indent
          ebib
          yasnippet-snippets
          info-colors
          dumb-jump
          dirvish
          avy
          ace-window
          logview
          ibuffer-vc
          lsp-mode
          lsp-ivy
          editorconfig
          realgud
          engine-mode
          evil-nerd-commenter
          rainbow-delimiters
          highlight-indent-guides
          doom-modeline
          hl-todo
          rainbow-mode
          hledger-mode
          ess
          envrc
          ob-http
          mpdel
          org-contacts
          toc-org
          evil-collection
          license-snippets
          melpaPackages.telega
          terminal-here
          zoxide
          smart-tab
          org-roam-ui
          graphviz-dot-mode
          vundo
          consult
          orderless
          embark
          embark-consult
          marginalia
          vertico
          consult-lsp
          project
          ibuffer-project
          consult-flycheck
        ];
      };

      git = {
        userName = "Vonfry";
        userEmail = "mail@vonfry.name";
        signing = mkIf (cfg.git.signKey != null) {
          signByDefault = true;
          key = cfg.git.signKey;
        };
        enable = true;
        extraConfig = {
          pull.rebase = mkDefault true;
          rebase.autoSquash = mkDefault true;
          github.user = "Vonfry";
          gitlab.user = "Vonfry";
          core = {
            pager = "nvim -R";
          };
          color.pager = false;
        };
        ignores = [ (builtins.readFile ./files/gitignore) ];
      };

      direnv = {
        enable = true;
        enableZshIntegration = true;
        nix-direnv = {
          enable = true;
        };
        stdlib = ''
          declare -A direnv_layout_dirs
          direnv_layout_dir() {
              echo "''${direnv_layout_dirs[$PWD]:=$(
                  echo -n "$XDG_CACHE_HOME"/direnv/layouts/
                  echo -n "$PWD" | shasum | cut -d ' ' -f 1
              )}"
          }
        '';
      };
    };

    home = {
      activation.developmentActivation = lib.hm.dag.entryAfter ["writeBoundary"]
        (concatStringsSep "\n" [ linkOrg linkEmacs ]);

      sessionVariables = {
        EDITOR = "nvim";
        MANPAGER = "nvim +Man!";
        PAGER = "nvim -R";
      };

      packages = with pkgs; [
        emacs-all-the-icons-fonts

        gitAndTools.gitflow gitAndTools.git-extras

        tokei zeal

        pandoc

        graphviz

        distrobox

        nixfmt
        rnix-lsp nixpkgs-review nix-prefetch-scripts
      ];

      # Use home.file instead of programs.<editor> due to I want to have a
      # structure # config file for them.
      file = {
        ".ghc/ghci.conf".text = ''
          :set +m

          -- see more about extension: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html
          :set -XLambdaCase
          :set -XMultiWayIf
          :set -XBinaryLiterals
          :set -XBangPatterns

          :set -XTemplateHaskell
          :set -XNamedFieldPuns
          :set -XFlexibleContexts
          :set -XFlexibleInstances
          :set -XMultiParamTypeClasses

          :set -XUnicodeSyntax

          :set -XDeriveGeneric
          :set -XDeriveFunctor
          :set -XDeriveFoldable

          :set -XImplicitParams

          -- preference
          :set prompt "λ "
          :set prompt-cont "> "

          -- allow C-c
          :set -fomit-yields
        '';

        ".latexmkrc".text = ''
          $out_dir = "latex.out";
          $pdf_mode = 5;
          $dvi_previewer = 'xdvi -watchfile 1.5';
          $ps_previewer  = 'feh';
          $pdf_previewer = 'zathura';
        '';

        ".Rprofile".text = ''
          options(browser = 'qutebrowser')
          # options(help_type = 'html')
        '';
      };
    };
  };
}