summaryrefslogtreecommitdiff
path: root/modules/development.nix
blob: 8520fc1968a9fcc0c12161a8abe8f434443a65e5 (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
{ 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; [

      # Tools
      golangci-lint
      shellcheck
      beautysh # shell formatter
      rustup
      goose
      sqlc
      maven
      gradle
      kotlin
      gomodifytags
      go-tools # staticcheck
      gosec
      devtoolbox
      busybox # A bunch of utils like lsof and fuser
      libllvm
      universal-ctags
      valgrind

      prometheus
      grafana-loki
      grafana-alloy
      pyroscope
    ];

    # Grafana for eko
    services.grafana.enable = true;
    services.grafana.settings.server.http_port = 3030;
    services.grafana.settings.smtp.enabled = true;
    services.grafana.settings.smtp = {
      host          = "smtp.example.com:587";
      user          = "your@user.com";
      password      = "super-secret";  # Consider using a file for secret
      skip_verify   = true;
      from_address  = "your@user.com";
      from_name     = "Grafana";
      startTLS_policy = "OpportunisticStartTLS";
    };

    systemd.services.grafana = {
      serviceConfig = {
        ProtectHome = lib.mkForce false;
        ProtectSystem = lib.mkForce false;
        PrivateTmp = lib.mkForce false;
        ReadWritePaths = [ "/home/kyren/projects/eko" ];
      };
    };

    # # Allow grafana to access DB
    # fileSystems."/var/lib/grafana/eko" = {
    #   device = "/home/kyren/projects/eko";
    #   options = [ "bind" "ro" ];
    # };

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

  };
}