Merge pull request #39304 from peterhoeg/f/ha

home-assistant: add a few knobs and make config YAML
This commit is contained in:
Peter Hoeg
2018-04-25 01:35:12 +00:00
committed by GitHub
3 changed files with 44 additions and 16 deletions
+36 -6
View File
@@ -5,7 +5,10 @@ with lib;
let let
cfg = config.services.home-assistant; cfg = config.services.home-assistant;
configFile = pkgs.writeText "configuration.yaml" (builtins.toJSON cfg.config); # cfg.config != null can be assumed here
configFile = pkgs.writeText "configuration.json"
(builtins.toJSON (if cfg.applyDefaultConfig then
(lib.recursiveUpdate defaultConfig cfg.config) else cfg.config));
availableComponents = pkgs.home-assistant.availableComponents; availableComponents = pkgs.home-assistant.availableComponents;
@@ -38,6 +41,12 @@ let
then (cfg.package.override { inherit extraComponents; }) then (cfg.package.override { inherit extraComponents; })
else cfg.package; 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 { in {
meta.maintainers = with maintainers; [ dotlambda ]; meta.maintainers = with maintainers; [ dotlambda ];
@@ -50,6 +59,26 @@ in {
description = "The config directory, where your <filename>configuration.yaml</filename> is located."; 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 { config = mkOption {
default = null; default = null;
type = with types; nullOr attrs; type = with types; nullOr attrs;
@@ -106,19 +135,20 @@ in {
description = "Home Assistant"; description = "Home Assistant";
after = [ "network.target" ]; after = [ "network.target" ];
preStart = lib.optionalString (cfg.config != null) '' preStart = lib.optionalString (cfg.config != null) ''
rm -f ${cfg.configDir}/configuration.yaml config=${cfg.configDir}/configuration.yaml
ln -s ${configFile} ${cfg.configDir}/configuration.yaml rm -f $config
${pkgs.remarshal}/bin/json2yaml -i ${configFile} -o $config
chmod 444 $config
''; '';
serviceConfig = { serviceConfig = {
ExecStart = '' ExecStart = "${package}/bin/hass --config '${cfg.configDir}'";
${package}/bin/hass --config "${cfg.configDir}"
'';
User = "hass"; User = "hass";
Group = "hass"; Group = "hass";
Restart = "on-failure"; Restart = "on-failure";
ProtectSystem = "strict"; ProtectSystem = "strict";
ReadWritePaths = "${cfg.configDir}"; ReadWritePaths = "${cfg.configDir}";
PrivateTmp = true; PrivateTmp = true;
RemoveIPC = true;
}; };
path = [ path = [
"/run/wrappers" # needed for ping "/run/wrappers" # needed for ping
+3 -3
View File
@@ -51,9 +51,9 @@ in {
startAll; startAll;
$hass->waitForUnit("home-assistant.service"); $hass->waitForUnit("home-assistant.service");
# Since config is specified using a Nix attribute set, # The config is specified using a Nix attribute set,
# configuration.yaml is a link to the Nix store # but then converted from JSON to YAML
$hass->succeed("test -L ${configDir}/configuration.yaml"); $hass->succeed("test -f ${configDir}/configuration.yaml");
# Check that Home Assistant's web interface and API can be reached # Check that Home Assistant's web interface and API can be reached
$hass->waitForOpenPort(8123); $hass->waitForOpenPort(8123);
+5 -7
View File
@@ -1,7 +1,7 @@
{ stdenv, pythonPackages, fetchFromGitHub }: { stdenv, python3Packages, fetchFromGitHub }:
pythonPackages.buildPythonApplication rec { python3Packages.buildPythonApplication rec {
name = "remarshal-${version}"; pname = "remarshal";
version = "0.7.0"; version = "0.7.0";
src = fetchFromGitHub { src = fetchFromGitHub {
@@ -11,10 +11,8 @@ pythonPackages.buildPythonApplication rec {
sha256 = "1wsgvzfp40lvly7nyyhv9prip4vi32rfc8kdji587jpw28zc1dfb"; sha256 = "1wsgvzfp40lvly7nyyhv9prip4vi32rfc8kdji587jpw28zc1dfb";
}; };
propagatedBuildInputs = with pythonPackages; [ propagatedBuildInputs = with python3Packages; [
dateutil dateutil pytoml pyyaml
pytoml
pyyaml
]; ];
meta = with stdenv.lib; { meta = with stdenv.lib; {