summaryrefslogtreecommitdiff
path: root/modules/development.nix
blob: d0e95390af69d4908ffa584a5ee9da0db2b1d729 (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
{ pkgs, lib, config, ... }: {

  options.development.enable = lib.mkOption {
    type        = lib.types.bool;
    default     = false;
    description = "enables development";
  };

  config = lib.mkIf config.development.enable {

    environment.systemPackages = with pkgs; [
      jetbrains.idea-community

      # LSP
      asm-lsp
      astro-language-server
      basedpyright
      bash-language-server
      vscode-langservers-extracted # html/css/json
      gopls
      lemminx # xml
      lua-language-server
      markdown-oxide
      marksman
      mdx-language-server
      neocmakelsp
      nil # nix
      tailwindcss-language-server
      taplo # toml
      typescript-language-server
      yaml-language-server
      # pnpm i -g css-variables-language-server
      # pnpm install -g gh-actions-language-server
      jdt-language-server
      kotlin-language-server

      # Tools
      stylua
      gofumpt
      golangci-lint
      prettierd
      jq
      lldb # codelldb debugger
      shellcheck
      beautysh # shell formatter
      gdb
      nasm
      rustup
      tokei # count lines of code
      go
      pnpm
      nodejs_24
      clang
      clang-tools
      gcc
      gnumake
      goose
      sqlc
      maven
      gradle
      kotlin
      mold # fast linker, for rust
      gomodifytags
      sops
      go-tools # staticcheck
      gosec
      devtoolbox

      prometheus
      grafana-loki
      grafana-alloy
    ];

    # Grafana for eko
    services.grafana.enable = true;
    services.grafana.settings.server.http_port = 3030;

    # Prometheus for eko
    services.prometheus.enable = true;
    services.prometheus.configText = builtins.readFile ./eko-prometheus.yml;

    # Alloy service for eko
    systemd.services.alloy = {
      description = "Alloy";

      wants = [ "network-online.target" ];
      after = [ "network-online.target" ];
      wantedBy = [ "multi-user.target" ];

      reloadTriggers = lib.mapAttrsToList (_: v: v.source or null) (
        lib.filterAttrs (n: _: lib.hasPrefix "alloy/" n && lib.hasSuffix ".alloy" n) config.environment.etc
      );

      serviceConfig = {
        Restart = "always";
        RestartSec = "2s";

        User = "root"; # TODO: make these not root?
        Group = "root";

        SupplementaryGroups = [
          # allow to read the systemd journal for loki log forwarding
          "systemd-journal"
        ];

        ConfigurationDirectory = "alloy";
        StateDirectory = "alloy";
        WorkingDirectory = "%S/alloy";
        Type = "simple";

        ExecStart = "${lib.getExe pkgs.grafana-alloy} run /etc/alloy/";
        ExecReload = "${pkgs.coreutils}/bin/kill -SIGHUP $MAINPID";
      };
    };

    environment.etc = {
      "alloy/eko-config.alloy".text = builtins.readFile ./eko-config.alloy;
    };

    # Loki service for eko
    services.loki.enable = true;
    services.loki.configuration = {
      auth_enabled = false;

      server = {
        http_listen_port = 3100;
      };

      common = {
        ring = {
          instance_addr = "127.0.0.1";
          kvstore = {
            store = "inmemory";
          };
        };
        replication_factor = 1;
        path_prefix = "/var/lib/loki";
      };

      schema_config = {
        configs = [
          {
            from = "2020-05-15";
            store = "tsdb";
            object_store = "filesystem";
            schema = "v13";
            index = {
              prefix = "index_";
              period = "24h";
            };
          }
        ];
      };

      storage_config = {
        filesystem = {
          directory = "/var/lib/loki/chunks";
        };
      };
    };

  };
}