aboutsummaryrefslogtreecommitdiff
path: root/nixos/machine/spt-mox.nix
blob: b01c48aeb8967165364489a157ad3f1f537cf486 (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
{ config, lib, pkgs, ... }:

with builtins;
with lib;

{

  config = {

    environment.systemPackages = with pkgs; [
      mosquitto
    ];

    networking.wirelessAP = {
      enable = true;
      environmentFile = "/run/secrets/hostapd.env";
      interfaces = {
        "wlp4s0" = {
          countryCode = "CZ";
          channel = 7;
          hwMode = "g";
          ht_capab = ["HT40+" "SHORT-GI-20" "SHORT-GI-40" "TX-STBC" "RX-STBC1" "DSSS_CCK-40"];
          ssid = "TurrisRules";
          bridge = "brlan";
          wpa = true;
          wpa3 = false;
          wpaPassphrase = "@PASS_TURRIS_RULES@";
        };
        # TODO use use wlp3s0 with 80211ax
      };
    };

    networking = {
      vlans = {
        "eth0.2" = {
          id = 2;
          interface = "eth0";
        };
      };
      bridges = {
        brlan = {
          interfaces = [
            "eth0" "lan1" "lan2" "lan3" "lan4"
          ];
        };
        brguest = {
          interfaces = [
            "eth0.2"
          ];
        };
      };
      interfaces.brlan = {
        ipv4 = {
          addresses = [{
            address = config.cynerd.hosts.spt.mox;
            prefixLength = 24;
          }];
        };
      };
      defaultGateway = config.cynerd.hosts.spt.omnia;
      nameservers = [ config.cynerd.hosts.spt.omnia "1.1.1.1" "8.8.8.8" ];
      dhcpcd.allowInterfaces = [ "brlan" ];
    };

    services.mosquitto = {
      enable = true;
      listeners = [
        {
          users = {
            cynerd = {
              acl = ["readwrite #"];
              passwordFile = "/run/secrets/mosquitto.cynerd.pass";
            };
            bigclown = {
              acl = ["readwrite bigclown/#"];
              passwordFile = "/run/secrets/mosquitto.bigclown.pass";
            };
          };
        }
      ];
    };
    networking.firewall.allowedTCPPorts = [1883];

    services.bigclown = {
      gateway = {
        enable = true;
        device = "/dev/ttyUSB0";
        environmentFile = "/run/secrets/bigclown.env";
        baseTopicPrefix = "bigclown/";
        mqtt = {
          username = "bigclown";
          password = "@PASS_MQTT@";
        };
      };
      mqtt2influxdb = {
        enable = true;
        environmentFile = "/run/secrets/bigclown.env";
        mqtt = {
          username = "bigclown";
          password = "@PASS_MQTT@";
        };
        influxdb = {
          host = "cynerd.cz";
          database = "bigclown";
          username = "bigclown";
          password = "@PASS_INFLUXDB@";
          ssl = true;
          verify_ssl = false;
        };
        points = [
          {
            measurement = "temperature";
            topic = "bigclown/node/+/thermometer/+/temperature";
            fields.value = "$.payload";
            tags = {
              id = "$.topic[2]";
              channel = "$.topic[4]";
            };
          }
          {
            measurement = "relative-humidity";
            topic = "bigclown/node/+/hygrometer/+/relative-humidity";
            fields.value = "$.payload";
            tags = {
              id = "$.topic[2]";
              channel = "$.topic[4]";
            };
          }
          {
            measurement = "illuminance";
            topic = "bigclown/node/+/lux-meter/0:0/illuminance";
            fields.value = "$.payload";
            tags = {
              id = "$.topic[2]";
            };
          }
          {
            measurement = "pressure";
            topic = "bigclown/node/+/barometer/0:0/pressure";
            fields.value = "$.payload";
            tags = {
              id = "$.topic[2]";
            };
          }
          {
            measurement = "voltage";
            topic = "bigclown/node/+/battery/+/voltage";
            fields.value = "$.payload";
            tags = {
              id = "$.topic[2]";
            };
          }
          {
            measurement = "button";
            topic = "bigclown/node/+/push-button/+/event-count";
            fields.value = "$.payload";
            tags = {
              id = "$.topic[2]";
              channel = "$.topic[4]";
            };
          }
        ];
      };
    };

    systemd.services.bigclown-leds = {
      description = "Bigclown LEDs control";
      wantedBy = ["multi-user.target"];
      after = ["mosquitto.service"];
      serviceConfig.ExecStart = "${pkgs.bigclown-leds}/bin/bigclown-leds /run/secrets/bigclown-leds.ini";
    };

  };

}