diff options
author | Peter Hoeg <peter@hoeg.com> | 2018-04-25 01:35:12 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-25 01:35:12 +0000 |
commit | 45f1205bab6650ebb33de392308922703070082e (patch) | |
tree | 5b52cad15ef2de3d1500ccccf6601346ae0a52c3 /nixos | |
parent | 7e33e374db487ed87db316db3b2687f917aa7f90 (diff) | |
parent | e4a6e320bb8f2adb79a3c9b83478da753de4eedb (diff) | |
download | nixpkgs-45f1205bab6650ebb33de392308922703070082e.tar nixpkgs-45f1205bab6650ebb33de392308922703070082e.tar.gz nixpkgs-45f1205bab6650ebb33de392308922703070082e.tar.bz2 nixpkgs-45f1205bab6650ebb33de392308922703070082e.tar.lz nixpkgs-45f1205bab6650ebb33de392308922703070082e.tar.xz nixpkgs-45f1205bab6650ebb33de392308922703070082e.tar.zst nixpkgs-45f1205bab6650ebb33de392308922703070082e.zip |
Merge pull request #39304 from peterhoeg/f/ha
home-assistant: add a few knobs and make config YAML
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/services/misc/home-assistant.nix | 42 | ||||
-rw-r--r-- | nixos/tests/home-assistant.nix | 6 |
2 files changed, 39 insertions, 9 deletions
diff --git a/nixos/modules/services/misc/home-assistant.nix b/nixos/modules/services/misc/home-assistant.nix index ac37c11106e..1dc7b44ee37 100644 --- a/nixos/modules/services/misc/home-assistant.nix +++ b/nixos/modules/services/misc/home-assistant.nix @@ -5,7 +5,10 @@ with lib; let 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; @@ -38,6 +41,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 +59,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; @@ -106,19 +135,20 @@ in { description = "Home Assistant"; after = [ "network.target" ]; preStart = lib.optionalString (cfg.config != null) '' - rm -f ${cfg.configDir}/configuration.yaml - ln -s ${configFile} ${cfg.configDir}/configuration.yaml + config=${cfg.configDir}/configuration.yaml + rm -f $config + ${pkgs.remarshal}/bin/json2yaml -i ${configFile} -o $config + chmod 444 $config ''; 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 diff --git a/nixos/tests/home-assistant.nix b/nixos/tests/home-assistant.nix index 2e45dc78471..4ebccb7ab86 100644 --- a/nixos/tests/home-assistant.nix +++ b/nixos/tests/home-assistant.nix @@ -51,9 +51,9 @@ in { startAll; $hass->waitForUnit("home-assistant.service"); - # Since config is specified using a Nix attribute set, - # configuration.yaml is a link to the Nix store - $hass->succeed("test -L ${configDir}/configuration.yaml"); + # The config is specified using a Nix attribute set, + # but then converted from JSON to YAML + $hass->succeed("test -f ${configDir}/configuration.yaml"); # Check that Home Assistant's web interface and API can be reached $hass->waitForOpenPort(8123); |