1{ lib, pkgs, config, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.domoticz;
8 pkgDesc = "Domoticz home automation";
9
10in {
11
12 options = {
13
14 services.domoticz = {
15 enable = mkEnableOption pkgDesc;
16
17 bind = mkOption {
18 type = types.str;
19 default = "0.0.0.0";
20 description = "IP address to bind to.";
21 };
22
23 port = mkOption {
24 type = types.port;
25 default = 8080;
26 description = "Port to bind to for HTTP, set to 0 to disable HTTP.";
27 };
28
29 };
30
31 };
32
33 config = mkIf cfg.enable {
34
35 systemd.services."domoticz" = {
36 description = pkgDesc;
37 wantedBy = [ "multi-user.target" ];
38 wants = [ "network-online.target" ];
39 after = [ "network-online.target" ];
40 serviceConfig = {
41 DynamicUser = true;
42 StateDirectory = "domoticz";
43 Restart = "always";
44 ExecStart = ''
45 ${pkgs.domoticz}/bin/domoticz -noupdates -www ${toString cfg.port} -wwwbind ${cfg.bind} -sslwww 0 -userdata /var/lib/domoticz -approot ${pkgs.domoticz}/share/domoticz/ -pidfile /var/run/domoticz.pid
46 '';
47 };
48 };
49
50 };
51
52}