DEVELOPMENT ENVIRONMENT

~liljamo/nix-arta

ref: 1ed6268e307d7b7d3dfa1c36757788192339a05e nix-arta/systems/hosts/proxy/default.nix -rw-r--r-- 3.3 KiB
1ed6268eJonni Liljamo chore: update nvim-flake 14 days 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
{
  config,
  pkgs,
  ...
}: let
  promtailPort = 3100;
in {
  sops.secrets.wg0PrivateKey = {};
  sops.secrets.wg0PresharedKey = {};

  networking.firewall.interfaces."eth0".allowedTCPPorts = [443 promtailPort 8404];
  networking.firewall.interfaces."wg0".allowedTCPPorts = [80];
  networking.wireguard.interfaces."wg0" = {
    ips = ["10.100.0.10/24"];
    listenPort = 51820;

    # pubKey pxbf41wTYSpBxTQW8ksQKNd7VOjTEUWKpW381qEnQyw=
    privateKeyFile = config.sops.secrets.wg0PrivateKey.path;

    peers = [
      {
        publicKey = "+HChRIruvl92cxk4Ztyut28T/m1ilEy3hqDd3HH6XRk=";
        presharedKeyFile = config.sops.secrets.wg0PresharedKey.path;
        allowedIPs = ["10.100.0.0/24"];
        endpoint = "172.234.96.20:51820";
        persistentKeepalive = 25;
      }
    ];
  };

  systemd.services.caddy.path = [
    pkgs.nssTools
  ];

  environment.etc = {
    "haproxy/domainstobackends.map" = {
      text = builtins.readFile ./domainstobackends.map;
    };
  };

  services = {
    haproxy = {
      enable = true;
      config = builtins.readFile ./haproxy.conf;
    };
    caddy = {
      enable = true;
      logFormat = "level ERROR";
      globalConfig = ''
        http_port 8080
        https_port 8443
      '';
      virtualHosts = {
        "dns.rustylily.home.arpa".extraConfig = ''
          tls internal
          reverse_proxy http://10.1.2.3:80
        '';

        "multi.media.rustylily.home.arpa".extraConfig = ''
          tls internal
          reverse_proxy http://10.1.2.30:8096
        '';
        "books.media.rustylily.home.arpa".extraConfig = ''
          tls internal
          reverse_proxy http://10.1.2.30:5000
        '';
        "nextcloud.rustylily.home.arpa".extraConfig = ''
          tls internal
          reverse_proxy http://10.1.2.15:80
        '';

        "metrics.rustylily.home.arpa".extraConfig = ''
          tls internal
          reverse_proxy http://10.1.2.5:3000
        '';

        "portainer.uwulpine.home.arpa".extraConfig = ''
          tls internal
          reverse_proxy http://10.1.1.10:9080
        '';
        "registry.uwulpine.home.arpa".extraConfig = ''
          tls internal
          reverse_proxy http://10.1.1.10:5000
        '';
        "registryui.uwulpine.home.arpa".extraConfig = ''
          tls internal
          reverse_proxy http://10.1.1.10:5080
        '';
      };
    };
  };

  services.promtail = {
    enable = true;
    configuration = {
      server = {
        http_listen_port = promtailPort;
        grpc_listen_port = 0;
      };
      positions = {
        filename = "/tmp/positions.yaml";
      };
      clients = [
        {
          url = "http://10.1.2.5:9091/loki/api/v1/push";
        }
      ];
      scrape_configs = [
        {
          job_name = "journal";
          journal = {
            max_age = "12h";
            labels = {
              job = "systemd-journal";
              host = "lxcproxy";
            };
          };
          relabel_configs = [
            {
              action = "keep";
              source_labels = ["__journal__systemd_unit"];
              regex = "haproxy.service";
            }
            {
              source_labels = ["__journal__systemd_unit"];
              target_label = "unit";
            }
          ];
        }
      ];
    };
  };

  system.stateVersion = "23.05";
}