summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorPeter Hoeg <peter@hoeg.com>2018-04-21 22:32:09 +0800
committerPeter Hoeg <peter@hoeg.com>2018-04-23 16:53:12 +0800
commit4cd88807d8434efdc3fb666767098e2b3ee0b812 (patch)
tree19a98b08d266a35ac18aa5027e5e9383c5cd84c4 /nixos
parent3e3b5895ca2088126219559768e412902b137ee0 (diff)
downloadnixpkgs-4cd88807d8434efdc3fb666767098e2b3ee0b812.tar
nixpkgs-4cd88807d8434efdc3fb666767098e2b3ee0b812.tar.gz
nixpkgs-4cd88807d8434efdc3fb666767098e2b3ee0b812.tar.bz2
nixpkgs-4cd88807d8434efdc3fb666767098e2b3ee0b812.tar.lz
nixpkgs-4cd88807d8434efdc3fb666767098e2b3ee0b812.tar.xz
nixpkgs-4cd88807d8434efdc3fb666767098e2b3ee0b812.tar.zst
nixpkgs-4cd88807d8434efdc3fb666767098e2b3ee0b812.zip
home-assistant: make port configurable so we can use it elsewhere
Additionally, some settings based on NixOS configuation is set via defaultConfig
which is then merged with the user provided configration.

For now that just means http port and time zone but others can easily be added.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/misc/home-assistant.nix35
1 files changed, 31 insertions, 4 deletions
diff --git a/nixos/modules/services/misc/home-assistant.nix b/nixos/modules/services/misc/home-assistant.nix
index ac37c11106e..07b14bb6764 100644
--- a/nixos/modules/services/misc/home-assistant.nix
+++ b/nixos/modules/services/misc/home-assistant.nix
@@ -5,7 +5,9 @@ with lib;
 let
   cfg = config.services.home-assistant;
 
-  configFile = pkgs.writeText "configuration.yaml" (builtins.toJSON cfg.config);
+  configFile = pkgs.writeText "configuration.json" (builtins.toJSON (if cfg.applyDefaultConfig
+    then (lib.recursiveUpdate defaultConfig (if (isNull cfg.config) then {} else cfg.config))
+    else cfg.config));
 
   availableComponents = pkgs.home-assistant.availableComponents;
 
@@ -38,6 +40,12 @@ let
     then (cfg.package.override { inherit extraComponents; })
     else cfg.package;
 
+  # If you are changing this, please update the description in applyDefaultConfig
+  defaultConfig = {
+    homeassistant.time_zone = config.time.timeZone;
+    http.server_port = (toString cfg.port);
+  };
+
 in {
   meta.maintainers = with maintainers; [ dotlambda ];
 
@@ -50,6 +58,26 @@ in {
       description = "The config directory, where your <filename>configuration.yaml</filename> is located.";
     };
 
+    port = mkOption {
+      default = 8123;
+      type = types.int;
+      description = "The port on which to listen.";
+    };
+
+    applyDefaultConfig = mkOption {
+      default = true;
+      type = types.bool;
+      description = ''
+        Setting this option enables a few configuration options for HA based on NixOS configuration (such as time zone) to avoid having to manually specify configuration we already have.
+        </para>
+        <para>
+        Currently one side effect of enabling this is that the <literal>http</literal> component will be enabled.
+        </para>
+        <para>
+        This only takes effect if <literal>config != null</literal> in order to ensure that a manually managed <filename>configuration.yaml</filename> is not overwritten.
+      '';
+    };
+
     config = mkOption {
       default = null;
       type = with types; nullOr attrs;
@@ -110,15 +138,14 @@ in {
         ln -s ${configFile} ${cfg.configDir}/configuration.yaml
       '';
       serviceConfig = {
-        ExecStart = ''
-          ${package}/bin/hass --config "${cfg.configDir}"
-        '';
+        ExecStart = "${package}/bin/hass --config '${cfg.configDir}'";
         User = "hass";
         Group = "hass";
         Restart = "on-failure";
         ProtectSystem = "strict";
         ReadWritePaths = "${cfg.configDir}";
         PrivateTmp = true;
+        RemoveIPC = true;
       };
       path = [
         "/run/wrappers" # needed for ping