summaryrefslogtreecommitdiffstats
path: root/usecases/desktop/development.nix
blob: aac331fdcd290639f30182ef19dbdc205659d10e (plain)
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
inputs: {
  config,
  lib,
  pkgs,
  ...
}: let
  inherit
    (pkgs.unstable)
    clang
    clang-tools
    elixir_ls
    haskell-language-server
    marksman
    nil
    rust-analyzer-unwrapped
    lua-language-server
    vimPlugins
    ;

  pylsp = with pkgs.unstable.python3Packages;
    python-lsp-server.overrideAttrs (old: {
      propagatedBuildInputs =
        old.propagatedBuildInputs
        ++ python-lsp-server.passthru.optional-dependencies.all;
    });

  luaFormat = inputs.self.lib.generators.lua {};
in {
  imports = [
    (import ./development/latex.nix inputs)
  ];

  options = with lib;
  with luaFormat.lib; {
    vim.lsp = mkOption {
      description = ''
        Configure Neovim to use these LSP servers;
      '';
      type = with types;
        attrsOf (submodule {
          freeformType = luaFormat.type;

          options = {
            capabilities = mkOption {
              default = mkRaw "capabilities";
            };
            cmd = mkOption {
              type = with types; listOf str;
            };
            on_attach = mkOption {
              default = mkRaw "on_attach";
            };
          };
        });
      default = {};
    };
  };

  config = {
    # TODO: add cargo-info
    users.extraUsers.minijackson.packages = with pkgs.unstable; [
      bintools
      bacon
      clang
      clang-tools
      diffoscopeMinimal
      difftastic
      elixir
      gcc
      gdb
      graphviz
      man-pages
      python3Packages.ipython
      rr
      rustup
      watchexec

      shfmt
      taplo

      # Python
      black
      python3Packages.isort
      python3Packages.mypy
      python3Packages.tox
      # TODO: how to install into pylsp's python env?
      # python-lsp-black
      # pyls-isort
      # pylsp-mypy

      ruff

      neovide

      deadnix
      statix
      # TODO: add global vale config
      vale
    ];

    vim = {
      extraPlugins = with vimPlugins; [
        vim-pandoc
        clangd_extensions-nvim
        lsp_signature-nvim
        neodev-nvim
        nvim-lspconfig
        playground
        rust-tools-nvim
        vim-grammarous
      ];

      variables = {
        rust_analyzer_path = "${rust-analyzer-unwrapped}/bin/rust-analyzer";
        luals_base_path = "${lua-language-server}";
        clangd_path = "${clang-tools}/bin/clangd";
      };

      lsp = {
        elixirls.cmd = ["${elixir_ls}/bin/elixir-ls"];
        hls.cmd = ["${haskell-language-server}/bin/haskell-language-server" "--lsp"];
        lua_ls = {
          cmd = ["${lua-language-server}/bin/lua-language-server"];
          settings.Lua = {
            completion.callSnippet = "Replace";
            telemetry.enable = false;
          };
        };
        marksman.cmd = ["${marksman}/bin/marksman"];
        nil_ls.cmd = ["${nil}/bin/nil"];
        pylsp = {
          cmd = ["${pylsp}/bin/pylsp"];
          settings.pylsp.plugins = {
            autopep8.enabled = false;
            flake8.ignore = ["E501"];
            pycodestyle.ignore = ["E501"];
            yapf.enabled = false;

            # See TODO above
            #black.enabled = true;
            #isort.enabled = true;
            #mypy.enabled = true;
          };
        };
      };

      luaConfig = with lib; let
        toLua = luaFormat.generate;
        lspconfigFor = name: settings: "lspconfig['${name}'].setup ${toLua settings}";
        lspconfig =
          concatStringsSep
          "\n"
          (mapAttrsToList lspconfigFor config.vim.lsp);
      in
        mkMerge [
          "require('vim-dev')"
          "local lspconfig = require('lspconfig')"
          lspconfig
        ];
    };

    programs.zsh.interactiveShellInit = ''
      (( $+commands[rustc] )) && fpath+="$(rustc --print sysroot)/share/zsh/site-functions"
    '';

    programs.liboping.enable = true;

    documentation.dev.enable = true;

    boot.kernel.sysctl = {
      # For RR
      "kernel.perf_event_paranoid" = 1;
    };

    home-manager.users.minijackson = {config, ...}: {
      home.file.".clang-format".source =
        (pkgs.formats.yaml {}).generate
        "clang-format.yml"
        {
          BasedOnStyle = "Mozilla";
          ColumnLimit = 100;
          TabWidth = 4;
          IndentWidth = 4;
          UseTab = "ForIndentation";

          AlignAfterOpenBracket = "AlwaysBreak";
          AccessModifierOffset = -4;
          AlwaysBreakAfterDefinitionReturnType = "None";
          AlwaysBreakAfterReturnType = "None";
          AlwaysBreakTemplateDeclarations = true;
          BinPackArguments = false;
          BinPackParameters = false;
          BreakConstructorInitializers = "BeforeComma";
          Cpp11BracedListStyle = true;
          DerivePointerAlignment = false;
          NamespaceIndentation = "Inner";
          PenaltyBreakBeforeFirstCallParameter = 2;
          PointerAlignment = "Left";
          Standard = "Latest";
        };

      programs.direnv = {
        enable = true;
        enableBashIntegration = true;
        enableZshIntegration = true;

        nix-direnv.enable = true;
      };
    };

    nixpkgs.overlays = [
      (self: super: {
        inherit (self.unstable) nix-direnv direnv;
      })
    ];
  };
}