summary refs log tree commit diff
path: root/nixos/modules/services/misc/domoticz.nix
diff options
context:
space:
mode:
authorEd Cragg <ed.cragg@eipi.xyz>2020-04-30 12:51:49 +0100
committerEd Cragg <ed.cragg@eipi.xyz>2020-05-17 14:20:09 +0100
commitc7683646526e3b5630b27c5e157bdca088500262 (patch)
treecf014cb8cd320f7b354f5aa382bcd67f1971fc7e /nixos/modules/services/misc/domoticz.nix
parent68f7d0748388406c5b52eda35d8320e0e23d7689 (diff)
downloadnixpkgs-c7683646526e3b5630b27c5e157bdca088500262.tar
nixpkgs-c7683646526e3b5630b27c5e157bdca088500262.tar.gz
nixpkgs-c7683646526e3b5630b27c5e157bdca088500262.tar.bz2
nixpkgs-c7683646526e3b5630b27c5e157bdca088500262.tar.lz
nixpkgs-c7683646526e3b5630b27c5e157bdca088500262.tar.xz
nixpkgs-c7683646526e3b5630b27c5e157bdca088500262.tar.zst
nixpkgs-c7683646526e3b5630b27c5e157bdca088500262.zip
domoticz: add module
Diffstat (limited to 'nixos/modules/services/misc/domoticz.nix')
-rw-r--r--nixos/modules/services/misc/domoticz.nix89
1 files changed, 89 insertions, 0 deletions
diff --git a/nixos/modules/services/misc/domoticz.nix b/nixos/modules/services/misc/domoticz.nix
new file mode 100644
index 00000000000..42b4218aa09
--- /dev/null
+++ b/nixos/modules/services/misc/domoticz.nix
@@ -0,0 +1,89 @@
+{ lib, pkgs, config, ... }:
+
+with lib;
+
+let
+
+  cfg = config.services.domoticz;
+  pkgDesc = "Domoticz home automation";
+
+in {
+
+  options = {
+
+    services.domoticz = {
+      enable = mkEnableOption pkgDesc;
+
+      user = mkOption {
+        type = types.str;
+        default = "domoticz";
+        description = "domoticz user";
+      };
+
+      group = mkOption {
+        type = types.str;
+        default = "domoticz";
+        description = "domoticz group";
+      };
+
+      extraGroups = mkOption {
+        type = types.listOf types.str;
+        default = [ ];
+        description = "Extra groups to add to domoticz user";
+      };
+
+      stateDir = mkOption {
+        type = types.path;
+        default = "/var/lib/domoticz/";
+        description = "The state directory for domoticz";
+        example = "/home/bob/.domoticz/";
+      };
+
+      bind = mkOption {
+        type = types.str;
+        default = "0.0.0.0";
+        description = "IP address to bind to.";
+      };
+
+      port = mkOption {
+        type = types.int;
+        default = 8080;
+        description = "Port to bind to for HTTP, set to 0 to disable HTTP.";
+      };
+
+    };
+
+  };
+
+  config = mkIf cfg.enable {
+
+    users.users."domoticz" = {
+      name = cfg.user;
+      group = cfg.group;
+      extraGroups = cfg.extraGroups;
+      home = cfg.stateDir;
+      createHome = true;
+      description = pkgDesc;
+    };
+
+    users.groups."domoticz" = {
+      name = cfg.group;
+    };
+
+    systemd.services."domoticz" = {
+      description = pkgDesc;
+      wantedBy = [ "multi-user.target" ];
+      after = [ "network-online.target" ];
+      serviceConfig = {
+        User = cfg.user;
+        Group = cfg.group;
+        Restart = "always";
+        ExecStart = ''
+          ${pkgs.domoticz}/bin/domoticz -noupdates -www ${toString cfg.port} -wwwbind ${cfg.bind} -sslwww 0 -userdata ${cfg.stateDir} -approot ${pkgs.domoticz}/share/domoticz/ -pidfile /var/run/domoticz.pid
+        '';
+      };
+    };
+
+  };
+
+}