zaphyra's git: nixfiles

zaphyra's nixfiles

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 
{
  config,
  lib,
  ...
}:

{

  options.zpha.configure.floraCtl.enable = lib.mkEnableOption "";

  config = lib.mkIf config.zpha.configure.floraCtl.enable {
    sops.secrets."zigbee2mqttSecrets.yaml" = {
      owner = "zigbee2mqtt";
      key = "zigbee2mqttSecrets";
    };

    common.configure.persist.system.dirs = [
      {
        directory = "/var/lib/zigbee2mqtt";
        mode = "0770";
        user = "zigbee2mqtt";
        group = "zigbee2mqtt";
      }
    ];

    systemd.services.zigbee2mqtt = {
      serviceConfig = {
        Restart = lib.mkForce "always";
        RuntimeMaxSec = "1d";
      };
    };

    services = {
      udev.extraRules = ''
        SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{serial}=="00_12_4B_00_25_9B_C1_FC", SYMLINK+="zigbee0"
        ATTR{idVendor}=="0451", ATTR{idProduct}=="16a8", ENV{ID_MM_DEVICE_IGNORE}="1"
        SUBSYSTEM=="tty", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="16a8", SYMLINK+="zigbee0"
      '';

      zigbee2mqtt = {
        enable = true;
        settings = {
          homeassistant.enabled = true;
          permit_join = false;

          mqtt = {
            base_topic = "zigbee2mqtt";
            server = "mqtt://192.168.2.147:1883";
            user = "!${config.sops.secrets."zigbee2mqttSecrets.yaml".path} mqttUser";
            password = "!${config.sops.secrets."zigbee2mqttSecrets.yaml".path} mqttPassword";
          };

          serial = {
            adapter = "zstack";
            port = "/dev/zigbee0";
            disable_led = true;
          };

          frontend = {
            port = 8422;
            host = "::1";
          };

          advanced = {
            log_level = "info";
            log_output = [ "console" ];
            channel = 11;
            pan_id = 55067;
            ext_pan_id = [
              116
              73
              103
              101
              20
              101
              160
              9
            ];
            network_key = "!${config.sops.secrets."zigbee2mqttSecrets.yaml".path} network_key";
          };

          device_options.retain = true;
          devices = {
            "0x00124b0023ad17f1".friendly_name = "door_buzzer";
          };
        };
      };
    };

  };

}