summaryrefslogtreecommitdiffstats
path: root/usecases/desktop/development.nix
blob: 5d9697f3ea8bd78253596c9a194debaaa5bbe658 (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
inputs:

{ config, lib, pkgs, ... }:

let
  inherit (pkgs.unstable)
    clang
    clang-tools
    elixir_ls
    rust-analyzer-unwrapped

    vimPlugins;

  inherit (pkgs.unstable.python3Packages) python-language-server;

in
{
  options = with lib; {
    vim.lsp = mkOption {
      description = ''
        Configure Neovim to use these LSP servers;
      '';
      # TODO: change that to submodule with cmd, settings, capabilities, etc.
      type = with types; attrsOf (listOf str);
      default = { };
    };
  };

  config = {
    users.extraUsers.minijackson.packages = with pkgs; [
      clang
      clang-tools
      elixir
      gcc
      gdb
      man-pages
      rr
      rtags
    ];

    vim = {
      extraPlugins = with vimPlugins; [
        nvim-lspconfig
        rust-tools-nvim
        vim-grammarous
      ];

      variables = {
        rust_analyzer_path = "'${rust-analyzer-unwrapped}/bin/rust-analyzer'";
      };

      lsp = {
        clangd = [ "${clang-tools}/bin/clangd" "--resource-dir=${clang}/resource-root" ];
        elixirls = [ "${elixir_ls}/bin/elixir-ls" ];
        pyls = [ "${python-language-server}/bin/pyls" ];
      };

      luaConfig = with lib; let
        toLua = list: "{ ${concatMapStringsSep ", " (elem: "'${escape [ "'" ] elem}'") list} }";
        lspconfigFor = name: cmd: ''
          lspconfig["${name}"].setup {
            capabilities = capabilities,
            cmd = ${toLua cmd},
            on_attach = on_attach,
          }
        '';
        lspconfig = concatStringsSep
          "\n"
          (mapAttrsToList lspconfigFor config.vim.lsp);
      in
      mkMerge [
        (readFile ../../dotfiles/vim-dev.lua)
        lspconfig
      ];
    };

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

    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";

            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;
        };

      };

    services.lorri.enable = true;
  };
}