summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/hardware/usbrelayd.nix
blob: 67c5e132e2ecee92580e9cddc995d1c06f36ff67 (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
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.services.usbrelayd;
in
{
  options.services.usbrelayd = with lib.types; {
    enable = lib.mkEnableOption "USB Relay MQTT daemon";

    broker = lib.mkOption {
      type = str;
      description = "Hostname or IP address of your MQTT Broker.";
      default = "127.0.0.1";
      example = [
        "mqtt"
        "192.168.1.1"
      ];
    };

    clientName = lib.mkOption {
      type = str;
      description = "Name, your client connects as.";
      default = "MyUSBRelay";
    };
  };

  config = lib.mkIf cfg.enable {

    environment.etc."usbrelayd.conf".text = ''
      [MQTT]
      BROKER = ${cfg.broker}
      CLIENTNAME = ${cfg.clientName}
    '';

    services.udev.packages = [ pkgs.usbrelayd ];
    systemd.packages = [ pkgs.usbrelayd ];
    users.groups.usbrelay = { };
  };

  meta = {
    maintainers = with lib.maintainers; [ wentasah ];
  };
}